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
Closed
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
10 changes: 3 additions & 7 deletions docs/source/en/package_reference/inference_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions docs/source/ko/package_reference/inference_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 6 additions & 12 deletions src/huggingface_hub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,11 @@
"ChatCompletionInputFunctionDefinition",
"ChatCompletionInputFunctionName",
"ChatCompletionInputGrammarType",
"ChatCompletionInputJSONSchema",
"ChatCompletionInputGrammarTypeType",
"ChatCompletionInputJSONSchemaConfig",
"ChatCompletionInputMessage",
"ChatCompletionInputMessageChunk",
"ChatCompletionInputMessageChunkType",
"ChatCompletionInputResponseFormatJSONObject",
"ChatCompletionInputResponseFormatJSONSchema",
"ChatCompletionInputResponseFormatText",
"ChatCompletionInputStreamOptions",
"ChatCompletionInputTool",
"ChatCompletionInputToolCall",
Expand Down Expand Up @@ -552,13 +550,11 @@
"ChatCompletionInputFunctionDefinition",
"ChatCompletionInputFunctionName",
"ChatCompletionInputGrammarType",
"ChatCompletionInputJSONSchema",
"ChatCompletionInputGrammarTypeType",
"ChatCompletionInputJSONSchemaConfig",
"ChatCompletionInputMessage",
"ChatCompletionInputMessageChunk",
"ChatCompletionInputMessageChunkType",
"ChatCompletionInputResponseFormatJSONObject",
"ChatCompletionInputResponseFormatJSONSchema",
"ChatCompletionInputResponseFormatText",
"ChatCompletionInputStreamOptions",
"ChatCompletionInputTool",
"ChatCompletionInputToolCall",
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions src/huggingface_hub/inference/_generated/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
ChatCompletionInputFunctionDefinition,
ChatCompletionInputFunctionName,
ChatCompletionInputGrammarType,
ChatCompletionInputJSONSchema,
ChatCompletionInputGrammarTypeType,
ChatCompletionInputJSONSchemaConfig,
ChatCompletionInputMessage,
ChatCompletionInputMessageChunk,
ChatCompletionInputMessageChunkType,
ChatCompletionInputResponseFormatJSONObject,
ChatCompletionInputResponseFormatJSONSchema,
ChatCompletionInputResponseFormatText,
ChatCompletionInputStreamOptions,
ChatCompletionInputTool,
ChatCompletionInputToolCall,
Expand Down
46 changes: 13 additions & 33 deletions src/huggingface_hub/inference/_generated/types/chat_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down