From 08296e5f4c9e3b96a77afc2fae32c7c1b437988c Mon Sep 17 00:00:00 2001 From: Wauplin Date: Tue, 17 Jun 2025 18:13:09 +0200 Subject: [PATCH] Update chat-completion json_schema specs --- .../src/tasks/chat-completion/inference.ts | 30 ++++-- .../src/tasks/chat-completion/spec/input.json | 92 +++++++++++-------- 2 files changed, 77 insertions(+), 45 deletions(-) diff --git a/packages/tasks/src/tasks/chat-completion/inference.ts b/packages/tasks/src/tasks/chat-completion/inference.ts index 9ee1b60944..4e36277258 100644 --- a/packages/tasks/src/tasks/chat-completion/inference.ts +++ b/packages/tasks/src/tasks/chat-completion/inference.ts @@ -136,17 +136,35 @@ export interface ChatCompletionInputFunctionDefinition { [property: string]: unknown; } export interface ChatCompletionInputGrammarType { + json_schema?: ChatCompletionInputJSONSchemaConfig; type: ChatCompletionInputGrammarTypeType; + [property: string]: unknown; +} +export interface ChatCompletionInputJSONSchemaConfig { /** - * A string that represents a [JSON Schema](https://json-schema.org/). - * - * JSON Schema is a declarative language that allows to annotate JSON documents - * with types and descriptions. + * A description of what the response format is for, used by the model to determine how to + * respond in the format. + */ + description?: string; + /** + * The name of the response format. + */ + name: string; + /** + * The schema for the response format, described as a JSON Schema object. Learn how to build + * JSON schemas [here](https://json-schema.org/). + */ + schema?: { + [key: string]: unknown; + }; + /** + * Whether to enable strict schema adherence when generating the output. If set to true, the + * model will always follow the exact schema defined in the `schema` field. */ - value: unknown; + strict?: boolean; [property: string]: unknown; } -export type ChatCompletionInputGrammarTypeType = "json" | "regex" | "json_schema"; +export type ChatCompletionInputGrammarTypeType = "text" | "json_schema" | "json_object"; export interface ChatCompletionInputStreamOptions { /** * If set, an additional chunk will be streamed before the data: [DONE] message. The usage diff --git a/packages/tasks/src/tasks/chat-completion/spec/input.json b/packages/tasks/src/tasks/chat-completion/spec/input.json index 1d2c76da45..bb99438004 100644 --- a/packages/tasks/src/tasks/chat-completion/spec/input.json +++ b/packages/tasks/src/tasks/chat-completion/spec/input.json @@ -291,61 +291,75 @@ "ChatCompletionInputGrammarType": { "oneOf": [ { - "type": "object", - "required": ["type", "value"], - "properties": { - "type": { - "type": "string", - "enum": ["json"] - }, - "value": { - "description": "A string that represents a [JSON Schema](https://json-schema.org/).\n\nJSON Schema is a declarative language that allows to annotate JSON documents\nwith types and descriptions." - } - } + "$ref": "#/$defs/ChatCompletionInputResponseFormatText" }, { - "type": "object", - "required": ["type", "value"], - "properties": { - "type": { - "type": "string", - "enum": ["regex"] - }, - "value": { - "type": "string" - } - } + "$ref": "#/$defs/ChatCompletionInputResponseFormatJSONSchema" }, { - "type": "object", - "required": ["type", "value"], - "properties": { - "type": { - "type": "string", - "enum": ["json_schema"] - }, - "value": { - "$ref": "#/$defs/ChatCompletionInputJsonSchemaConfig" - } - } + "$ref": "#/$defs/ChatCompletionInputResponseFormatJSONObject" } ], - "discriminator": { - "propertyName": "type" - }, "title": "ChatCompletionInputGrammarType" }, + "ChatCompletionInputResponseFormatText": { + "type": "object", + "required": ["type"], + "properties": { + "type": { + "type": "string", + "enum": ["text"] + } + }, + "title": "ChatCompletionInputResponseFormatText" + }, + "ChatCompletionInputResponseFormatJSONSchema": { + "type": "object", + "required": ["type", "json_schema"], + "properties": { + "type": { + "type": "string", + "enum": ["json_schema"] + }, + "json_schema": { + "$ref": "#/$defs/ChatCompletionInputJsonSchemaConfig" + } + }, + "title": "ChatCompletionInputResponseFormatJSONSchema" + }, + "ChatCompletionInputResponseFormatJSONObject": { + "type": "object", + "required": ["type"], + "properties": { + "type": { + "type": "string", + "enum": ["json_object"] + } + }, + "title": "ChatCompletionInputResponseFormatJSONObject" + }, "ChatCompletionInputJsonSchemaConfig": { "type": "object", - "required": ["schema"], + "required": ["name"], "properties": { "name": { "type": "string", - "description": "Optional name identifier for the schema", + "description": "The name of the response format." + }, + "description": { + "type": "string", + "description": "A description of what the response format is for, used by the model to determine how to respond in the format.", "nullable": true }, "schema": { - "description": "The actual JSON schema definition" + "type": "object", + "description": "The schema for the response format, described as a JSON Schema object. Learn how to build JSON schemas [here](https://json-schema.org/).", + "nullable": true + }, + "strict": { + "type": "boolean", + "description": "Whether to enable strict schema adherence when generating the output. If set to true, the model will always follow the exact schema defined in the `schema` field.", + "nullable": true } }, "title": "ChatCompletionInputJsonSchemaConfig"