From d17f36e4973bbb1eb5b40fb30f201e78cdcccf87 Mon Sep 17 00:00:00 2001 From: Emmanuel Ferdman Date: Wed, 11 Jun 2025 15:34:12 -0700 Subject: [PATCH] Migrate to V2 Pydantic interface Signed-off-by: Emmanuel Ferdman --- docs/source/basic_tutorials/using_guidance.md | 4 ++-- .../models/test_grammar_response_format_llama.py | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/source/basic_tutorials/using_guidance.md b/docs/source/basic_tutorials/using_guidance.md index e389fbbc..d25a6bd0 100644 --- a/docs/source/basic_tutorials/using_guidance.md +++ b/docs/source/basic_tutorials/using_guidance.md @@ -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) diff --git a/integration-tests/models/test_grammar_response_format_llama.py b/integration-tests/models/test_grammar_response_format_llama.py index b2e69d61..8a905e64 100644 --- a/integration-tests/models/test_grammar_response_format_llama.py +++ b/integration-tests/models/test_grammar_response_format_llama.py @@ -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()}, }, )