From 70b851dff0a1bf44ebdac2a7589b0747285062dd Mon Sep 17 00:00:00 2001 From: Lucain Pouget Date: Tue, 17 Jun 2025 18:25:16 +0200 Subject: [PATCH] Update chat-completion json_schema specs --- .../en/package_reference/inference_types.md | 10 ++-- .../ko/package_reference/inference_types.md | 10 ++-- src/huggingface_hub/__init__.py | 18 +++----- .../inference/_generated/types/__init__.py | 6 +-- .../_generated/types/chat_completion.py | 46 ++++++------------- 5 files changed, 27 insertions(+), 63 deletions(-) diff --git a/docs/source/en/package_reference/inference_types.md b/docs/source/en/package_reference/inference_types.md index 1c90e9facb..d719409cdc 100644 --- a/docs/source/en/package_reference/inference_types.md +++ b/docs/source/en/package_reference/inference_types.md @@ -57,18 +57,14 @@ This part of the lib is still under development and will be improved in future r [[autodoc]] huggingface_hub.ChatCompletionInputFunctionName -[[autodoc]] huggingface_hub.ChatCompletionInputJSONSchema +[[autodoc]] huggingface_hub.ChatCompletionInputGrammarType + +[[autodoc]] huggingface_hub.ChatCompletionInputJSONSchemaConfig [[autodoc]] huggingface_hub.ChatCompletionInputMessage [[autodoc]] huggingface_hub.ChatCompletionInputMessageChunk -[[autodoc]] huggingface_hub.ChatCompletionInputResponseFormatJSONObject - -[[autodoc]] huggingface_hub.ChatCompletionInputResponseFormatJSONSchema - -[[autodoc]] huggingface_hub.ChatCompletionInputResponseFormatText - [[autodoc]] huggingface_hub.ChatCompletionInputStreamOptions [[autodoc]] huggingface_hub.ChatCompletionInputTool diff --git a/docs/source/ko/package_reference/inference_types.md b/docs/source/ko/package_reference/inference_types.md index 3746086ed2..30d7dfa56b 100644 --- a/docs/source/ko/package_reference/inference_types.md +++ b/docs/source/ko/package_reference/inference_types.md @@ -56,18 +56,14 @@ rendered properly in your Markdown viewer. [[autodoc]] huggingface_hub.ChatCompletionInputFunctionName -[[autodoc]] huggingface_hub.ChatCompletionInputJSONSchema +[[autodoc]] huggingface_hub.ChatCompletionInputGrammarType + +[[autodoc]] huggingface_hub.ChatCompletionInputJSONSchemaConfig [[autodoc]] huggingface_hub.ChatCompletionInputMessage [[autodoc]] huggingface_hub.ChatCompletionInputMessageChunk -[[autodoc]] huggingface_hub.ChatCompletionInputResponseFormatJSONObject - -[[autodoc]] huggingface_hub.ChatCompletionInputResponseFormatJSONSchema - -[[autodoc]] huggingface_hub.ChatCompletionInputResponseFormatText - [[autodoc]] huggingface_hub.ChatCompletionInputStreamOptions [[autodoc]] huggingface_hub.ChatCompletionInputTool diff --git a/src/huggingface_hub/__init__.py b/src/huggingface_hub/__init__.py index f74b00d5c8..402c46e0f6 100644 --- a/src/huggingface_hub/__init__.py +++ b/src/huggingface_hub/__init__.py @@ -301,13 +301,11 @@ "ChatCompletionInputFunctionDefinition", "ChatCompletionInputFunctionName", "ChatCompletionInputGrammarType", - "ChatCompletionInputJSONSchema", + "ChatCompletionInputGrammarTypeType", + "ChatCompletionInputJSONSchemaConfig", "ChatCompletionInputMessage", "ChatCompletionInputMessageChunk", "ChatCompletionInputMessageChunkType", - "ChatCompletionInputResponseFormatJSONObject", - "ChatCompletionInputResponseFormatJSONSchema", - "ChatCompletionInputResponseFormatText", "ChatCompletionInputStreamOptions", "ChatCompletionInputTool", "ChatCompletionInputToolCall", @@ -552,13 +550,11 @@ "ChatCompletionInputFunctionDefinition", "ChatCompletionInputFunctionName", "ChatCompletionInputGrammarType", - "ChatCompletionInputJSONSchema", + "ChatCompletionInputGrammarTypeType", + "ChatCompletionInputJSONSchemaConfig", "ChatCompletionInputMessage", "ChatCompletionInputMessageChunk", "ChatCompletionInputMessageChunkType", - "ChatCompletionInputResponseFormatJSONObject", - "ChatCompletionInputResponseFormatJSONSchema", - "ChatCompletionInputResponseFormatText", "ChatCompletionInputStreamOptions", "ChatCompletionInputTool", "ChatCompletionInputToolCall", @@ -1277,13 +1273,11 @@ def __dir__(): ChatCompletionInputFunctionDefinition, # noqa: F401 ChatCompletionInputFunctionName, # noqa: F401 ChatCompletionInputGrammarType, # noqa: F401 - ChatCompletionInputJSONSchema, # noqa: F401 + ChatCompletionInputGrammarTypeType, # noqa: F401 + ChatCompletionInputJSONSchemaConfig, # noqa: F401 ChatCompletionInputMessage, # noqa: F401 ChatCompletionInputMessageChunk, # noqa: F401 ChatCompletionInputMessageChunkType, # noqa: F401 - ChatCompletionInputResponseFormatJSONObject, # noqa: F401 - ChatCompletionInputResponseFormatJSONSchema, # noqa: F401 - ChatCompletionInputResponseFormatText, # noqa: F401 ChatCompletionInputStreamOptions, # noqa: F401 ChatCompletionInputTool, # noqa: F401 ChatCompletionInputToolCall, # noqa: F401 diff --git a/src/huggingface_hub/inference/_generated/types/__init__.py b/src/huggingface_hub/inference/_generated/types/__init__.py index 63f6a653d6..a602fa149e 100644 --- a/src/huggingface_hub/inference/_generated/types/__init__.py +++ b/src/huggingface_hub/inference/_generated/types/__init__.py @@ -24,13 +24,11 @@ ChatCompletionInputFunctionDefinition, ChatCompletionInputFunctionName, ChatCompletionInputGrammarType, - ChatCompletionInputJSONSchema, + ChatCompletionInputGrammarTypeType, + ChatCompletionInputJSONSchemaConfig, ChatCompletionInputMessage, ChatCompletionInputMessageChunk, ChatCompletionInputMessageChunkType, - ChatCompletionInputResponseFormatJSONObject, - ChatCompletionInputResponseFormatJSONSchema, - ChatCompletionInputResponseFormatText, ChatCompletionInputStreamOptions, ChatCompletionInputTool, ChatCompletionInputToolCall, diff --git a/src/huggingface_hub/inference/_generated/types/chat_completion.py b/src/huggingface_hub/inference/_generated/types/chat_completion.py index fe455ee710..5b3b50f320 100644 --- a/src/huggingface_hub/inference/_generated/types/chat_completion.py +++ b/src/huggingface_hub/inference/_generated/types/chat_completion.py @@ -46,50 +46,30 @@ class ChatCompletionInputMessage(BaseInferenceType): @dataclass_with_extra -class ChatCompletionInputJSONSchema(BaseInferenceType): +class ChatCompletionInputJSONSchemaConfig(BaseInferenceType): name: str - """ - The name of the response format. - """ + """The name of the response format.""" description: Optional[str] = None + """A description of what the response format is for, used by the model to determine how to + respond in the format. """ - A description of what the response format is for, used by the model to determine - how to respond in the format. - """ - schema: Optional[Dict[str, object]] = None - """ - The schema for the response format, described as a JSON Schema object. Learn how - to build JSON schemas [here](https://json-schema.org/). + schema: Optional[Dict[str, Any]] = None + """The schema for the response format, described as a JSON Schema object. Learn how to build + JSON schemas [here](https://json-schema.org/). """ strict: Optional[bool] = None - """ - 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. + """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. """ -@dataclass_with_extra -class ChatCompletionInputResponseFormatText(BaseInferenceType): - type: Literal["text"] +ChatCompletionInputGrammarTypeType = Literal["text", "json_schema", "json_object"] @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, -] +class ChatCompletionInputGrammarType(BaseInferenceType): + type: "ChatCompletionInputGrammarTypeType" + json_schema: Optional[ChatCompletionInputJSONSchemaConfig] = None @dataclass_with_extra