forked from phoenix/litellm-mirror
docs(json_mode.md): add example of calling openai with pydantic model via litellm
This commit is contained in:
parent
9cf3d5f568
commit
0c88cc4153
1 changed files with 6 additions and 33 deletions
|
@ -71,12 +71,6 @@ response_format: { "type": "json_schema", "json_schema": … , "strict": true }
|
||||||
|
|
||||||
Works for OpenAI models
|
Works for OpenAI models
|
||||||
|
|
||||||
:::info
|
|
||||||
|
|
||||||
Support for passing in a pydantic object to litellm sdk will be [coming soon](https://github.com/BerriAI/litellm/issues/5074#issuecomment-2272355842)
|
|
||||||
|
|
||||||
:::
|
|
||||||
|
|
||||||
<Tabs>
|
<Tabs>
|
||||||
<TabItem value="sdk" label="SDK">
|
<TabItem value="sdk" label="SDK">
|
||||||
|
|
||||||
|
@ -89,36 +83,15 @@ os.environ["OPENAI_API_KEY"] = ""
|
||||||
|
|
||||||
messages = [{"role": "user", "content": "List 5 cookie recipes"}]
|
messages = [{"role": "user", "content": "List 5 cookie recipes"}]
|
||||||
|
|
||||||
|
class CalendarEvent(BaseModel):
|
||||||
|
name: str
|
||||||
|
date: str
|
||||||
|
participants: list[str]
|
||||||
|
|
||||||
resp = completion(
|
resp = completion(
|
||||||
model="gpt-4o-2024-08-06",
|
model="gpt-4o-2024-08-06",
|
||||||
messages=messages,
|
messages=messages,
|
||||||
response_format={
|
response_format=CalendarEvent
|
||||||
"type": "json_schema",
|
|
||||||
"json_schema": {
|
|
||||||
"name": "math_reasoning",
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"steps": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"explanation": { "type": "string" },
|
|
||||||
"output": { "type": "string" }
|
|
||||||
},
|
|
||||||
"required": ["explanation", "output"],
|
|
||||||
"additionalProperties": False
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"final_answer": { "type": "string" }
|
|
||||||
},
|
|
||||||
"required": ["steps", "final_answer"],
|
|
||||||
"additionalProperties": False
|
|
||||||
},
|
|
||||||
"strict": True
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
print("Received={}".format(resp))
|
print("Received={}".format(resp))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue