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

Conversation

Wauplin
Copy link
Contributor

@Wauplin Wauplin commented Jun 17, 2025

In huggingface/huggingface_hub#3082 @hanouticelina fixed the Python inference types for chat completion grammar input. Biggest update was:

@dataclass_with_extra
class ChatCompletionInputResponseFormatText(BaseInferenceType):
    type: Literal["text"]


@dataclass_with_extra
class ChatCompletionInputResponseFormatJSONSchema(BaseInferenceType):
    type: Literal["json_schema"]
    json_schema: ChatCompletionInputJSONSchema


@dataclass_with_extra
class ChatCompletionInputResponseFormatJSONObject(BaseInferenceType):
    type: Literal["json_object"]


ChatCompletionInputGrammarType = Union[
    ChatCompletionInputResponseFormatText,
    ChatCompletionInputResponseFormatJSONSchema,
    ChatCompletionInputResponseFormatJSONObject,
]

This PR reflects "officially" this update in the JS specs. It makes JS and Python specs aligned again (was not the case for the last month, ending up with annoying PRs like this one huggingface/huggingface_hub#3104). The result is not as satisfying as what a manual implementation would give because the 3 objects are merged in 1 with optional fields (see export type ChatCompletionInputGrammarTypeType = "text" | "json_schema" | "json_object";). This is because quicktype do not handle properly unions (see glideapps/quicktype#1266 - 6 yo 😕 ). It's not the only case like this in our specs but first time I find out about it. Not a problem since we don't enforce data structures.

In Python, the data structure will result in this: huggingface/huggingface_hub#3167

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants