From 0c88cc41538a66d2189fde44e24f67140a41fdaf Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Tue, 6 Aug 2024 18:27:06 -0700 Subject: [PATCH] docs(json_mode.md): add example of calling openai with pydantic model via litellm --- docs/my-website/docs/completion/json_mode.md | 39 +++----------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/docs/my-website/docs/completion/json_mode.md b/docs/my-website/docs/completion/json_mode.md index 92e135dff5c..3c3bca3adba 100644 --- a/docs/my-website/docs/completion/json_mode.md +++ b/docs/my-website/docs/completion/json_mode.md @@ -71,12 +71,6 @@ response_format: { "type": "json_schema", "json_schema": … , "strict": true } 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) - -::: - @@ -89,36 +83,15 @@ os.environ["OPENAI_API_KEY"] = "" messages = [{"role": "user", "content": "List 5 cookie recipes"}] +class CalendarEvent(BaseModel): + name: str + date: str + participants: list[str] + resp = completion( model="gpt-4o-2024-08-06", messages=messages, - response_format={ - "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 - }, - } + response_format=CalendarEvent ) print("Received={}".format(resp))