Skip to content
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

Support text-generation in InferenceClient #1513

Merged
merged 23 commits into from
Jun 27, 2023
Merged
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
2 changes: 1 addition & 1 deletion docs/source/guides/inference.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ has a simple API that supports the most common tasks. Here is a list of the curr
| | [Summarization](https://huggingface.co/tasks/summarization) | ✅ | [`~InferenceClient.summarization`] |
| | [Table Question Answering](https://huggingface.co/tasks/table-question-answering) | | |
| | [Text Classification](https://huggingface.co/tasks/text-classification) | | |
| | [Text Generation](https://huggingface.co/tasks/text-generation) | | |
| | [Text Generation](https://huggingface.co/tasks/text-generation) | ✅ | [`~InferenceClient.text_generation`] |
| | [Token Classification](https://huggingface.co/tasks/token-classification) | | |
| | [Translation](https://huggingface.co/tasks/translation) | | |
| | [Zero Shot Classification](https://huggingface.co/tasks/zero-shot-image-classification) | | |
Expand Down
29 changes: 29 additions & 0 deletions docs/source/package_reference/inference_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,35 @@ For most tasks, the return value has a built-in type (string, list, image...). H

[[autodoc]] huggingface_hub.inference._types.ImageSegmentationOutput

### Text generation types

[`~InferenceClient.text_generation`] task has a greater support than other tasks in `InferenceClient`. In
particular, user inputs and server outputs are validated using [Pydantic](https://docs.pydantic.dev/latest/)
if this package is installed. Therefore, we recommend installing it (`pip install pydantic`)
for a better user experience.

You can find below the dataclasses used to validate data and in particular [`~huggingface_hub.inference._text_generation.TextGenerationParameters`] (input),
[`~huggingface_hub.inference._text_generation.TextGenerationResponse`] (output) and
[`~huggingface_hub.inference._text_generation.TextGenerationStreamResponse`] (streaming output).

[[autodoc]] huggingface_hub.inference._text_generation.TextGenerationParameters

[[autodoc]] huggingface_hub.inference._text_generation.TextGenerationResponse

[[autodoc]] huggingface_hub.inference._text_generation.TextGenerationStreamResponse

[[autodoc]] huggingface_hub.inference._text_generation.InputToken

[[autodoc]] huggingface_hub.inference._text_generation.Token

[[autodoc]] huggingface_hub.inference._text_generation.FinishReason

[[autodoc]] huggingface_hub.inference._text_generation.BestOfSequence

[[autodoc]] huggingface_hub.inference._text_generation.Details

[[autodoc]] huggingface_hub.inference._text_generation.StreamDetails

## InferenceAPI

[`InferenceAPI`] is the legacy way to call the Inference API. The interface is more simplistic and requires knowing
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ preview = true
ignore_missing_imports = true
no_implicit_optional = true
scripts_are_modules = true
plugins = [
"pydantic.mypy"
]

[tool.ruff]
# Ignored rules:
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def get_version() -> str:
"Pillow",
"gradio", # to test webhooks
"numpy", # for embeddings
"pydantic", # for text-generation-inference
]

# Typing extra dependencies list is duplicated in `.pre-commit-config.yaml`
Expand All @@ -66,6 +67,7 @@ def get_version() -> str:
"types-toml",
"types-tqdm",
"types-urllib3",
"pydantic", # for text-generation dataclasses
]

extras["quality"] = [
Expand Down
Loading