Skip to content

Update chat-completion json_schema specs (JS) #1537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions packages/tasks/src/tasks/chat-completion/inference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
92 changes: 53 additions & 39 deletions packages/tasks/src/tasks/chat-completion/spec/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading