Skip to content

Commit b4386b8

Browse files
Migrate to V2 Pydantic interface (#3262)
Signed-off-by: Emmanuel Ferdman <[email protected]>
1 parent 24c2bff commit b4386b8

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

docs/source/basic_tutorials/using_guidance.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ client = InferenceClient("http://localhost:3000")
138138

139139
user_input = "I saw a puppy a cat and a raccoon during my bike ride in the park"
140140
resp = client.text_generation(
141-
f"convert to JSON: 'f{user_input}'. please use the following schema: {Animals.schema()}",
141+
f"convert to JSON: 'f{user_input}'. please use the following schema: {Animals.model_json_schema()}",
142142
max_new_tokens=100,
143143
seed=42,
144-
grammar={"type": "json", "value": Animals.schema()},
144+
grammar={"type": "json", "value": Animals.model_json_schema()},
145145
)
146146

147147
print(resp)

integration-tests/models/test_grammar_response_format_llama.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Weather(BaseModel):
3434
"messages": [
3535
{
3636
"role": "system",
37-
"content": f"Respond to the users questions and answer them in the following format: {Weather.schema()}",
37+
"content": f"Respond to the users questions and answer them in the following format: {Weather.model_json_schema()}",
3838
},
3939
{
4040
"role": "user",
@@ -43,7 +43,7 @@ class Weather(BaseModel):
4343
],
4444
"seed": 42,
4545
"max_tokens": 500,
46-
"response_format": {"type": "json_object", "value": Weather.schema()},
46+
"response_format": {"type": "json_object", "value": Weather.model_json_schema()},
4747
}
4848
# send the request
4949
response = requests.post(
@@ -75,7 +75,7 @@ class Weather(BaseModel):
7575

7676
json_payload["response_format"] = {
7777
"type": "json_schema",
78-
"value": {"name": "weather", "strict": True, "schema": Weather.schema()},
78+
"value": {"name": "weather", "strict": True, "schema": Weather.model_json_schema()},
7979
}
8080
response = requests.post(
8181
f"{llama_grammar.base_url}/v1/chat/completions",
@@ -109,7 +109,7 @@ class Weather(BaseModel):
109109
"messages": [
110110
{
111111
"role": "system",
112-
"content": f"Respond to the users questions and answer them in the following format: {Weather.schema()}",
112+
"content": f"Respond to the users questions and answer them in the following format: {Weather.model_json_schema()}",
113113
},
114114
{
115115
"role": "user",
@@ -119,7 +119,7 @@ class Weather(BaseModel):
119119
"seed": 42,
120120
"max_tokens": 500,
121121
"tools": [],
122-
"response_format": {"type": "json_object", "value": Weather.schema()},
122+
"response_format": {"type": "json_object", "value": Weather.model_json_schema()},
123123
},
124124
)
125125

0 commit comments

Comments
 (0)