From bbb5f75b8875235d93b6ec2f8a9a859b8021331c Mon Sep 17 00:00:00 2001 From: longwei66 Date: Fri, 4 Oct 2024 14:33:49 +0200 Subject: [PATCH] Update use-structured-outputs.mdx Update examples for Using structured outputs with JSON schema (manual definition or with (Pydantic) The API requires the response_format when using a json_schema to have a name attribute. --- ai-data/generative-apis/how-to/use-structured-outputs.mdx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ai-data/generative-apis/how-to/use-structured-outputs.mdx b/ai-data/generative-apis/how-to/use-structured-outputs.mdx index f438fac275..02c3d78ccf 100644 --- a/ai-data/generative-apis/how-to/use-structured-outputs.mdx +++ b/ai-data/generative-apis/how-to/use-structured-outputs.mdx @@ -162,6 +162,7 @@ extract = client.chat.completions.create( response_format={ "type": "json_schema", "json_schema": { + "name": "VoiceNote", "schema": VoiceNote.model_json_schema(), } }, @@ -203,6 +204,7 @@ extract = client.chat.completions.create( response_format={ "type": "json_schema", "json_schema": { + "name": "VoiceNote", "schema": { "type": "object", "properties": { @@ -243,4 +245,4 @@ By choosing between JSON mode and Structured outputs with JSON schema, you contr - **JSON mode** is flexible but less predictable. - **Structured outputs** provide strict adherence to a predefined schema, ensuring consistency. -Experiment with both methods to determine which best fits your application's requirements. \ No newline at end of file +Experiment with both methods to determine which best fits your application's requirements.