Skip to content

Migrate to V2 Pydantic interface #3262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/source/basic_tutorials/using_guidance.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions integration-tests/models/test_grammar_response_format_llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Weather(BaseModel):
"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",
Expand All @@ -43,7 +43,7 @@ class Weather(BaseModel):
],
"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(
Expand Down Expand Up @@ -75,7 +75,7 @@ class Weather(BaseModel):

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",
Expand Down Expand Up @@ -109,7 +109,7 @@ class Weather(BaseModel):
"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",
Expand All @@ -119,7 +119,7 @@ class Weather(BaseModel):
"seed": 42,
"max_tokens": 500,
"tools": [],
"response_format": {"type": "json_object", "value": Weather.schema()},
"response_format": {"type": "json_object", "value": Weather.model_json_schema()},
},
)

Expand Down