Skip to content

Update chat-completion json_schema specs (Python) #3167

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

Closed
wants to merge 1 commit into from

Conversation

Wauplin
Copy link
Contributor

@Wauplin Wauplin commented Jun 17, 2025

Follow-up PR after #3082 and huggingface/huggingface.js#1537. Resulting data structure is less optimal but at least it comes from our JS specs. See huggingface/huggingface.js#1537 for more details.

@Wauplin Wauplin changed the title Update chat-completion json_schema specs Update chat-completion json_schema specs (Python) Jun 17, 2025
@Wauplin Wauplin requested a review from hanouticelina June 17, 2025 16:26
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@Wauplin
Copy link
Contributor Author

Wauplin commented Jun 25, 2025

closing this PR as it degrades the typing

@Wauplin Wauplin closed this Jun 25, 2025
Wauplin added a commit to huggingface/huggingface.js that referenced this pull request Jun 25, 2025
In huggingface/huggingface_hub#3082
@hanouticelina fixed the Python inference types for chat completion
grammar input. Biggest update was:

```py
@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
:confused: ). 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