This commit is contained in:
Emmanuel Ferdman 2025-06-18 18:49:07 +08:00 committed by GitHub
commit 4ab7c8edd2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 7 deletions

View File

@ -138,10 +138,10 @@ client = InferenceClient("http://localhost:3000")
user_input = "I saw a puppy a cat and a raccoon during my bike ride in the park"
resp = client.text_generation(
f"convert to JSON: 'f{user_input}'. please use the following schema: {Animals.schema()}",
f"convert to JSON: 'f{user_input}'. please use the following schema: {Animals.model_json_schema()}",
max_new_tokens=100,
seed=42,
grammar={"type": "json", "value": Animals.schema()},
grammar={"type": "json", "value": Animals.model_json_schema()},
)
print(resp)

View File

@ -34,7 +34,7 @@ async def test_grammar_response_format_llama_json(llama_grammar, response_snapsh
"messages": [
{
"role": "system",
"content": f"Respond to the users questions and answer them in the following format: {Weather.schema()}",
"content": f"Respond to the users questions and answer them in the following format: {Weather.model_json_schema()}",
},
{
"role": "user",
@ -43,7 +43,7 @@ async def test_grammar_response_format_llama_json(llama_grammar, response_snapsh
],
"seed": 42,
"max_tokens": 500,
"response_format": {"type": "json_object", "value": Weather.schema()},
"response_format": {"type": "json_object", "value": Weather.model_json_schema()},
}
# send the request
response = requests.post(
@ -75,7 +75,7 @@ async def test_grammar_response_format_llama_json(llama_grammar, response_snapsh
json_payload["response_format"] = {
"type": "json_schema",
"value": {"name": "weather", "strict": True, "schema": Weather.schema()},
"value": {"name": "weather", "strict": True, "schema": Weather.model_json_schema()},
}
response = requests.post(
f"{llama_grammar.base_url}/v1/chat/completions",
@ -109,7 +109,7 @@ async def test_grammar_response_format_llama_error_if_tools_not_installed(
"messages": [
{
"role": "system",
"content": f"Respond to the users questions and answer them in the following format: {Weather.schema()}",
"content": f"Respond to the users questions and answer them in the following format: {Weather.model_json_schema()}",
},
{
"role": "user",
@ -119,7 +119,7 @@ async def test_grammar_response_format_llama_error_if_tools_not_installed(
"seed": 42,
"max_tokens": 500,
"tools": [],
"response_format": {"type": "json_object", "value": Weather.schema()},
"response_format": {"type": "json_object", "value": Weather.model_json_schema()},
},
)