Voice et bot modif
This commit is contained in:
parent
189d56026b
commit
7333a22bcd
10774 changed files with 634644 additions and 933308 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load diff
|
|
@ -1,4 +1,3 @@
|
|||
# coding=utf-8
|
||||
# Copyright 2023-present, the HuggingFace Inc. team.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -19,9 +18,10 @@ import io
|
|||
import json
|
||||
import logging
|
||||
import mimetypes
|
||||
from collections.abc import AsyncIterable, Iterable
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any, AsyncIterable, BinaryIO, Iterable, Literal, NoReturn, Optional, Union, overload
|
||||
from typing import TYPE_CHECKING, Any, BinaryIO, Literal, NoReturn, Union, overload
|
||||
|
||||
import httpx
|
||||
|
||||
|
|
@ -57,9 +57,9 @@ logger = logging.getLogger(__name__)
|
|||
class RequestParameters:
|
||||
url: str
|
||||
task: str
|
||||
model: Optional[str]
|
||||
json: Optional[Union[str, dict, list]]
|
||||
data: Optional[bytes]
|
||||
model: str | None
|
||||
json: str | dict | list | None
|
||||
data: bytes | None
|
||||
headers: dict[str, Any]
|
||||
|
||||
|
||||
|
|
@ -78,9 +78,9 @@ class MimeBytes(bytes):
|
|||
```
|
||||
"""
|
||||
|
||||
mime_type: Optional[str]
|
||||
mime_type: str | None
|
||||
|
||||
def __new__(cls, data: bytes, mime_type: Optional[str] = None):
|
||||
def __new__(cls, data: bytes, mime_type: str | None = None):
|
||||
obj = super().__new__(cls, data)
|
||||
obj.mime_type = mime_type
|
||||
if isinstance(data, MimeBytes) and mime_type is None:
|
||||
|
|
@ -123,7 +123,7 @@ def _open_as_mime_bytes(content: ContentT) -> MimeBytes: ... # means "if input
|
|||
def _open_as_mime_bytes(content: Literal[None]) -> Literal[None]: ... # means "if input is None, output is None"
|
||||
|
||||
|
||||
def _open_as_mime_bytes(content: Optional[ContentT]) -> Optional[MimeBytes]:
|
||||
def _open_as_mime_bytes(content: ContentT | None) -> MimeBytes | None:
|
||||
"""Open `content` as a binary file, either from a URL, a local path, raw bytes, or a PIL Image.
|
||||
|
||||
Do nothing if `content` is None.
|
||||
|
|
@ -249,7 +249,7 @@ def _bytes_to_image(content: bytes) -> "Image":
|
|||
return Image.open(io.BytesIO(content))
|
||||
|
||||
|
||||
def _as_dict(response: Union[bytes, dict]) -> dict:
|
||||
def _as_dict(response: bytes | dict) -> dict:
|
||||
return json.loads(response) if isinstance(response, bytes) else response
|
||||
|
||||
|
||||
|
|
@ -258,7 +258,7 @@ def _as_dict(response: Union[bytes, dict]) -> dict:
|
|||
|
||||
def _stream_text_generation_response(
|
||||
output_lines: Iterable[str], details: bool
|
||||
) -> Union[Iterable[str], Iterable[TextGenerationStreamOutput]]:
|
||||
) -> Iterable[str] | Iterable[TextGenerationStreamOutput]:
|
||||
"""Used in `InferenceClient.text_generation`."""
|
||||
# Parse ServerSentEvents
|
||||
for line in output_lines:
|
||||
|
|
@ -272,7 +272,7 @@ def _stream_text_generation_response(
|
|||
|
||||
async def _async_stream_text_generation_response(
|
||||
output_lines: AsyncIterable[str], details: bool
|
||||
) -> Union[AsyncIterable[str], AsyncIterable[TextGenerationStreamOutput]]:
|
||||
) -> AsyncIterable[str] | AsyncIterable[TextGenerationStreamOutput]:
|
||||
"""Used in `AsyncInferenceClient.text_generation`."""
|
||||
# Parse ServerSentEvents
|
||||
async for line in output_lines:
|
||||
|
|
@ -284,9 +284,7 @@ async def _async_stream_text_generation_response(
|
|||
yield output
|
||||
|
||||
|
||||
def _format_text_generation_stream_output(
|
||||
line: str, details: bool
|
||||
) -> Optional[Union[str, TextGenerationStreamOutput]]:
|
||||
def _format_text_generation_stream_output(line: str, details: bool) -> str | TextGenerationStreamOutput | None:
|
||||
if not line.startswith("data:"):
|
||||
return None # empty line
|
||||
|
||||
|
|
@ -334,7 +332,7 @@ async def _async_stream_chat_completion_response(
|
|||
|
||||
def _format_chat_completion_stream_output(
|
||||
line: str,
|
||||
) -> Optional[ChatCompletionStreamOutput]:
|
||||
) -> ChatCompletionStreamOutput | None:
|
||||
if not line.startswith("data:"):
|
||||
return None # empty line
|
||||
|
||||
|
|
@ -375,14 +373,14 @@ async def _async_yield_from(client: httpx.AsyncClient, response: httpx.Response)
|
|||
# For more details, see https://github.com/huggingface/text-generation-inference and
|
||||
# https://huggingface.co/docs/api-inference/detailed_parameters#text-generation-task.
|
||||
|
||||
_UNSUPPORTED_TEXT_GENERATION_KWARGS: dict[Optional[str], list[str]] = {}
|
||||
_UNSUPPORTED_TEXT_GENERATION_KWARGS: dict[str | None, list[str]] = {}
|
||||
|
||||
|
||||
def _set_unsupported_text_generation_kwargs(model: Optional[str], unsupported_kwargs: list[str]) -> None:
|
||||
def _set_unsupported_text_generation_kwargs(model: str | None, unsupported_kwargs: list[str]) -> None:
|
||||
_UNSUPPORTED_TEXT_GENERATION_KWARGS.setdefault(model, []).extend(unsupported_kwargs)
|
||||
|
||||
|
||||
def _get_unsupported_text_generation_kwargs(model: Optional[str]) -> list[str]:
|
||||
def _get_unsupported_text_generation_kwargs(model: str | None) -> list[str]:
|
||||
return _UNSUPPORTED_TEXT_GENERATION_KWARGS.get(model, [])
|
||||
|
||||
|
||||
|
|
@ -422,7 +420,7 @@ def raise_text_generation_error(http_error: HfHubHTTPError) -> NoReturn:
|
|||
raise http_error
|
||||
|
||||
|
||||
def _parse_text_generation_error(error: Optional[str], error_type: Optional[str]) -> TextGenerationError:
|
||||
def _parse_text_generation_error(error: str | None, error_type: str | None) -> TextGenerationError:
|
||||
if error_type == "generation":
|
||||
return GenerationError(error) # type: ignore
|
||||
if error_type == "incomplete_generation":
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -17,7 +17,7 @@ class AudioClassificationParameters(BaseInferenceType):
|
|||
|
||||
function_to_apply: Optional["AudioClassificationOutputTransform"] = None
|
||||
"""The function to apply to the model outputs in order to retrieve the scores."""
|
||||
top_k: Optional[int] = None
|
||||
top_k: int | None = None
|
||||
"""When specified, limits the output to the top K most probable classes."""
|
||||
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ class AudioClassificationInput(BaseInferenceType):
|
|||
"""The input audio data as a base64-encoded string. If no `parameters` are provided, you can
|
||||
also provide the audio data as a raw bytes payload.
|
||||
"""
|
||||
parameters: Optional[AudioClassificationParameters] = None
|
||||
parameters: AudioClassificationParameters | None = None
|
||||
"""Additional inference parameters for Audio Classification"""
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# See:
|
||||
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
|
||||
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
|
||||
from typing import Literal, Optional, Union
|
||||
from typing import Literal, Union
|
||||
|
||||
from .base import BaseInferenceType, dataclass_with_extra
|
||||
|
||||
|
|
@ -15,17 +15,17 @@ AutomaticSpeechRecognitionEarlyStoppingEnum = Literal["never"]
|
|||
class AutomaticSpeechRecognitionGenerationParameters(BaseInferenceType):
|
||||
"""Parametrization of the text generation process"""
|
||||
|
||||
do_sample: Optional[bool] = None
|
||||
do_sample: bool | None = None
|
||||
"""Whether to use sampling instead of greedy decoding when generating new tokens."""
|
||||
early_stopping: Optional[Union[bool, "AutomaticSpeechRecognitionEarlyStoppingEnum"]] = None
|
||||
early_stopping: Union[bool, "AutomaticSpeechRecognitionEarlyStoppingEnum"] | None = None
|
||||
"""Controls the stopping condition for beam-based methods."""
|
||||
epsilon_cutoff: Optional[float] = None
|
||||
epsilon_cutoff: float | None = None
|
||||
"""If set to float strictly between 0 and 1, only tokens with a conditional probability
|
||||
greater than epsilon_cutoff will be sampled. In the paper, suggested values range from
|
||||
3e-4 to 9e-4, depending on the size of the model. See [Truncation Sampling as Language
|
||||
Model Desmoothing](https://hf.co/papers/2210.15191) for more details.
|
||||
"""
|
||||
eta_cutoff: Optional[float] = None
|
||||
eta_cutoff: float | None = None
|
||||
"""Eta sampling is a hybrid of locally typical sampling and epsilon sampling. If set to
|
||||
float strictly between 0 and 1, a token is only considered if it is greater than either
|
||||
eta_cutoff or sqrt(eta_cutoff) * exp(-entropy(softmax(next_token_logits))). The latter
|
||||
|
|
@ -34,40 +34,40 @@ class AutomaticSpeechRecognitionGenerationParameters(BaseInferenceType):
|
|||
See [Truncation Sampling as Language Model Desmoothing](https://hf.co/papers/2210.15191)
|
||||
for more details.
|
||||
"""
|
||||
max_length: Optional[int] = None
|
||||
max_length: int | None = None
|
||||
"""The maximum length (in tokens) of the generated text, including the input."""
|
||||
max_new_tokens: Optional[int] = None
|
||||
max_new_tokens: int | None = None
|
||||
"""The maximum number of tokens to generate. Takes precedence over max_length."""
|
||||
min_length: Optional[int] = None
|
||||
min_length: int | None = None
|
||||
"""The minimum length (in tokens) of the generated text, including the input."""
|
||||
min_new_tokens: Optional[int] = None
|
||||
min_new_tokens: int | None = None
|
||||
"""The minimum number of tokens to generate. Takes precedence over min_length."""
|
||||
num_beam_groups: Optional[int] = None
|
||||
num_beam_groups: int | None = None
|
||||
"""Number of groups to divide num_beams into in order to ensure diversity among different
|
||||
groups of beams. See [this paper](https://hf.co/papers/1610.02424) for more details.
|
||||
"""
|
||||
num_beams: Optional[int] = None
|
||||
num_beams: int | None = None
|
||||
"""Number of beams to use for beam search."""
|
||||
penalty_alpha: Optional[float] = None
|
||||
penalty_alpha: float | None = None
|
||||
"""The value balances the model confidence and the degeneration penalty in contrastive
|
||||
search decoding.
|
||||
"""
|
||||
temperature: Optional[float] = None
|
||||
temperature: float | None = None
|
||||
"""The value used to modulate the next token probabilities."""
|
||||
top_k: Optional[int] = None
|
||||
top_k: int | None = None
|
||||
"""The number of highest probability vocabulary tokens to keep for top-k-filtering."""
|
||||
top_p: Optional[float] = None
|
||||
top_p: float | None = None
|
||||
"""If set to float < 1, only the smallest set of most probable tokens with probabilities
|
||||
that add up to top_p or higher are kept for generation.
|
||||
"""
|
||||
typical_p: Optional[float] = None
|
||||
typical_p: float | None = None
|
||||
"""Local typicality measures how similar the conditional probability of predicting a target
|
||||
token next is to the expected conditional probability of predicting a random token next,
|
||||
given the partial text already generated. If set to float < 1, the smallest set of the
|
||||
most locally typical tokens with probabilities that add up to typical_p or higher are
|
||||
kept for generation. See [this paper](https://hf.co/papers/2202.00666) for more details.
|
||||
"""
|
||||
use_cache: Optional[bool] = None
|
||||
use_cache: bool | None = None
|
||||
"""Whether the model should use the past last key/values attentions to speed up decoding"""
|
||||
|
||||
|
||||
|
|
@ -75,9 +75,9 @@ class AutomaticSpeechRecognitionGenerationParameters(BaseInferenceType):
|
|||
class AutomaticSpeechRecognitionParameters(BaseInferenceType):
|
||||
"""Additional inference parameters for Automatic Speech Recognition"""
|
||||
|
||||
generation_parameters: Optional[AutomaticSpeechRecognitionGenerationParameters] = None
|
||||
generation_parameters: AutomaticSpeechRecognitionGenerationParameters | None = None
|
||||
"""Parametrization of the text generation process"""
|
||||
return_timestamps: Optional[bool] = None
|
||||
return_timestamps: bool | None = None
|
||||
"""Whether to output corresponding timestamps with the generated text"""
|
||||
|
||||
|
||||
|
|
@ -89,7 +89,7 @@ class AutomaticSpeechRecognitionInput(BaseInferenceType):
|
|||
"""The input audio data as a base64-encoded string. If no `parameters` are provided, you can
|
||||
also provide the audio data as a raw bytes payload.
|
||||
"""
|
||||
parameters: Optional[AutomaticSpeechRecognitionParameters] = None
|
||||
parameters: AutomaticSpeechRecognitionParameters | None = None
|
||||
"""Additional inference parameters for Automatic Speech Recognition"""
|
||||
|
||||
|
||||
|
|
@ -107,7 +107,7 @@ class AutomaticSpeechRecognitionOutput(BaseInferenceType):
|
|||
|
||||
text: str
|
||||
"""The recognized text."""
|
||||
chunks: Optional[list[AutomaticSpeechRecognitionOutputChunk]] = None
|
||||
chunks: list[AutomaticSpeechRecognitionOutputChunk] | None = None
|
||||
"""When returnTimestamps is enabled, chunks contains a list of audio chunks identified by
|
||||
the model.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import inspect
|
|||
import json
|
||||
import types
|
||||
from dataclasses import asdict, dataclass
|
||||
from typing import Any, TypeVar, Union, get_args
|
||||
from typing import Any, TypeVar, get_args
|
||||
|
||||
from typing_extensions import dataclass_transform
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ class BaseInferenceType(dict):
|
|||
"""
|
||||
|
||||
@classmethod
|
||||
def parse_obj_as_list(cls: type[T], data: Union[bytes, str, list, dict]) -> list[T]:
|
||||
def parse_obj_as_list(cls: type[T], data: bytes | str | list | dict) -> list[T]:
|
||||
"""Alias to parse server response and return a single instance.
|
||||
|
||||
See `parse_obj` for more details.
|
||||
|
|
@ -64,7 +64,7 @@ class BaseInferenceType(dict):
|
|||
return output
|
||||
|
||||
@classmethod
|
||||
def parse_obj_as_instance(cls: type[T], data: Union[bytes, str, list, dict]) -> T:
|
||||
def parse_obj_as_instance(cls: type[T], data: bytes | str | list | dict) -> T:
|
||||
"""Alias to parse server response and return a single instance.
|
||||
|
||||
See `parse_obj` for more details.
|
||||
|
|
@ -75,7 +75,7 @@ class BaseInferenceType(dict):
|
|||
return output
|
||||
|
||||
@classmethod
|
||||
def parse_obj(cls: type[T], data: Union[bytes, str, list, dict]) -> Union[list[T], T]:
|
||||
def parse_obj(cls: type[T], data: bytes | str | list | dict) -> list[T] | T:
|
||||
"""Parse server response as a dataclass or list of dataclasses.
|
||||
|
||||
To enable future-compatibility, we want to handle cases where the server return more fields than expected.
|
||||
|
|
@ -90,7 +90,7 @@ class BaseInferenceType(dict):
|
|||
|
||||
# If a list, parse each item individually
|
||||
if isinstance(data, list):
|
||||
return [cls.parse_obj(d) for d in data] # type: ignore [misc]
|
||||
return [cls.parse_obj(d) for d in data] # type: ignore
|
||||
|
||||
# At this point, we expect a dict
|
||||
if not isinstance(data, dict):
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# See:
|
||||
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
|
||||
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
|
||||
from typing import Any, Literal, Optional, Union
|
||||
from typing import Any, Literal, Union
|
||||
|
||||
from .base import BaseInferenceType, dataclass_with_extra
|
||||
|
||||
|
|
@ -19,15 +19,15 @@ ChatCompletionInputMessageChunkType = Literal["text", "image_url"]
|
|||
@dataclass_with_extra
|
||||
class ChatCompletionInputMessageChunk(BaseInferenceType):
|
||||
type: "ChatCompletionInputMessageChunkType"
|
||||
image_url: Optional[ChatCompletionInputURL] = None
|
||||
text: Optional[str] = None
|
||||
image_url: ChatCompletionInputURL | None = None
|
||||
text: str | None = None
|
||||
|
||||
|
||||
@dataclass_with_extra
|
||||
class ChatCompletionInputFunctionDefinition(BaseInferenceType):
|
||||
name: str
|
||||
parameters: Any
|
||||
description: Optional[str] = None
|
||||
description: str | None = None
|
||||
|
||||
|
||||
@dataclass_with_extra
|
||||
|
|
@ -40,9 +40,9 @@ class ChatCompletionInputToolCall(BaseInferenceType):
|
|||
@dataclass_with_extra
|
||||
class ChatCompletionInputMessage(BaseInferenceType):
|
||||
role: str
|
||||
content: Optional[Union[list[ChatCompletionInputMessageChunk], str]] = None
|
||||
name: Optional[str] = None
|
||||
tool_calls: Optional[list[ChatCompletionInputToolCall]] = None
|
||||
content: list[ChatCompletionInputMessageChunk] | str | None = None
|
||||
name: str | None = None
|
||||
tool_calls: list[ChatCompletionInputToolCall] | None = None
|
||||
|
||||
|
||||
@dataclass_with_extra
|
||||
|
|
@ -51,17 +51,17 @@ class ChatCompletionInputJSONSchema(BaseInferenceType):
|
|||
"""
|
||||
The name of the response format.
|
||||
"""
|
||||
description: Optional[str] = None
|
||||
description: str | None = None
|
||||
"""
|
||||
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
|
||||
schema: dict[str, object] | None = 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
|
||||
strict: bool | None = 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`
|
||||
|
|
@ -94,7 +94,7 @@ ChatCompletionInputGrammarType = Union[
|
|||
|
||||
@dataclass_with_extra
|
||||
class ChatCompletionInputStreamOptions(BaseInferenceType):
|
||||
include_usage: Optional[bool] = None
|
||||
include_usage: bool | None = None
|
||||
"""If set, an additional chunk will be streamed before the data: [DONE] message. The usage
|
||||
field on this chunk shows the token usage statistics for the entire request, and the
|
||||
choices field will always be an empty array. All other chunks will also include a usage
|
||||
|
|
@ -131,12 +131,12 @@ class ChatCompletionInput(BaseInferenceType):
|
|||
|
||||
messages: list[ChatCompletionInputMessage]
|
||||
"""A list of messages comprising the conversation so far."""
|
||||
frequency_penalty: Optional[float] = None
|
||||
frequency_penalty: float | None = None
|
||||
"""Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing
|
||||
frequency in the text so far,
|
||||
decreasing the model's likelihood to repeat the same line verbatim.
|
||||
"""
|
||||
logit_bias: Optional[list[float]] = None
|
||||
logit_bias: list[float] | None = None
|
||||
"""UNUSED
|
||||
Modify the likelihood of specified tokens appearing in the completion. Accepts a JSON
|
||||
object that maps tokens
|
||||
|
|
@ -148,54 +148,54 @@ class ChatCompletionInput(BaseInferenceType):
|
|||
like -100 or 100 should
|
||||
result in a ban or exclusive selection of the relevant token.
|
||||
"""
|
||||
logprobs: Optional[bool] = None
|
||||
logprobs: bool | None = None
|
||||
"""Whether to return log probabilities of the output tokens or not. If true, returns the log
|
||||
probabilities of each
|
||||
output token returned in the content of message.
|
||||
"""
|
||||
max_tokens: Optional[int] = None
|
||||
max_tokens: int | None = None
|
||||
"""The maximum number of tokens that can be generated in the chat completion."""
|
||||
model: Optional[str] = None
|
||||
model: str | None = None
|
||||
"""[UNUSED] ID of the model to use. See the model endpoint compatibility table for details
|
||||
on which models work with the Chat API.
|
||||
"""
|
||||
n: Optional[int] = None
|
||||
n: int | None = None
|
||||
"""UNUSED
|
||||
How many chat completion choices to generate for each input message. Note that you will
|
||||
be charged based on the
|
||||
number of generated tokens across all of the choices. Keep n as 1 to minimize costs.
|
||||
"""
|
||||
presence_penalty: Optional[float] = None
|
||||
presence_penalty: float | None = None
|
||||
"""Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they
|
||||
appear in the text so far,
|
||||
increasing the model's likelihood to talk about new topics
|
||||
"""
|
||||
response_format: Optional[ChatCompletionInputGrammarType] = None
|
||||
seed: Optional[int] = None
|
||||
stop: Optional[list[str]] = None
|
||||
response_format: ChatCompletionInputGrammarType | None = None
|
||||
seed: int | None = None
|
||||
stop: list[str] | None = None
|
||||
"""Up to 4 sequences where the API will stop generating further tokens."""
|
||||
stream: Optional[bool] = None
|
||||
stream_options: Optional[ChatCompletionInputStreamOptions] = None
|
||||
temperature: Optional[float] = None
|
||||
stream: bool | None = None
|
||||
stream_options: ChatCompletionInputStreamOptions | None = None
|
||||
temperature: float | None = None
|
||||
"""What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the
|
||||
output more random, while
|
||||
lower values like 0.2 will make it more focused and deterministic.
|
||||
We generally recommend altering this or `top_p` but not both.
|
||||
"""
|
||||
tool_choice: Optional[Union[ChatCompletionInputToolChoiceClass, "ChatCompletionInputToolChoiceEnum"]] = None
|
||||
tool_prompt: Optional[str] = None
|
||||
tool_choice: Union[ChatCompletionInputToolChoiceClass, "ChatCompletionInputToolChoiceEnum"] | None = None
|
||||
tool_prompt: str | None = None
|
||||
"""A prompt to be appended before the tools"""
|
||||
tools: Optional[list[ChatCompletionInputTool]] = None
|
||||
tools: list[ChatCompletionInputTool] | None = None
|
||||
"""A list of tools the model may call. Currently, only functions are supported as a tool.
|
||||
Use this to provide a list of
|
||||
functions the model may generate JSON inputs for.
|
||||
"""
|
||||
top_logprobs: Optional[int] = None
|
||||
top_logprobs: int | None = None
|
||||
"""An integer between 0 and 5 specifying the number of most likely tokens to return at each
|
||||
token position, each with
|
||||
an associated log probability. logprobs must be set to true if this parameter is used.
|
||||
"""
|
||||
top_p: Optional[float] = None
|
||||
top_p: float | None = None
|
||||
"""An alternative to sampling with temperature, called nucleus sampling, where the model
|
||||
considers the results of the
|
||||
tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10%
|
||||
|
|
@ -225,7 +225,7 @@ class ChatCompletionOutputLogprobs(BaseInferenceType):
|
|||
class ChatCompletionOutputFunctionDefinition(BaseInferenceType):
|
||||
arguments: str
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
description: str | None = None
|
||||
|
||||
|
||||
@dataclass_with_extra
|
||||
|
|
@ -238,10 +238,10 @@ class ChatCompletionOutputToolCall(BaseInferenceType):
|
|||
@dataclass_with_extra
|
||||
class ChatCompletionOutputMessage(BaseInferenceType):
|
||||
role: str
|
||||
content: Optional[str] = None
|
||||
reasoning: Optional[str] = None
|
||||
tool_call_id: Optional[str] = None
|
||||
tool_calls: Optional[list[ChatCompletionOutputToolCall]] = None
|
||||
content: str | None = None
|
||||
reasoning: str | None = None
|
||||
tool_call_id: str | None = None
|
||||
tool_calls: list[ChatCompletionOutputToolCall] | None = None
|
||||
|
||||
|
||||
@dataclass_with_extra
|
||||
|
|
@ -249,7 +249,7 @@ class ChatCompletionOutputComplete(BaseInferenceType):
|
|||
finish_reason: str
|
||||
index: int
|
||||
message: ChatCompletionOutputMessage
|
||||
logprobs: Optional[ChatCompletionOutputLogprobs] = None
|
||||
logprobs: ChatCompletionOutputLogprobs | None = None
|
||||
|
||||
|
||||
@dataclass_with_extra
|
||||
|
|
@ -278,7 +278,7 @@ class ChatCompletionOutput(BaseInferenceType):
|
|||
@dataclass_with_extra
|
||||
class ChatCompletionStreamOutputFunction(BaseInferenceType):
|
||||
arguments: str
|
||||
name: Optional[str] = None
|
||||
name: str | None = None
|
||||
|
||||
|
||||
@dataclass_with_extra
|
||||
|
|
@ -292,10 +292,10 @@ class ChatCompletionStreamOutputDeltaToolCall(BaseInferenceType):
|
|||
@dataclass_with_extra
|
||||
class ChatCompletionStreamOutputDelta(BaseInferenceType):
|
||||
role: str
|
||||
content: Optional[str] = None
|
||||
reasoning: Optional[str] = None
|
||||
tool_call_id: Optional[str] = None
|
||||
tool_calls: Optional[list[ChatCompletionStreamOutputDeltaToolCall]] = None
|
||||
content: str | None = None
|
||||
reasoning: str | None = None
|
||||
tool_call_id: str | None = None
|
||||
tool_calls: list[ChatCompletionStreamOutputDeltaToolCall] | None = None
|
||||
|
||||
|
||||
@dataclass_with_extra
|
||||
|
|
@ -320,8 +320,8 @@ class ChatCompletionStreamOutputLogprobs(BaseInferenceType):
|
|||
class ChatCompletionStreamOutputChoice(BaseInferenceType):
|
||||
delta: ChatCompletionStreamOutputDelta
|
||||
index: int
|
||||
finish_reason: Optional[str] = None
|
||||
logprobs: Optional[ChatCompletionStreamOutputLogprobs] = None
|
||||
finish_reason: str | None = None
|
||||
logprobs: ChatCompletionStreamOutputLogprobs | None = None
|
||||
|
||||
|
||||
@dataclass_with_extra
|
||||
|
|
@ -344,4 +344,4 @@ class ChatCompletionStreamOutput(BaseInferenceType):
|
|||
id: str
|
||||
model: str
|
||||
system_fingerprint: str
|
||||
usage: Optional[ChatCompletionStreamOutputUsage] = None
|
||||
usage: ChatCompletionStreamOutputUsage | None = None
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# See:
|
||||
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
|
||||
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
from .base import BaseInferenceType, dataclass_with_extra
|
||||
|
||||
|
|
@ -14,7 +14,7 @@ class DepthEstimationInput(BaseInferenceType):
|
|||
|
||||
inputs: Any
|
||||
"""The input image data"""
|
||||
parameters: Optional[dict[str, Any]] = None
|
||||
parameters: dict[str, Any] | None = None
|
||||
"""Additional inference parameters for Depth Estimation"""
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# See:
|
||||
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
|
||||
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
|
||||
from typing import Any, Optional, Union
|
||||
from typing import Any
|
||||
|
||||
from .base import BaseInferenceType, dataclass_with_extra
|
||||
|
||||
|
|
@ -22,31 +22,31 @@ class DocumentQuestionAnsweringInputData(BaseInferenceType):
|
|||
class DocumentQuestionAnsweringParameters(BaseInferenceType):
|
||||
"""Additional inference parameters for Document Question Answering"""
|
||||
|
||||
doc_stride: Optional[int] = None
|
||||
doc_stride: int | None = None
|
||||
"""If the words in the document are too long to fit with the question for the model, it will
|
||||
be split in several chunks with some overlap. This argument controls the size of that
|
||||
overlap.
|
||||
"""
|
||||
handle_impossible_answer: Optional[bool] = None
|
||||
handle_impossible_answer: bool | None = None
|
||||
"""Whether to accept impossible as an answer"""
|
||||
lang: Optional[str] = None
|
||||
lang: str | None = None
|
||||
"""Language to use while running OCR. Defaults to english."""
|
||||
max_answer_len: Optional[int] = None
|
||||
max_answer_len: int | None = None
|
||||
"""The maximum length of predicted answers (e.g., only answers with a shorter length are
|
||||
considered).
|
||||
"""
|
||||
max_question_len: Optional[int] = None
|
||||
max_question_len: int | None = None
|
||||
"""The maximum length of the question after tokenization. It will be truncated if needed."""
|
||||
max_seq_len: Optional[int] = None
|
||||
max_seq_len: int | None = None
|
||||
"""The maximum length of the total sentence (context + question) in tokens of each chunk
|
||||
passed to the model. The context will be split in several chunks (using doc_stride as
|
||||
overlap) if needed.
|
||||
"""
|
||||
top_k: Optional[int] = None
|
||||
top_k: int | None = None
|
||||
"""The number of answers to return (will be chosen by order of likelihood). Can return less
|
||||
than top_k answers if there are not enough options available within the context.
|
||||
"""
|
||||
word_boxes: Optional[list[Union[list[float], str]]] = None
|
||||
word_boxes: list[list[float] | str] | None = None
|
||||
"""A list of words and bounding boxes (normalized 0->1000). If provided, the inference will
|
||||
skip the OCR step and use the provided bounding boxes instead.
|
||||
"""
|
||||
|
|
@ -58,7 +58,7 @@ class DocumentQuestionAnsweringInput(BaseInferenceType):
|
|||
|
||||
inputs: DocumentQuestionAnsweringInputData
|
||||
"""One (document, question) pair to answer"""
|
||||
parameters: Optional[DocumentQuestionAnsweringParameters] = None
|
||||
parameters: DocumentQuestionAnsweringParameters | None = None
|
||||
"""Additional inference parameters for Document Question Answering"""
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# See:
|
||||
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
|
||||
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
|
||||
from typing import Literal, Optional, Union
|
||||
from typing import Literal, Optional
|
||||
|
||||
from .base import BaseInferenceType, dataclass_with_extra
|
||||
|
||||
|
|
@ -19,10 +19,10 @@ class FeatureExtractionInput(BaseInferenceType):
|
|||
https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-tei-import.ts.
|
||||
"""
|
||||
|
||||
inputs: Union[list[str], str]
|
||||
inputs: list[str] | str
|
||||
"""The text or list of texts to embed."""
|
||||
normalize: Optional[bool] = None
|
||||
prompt_name: Optional[str] = None
|
||||
normalize: bool | None = None
|
||||
prompt_name: str | None = None
|
||||
"""The name of the prompt that should be used by for encoding. If not set, no prompt
|
||||
will be applied.
|
||||
Must be a key in the `sentence-transformers` configuration `prompts` dictionary.
|
||||
|
|
@ -32,5 +32,5 @@ class FeatureExtractionInput(BaseInferenceType):
|
|||
"query: What is the capital of France?" because the prompt text will be prepended before
|
||||
any text to encode.
|
||||
"""
|
||||
truncate: Optional[bool] = None
|
||||
truncate: bool | None = None
|
||||
truncation_direction: Optional["FeatureExtractionInputTruncationDirection"] = None
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# See:
|
||||
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
|
||||
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
from .base import BaseInferenceType, dataclass_with_extra
|
||||
|
||||
|
|
@ -12,13 +12,13 @@ from .base import BaseInferenceType, dataclass_with_extra
|
|||
class FillMaskParameters(BaseInferenceType):
|
||||
"""Additional inference parameters for Fill Mask"""
|
||||
|
||||
targets: Optional[list[str]] = None
|
||||
targets: list[str] | None = None
|
||||
"""When passed, the model will limit the scores to the passed targets instead of looking up
|
||||
in the whole vocabulary. If the provided targets are not in the model vocab, they will be
|
||||
tokenized and the first resulting token will be used (with a warning, and that might be
|
||||
slower).
|
||||
"""
|
||||
top_k: Optional[int] = None
|
||||
top_k: int | None = None
|
||||
"""When passed, overrides the number of predictions to return."""
|
||||
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ class FillMaskInput(BaseInferenceType):
|
|||
|
||||
inputs: str
|
||||
"""The text with masked tokens"""
|
||||
parameters: Optional[FillMaskParameters] = None
|
||||
parameters: FillMaskParameters | None = None
|
||||
"""Additional inference parameters for Fill Mask"""
|
||||
|
||||
|
||||
|
|
@ -43,5 +43,5 @@ class FillMaskOutputElement(BaseInferenceType):
|
|||
token: int
|
||||
"""The predicted token id (to replace the masked one)."""
|
||||
token_str: Any
|
||||
fill_mask_output_token_str: Optional[str] = None
|
||||
fill_mask_output_token_str: str | None = None
|
||||
"""The predicted token (to replace the masked one)."""
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class ImageClassificationParameters(BaseInferenceType):
|
|||
|
||||
function_to_apply: Optional["ImageClassificationOutputTransform"] = None
|
||||
"""The function to apply to the model outputs in order to retrieve the scores."""
|
||||
top_k: Optional[int] = None
|
||||
top_k: int | None = None
|
||||
"""When specified, limits the output to the top K most probable classes."""
|
||||
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ class ImageClassificationInput(BaseInferenceType):
|
|||
"""The input image data as a base64-encoded string. If no `parameters` are provided, you can
|
||||
also provide the image data as a raw bytes payload.
|
||||
"""
|
||||
parameters: Optional[ImageClassificationParameters] = None
|
||||
parameters: ImageClassificationParameters | None = None
|
||||
"""Additional inference parameters for Image Classification"""
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -15,13 +15,13 @@ ImageSegmentationSubtask = Literal["instance", "panoptic", "semantic"]
|
|||
class ImageSegmentationParameters(BaseInferenceType):
|
||||
"""Additional inference parameters for Image Segmentation"""
|
||||
|
||||
mask_threshold: Optional[float] = None
|
||||
mask_threshold: float | None = None
|
||||
"""Threshold to use when turning the predicted masks into binary values."""
|
||||
overlap_mask_area_threshold: Optional[float] = None
|
||||
overlap_mask_area_threshold: float | None = None
|
||||
"""Mask overlap threshold to eliminate small, disconnected segments."""
|
||||
subtask: Optional["ImageSegmentationSubtask"] = None
|
||||
"""Segmentation task to be performed, depending on model capabilities."""
|
||||
threshold: Optional[float] = None
|
||||
threshold: float | None = None
|
||||
"""Probability threshold to filter out predicted masks."""
|
||||
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ class ImageSegmentationInput(BaseInferenceType):
|
|||
"""The input image data as a base64-encoded string. If no `parameters` are provided, you can
|
||||
also provide the image data as a raw bytes payload.
|
||||
"""
|
||||
parameters: Optional[ImageSegmentationParameters] = None
|
||||
parameters: ImageSegmentationParameters | None = None
|
||||
"""Additional inference parameters for Image Segmentation"""
|
||||
|
||||
|
||||
|
|
@ -47,5 +47,5 @@ class ImageSegmentationOutputElement(BaseInferenceType):
|
|||
"""The label of the predicted segment."""
|
||||
mask: str
|
||||
"""The corresponding mask as a black-and-white image (base64-encoded)."""
|
||||
score: Optional[float] = None
|
||||
score: float | None = None
|
||||
"""The score or confidence degree the model has."""
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# See:
|
||||
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
|
||||
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
from .base import BaseInferenceType, dataclass_with_extra
|
||||
|
||||
|
|
@ -22,23 +22,23 @@ class ImageTextToImageTargetSize(BaseInferenceType):
|
|||
class ImageTextToImageParameters(BaseInferenceType):
|
||||
"""Additional inference parameters for Image Text To Image"""
|
||||
|
||||
guidance_scale: Optional[float] = None
|
||||
guidance_scale: float | None = None
|
||||
"""For diffusion models. A higher guidance scale value encourages the model to generate
|
||||
images closely linked to the text prompt at the expense of lower image quality.
|
||||
"""
|
||||
negative_prompt: Optional[str] = None
|
||||
negative_prompt: str | None = None
|
||||
"""One prompt to guide what NOT to include in image generation."""
|
||||
num_inference_steps: Optional[int] = None
|
||||
num_inference_steps: int | None = None
|
||||
"""For diffusion models. The number of denoising steps. More denoising steps usually lead to
|
||||
a higher quality image at the expense of slower inference.
|
||||
"""
|
||||
prompt: Optional[str] = None
|
||||
prompt: str | None = None
|
||||
"""The text prompt to guide the image generation. Either this or inputs (image) must be
|
||||
provided.
|
||||
"""
|
||||
seed: Optional[int] = None
|
||||
seed: int | None = None
|
||||
"""Seed for the random number generator."""
|
||||
target_size: Optional[ImageTextToImageTargetSize] = None
|
||||
target_size: ImageTextToImageTargetSize | None = None
|
||||
"""The size in pixels of the output image. This parameter is only supported by some
|
||||
providers and for specific models. It will be ignored when unsupported.
|
||||
"""
|
||||
|
|
@ -50,12 +50,12 @@ class ImageTextToImageInput(BaseInferenceType):
|
|||
must be provided, or both.
|
||||
"""
|
||||
|
||||
inputs: Optional[str] = None
|
||||
inputs: str | None = None
|
||||
"""The input image data as a base64-encoded string. If no `parameters` are provided, you can
|
||||
also provide the image data as a raw bytes payload. Either this or prompt must be
|
||||
provided.
|
||||
"""
|
||||
parameters: Optional[ImageTextToImageParameters] = None
|
||||
parameters: ImageTextToImageParameters | None = None
|
||||
"""Additional inference parameters for Image Text To Image"""
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# See:
|
||||
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
|
||||
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
from .base import BaseInferenceType, dataclass_with_extra
|
||||
|
||||
|
|
@ -20,25 +20,25 @@ class ImageTextToVideoTargetSize(BaseInferenceType):
|
|||
class ImageTextToVideoParameters(BaseInferenceType):
|
||||
"""Additional inference parameters for Image Text To Video"""
|
||||
|
||||
guidance_scale: Optional[float] = None
|
||||
guidance_scale: float | None = None
|
||||
"""For diffusion models. A higher guidance scale value encourages the model to generate
|
||||
videos closely linked to the text prompt at the expense of lower image quality.
|
||||
"""
|
||||
negative_prompt: Optional[str] = None
|
||||
negative_prompt: str | None = None
|
||||
"""One prompt to guide what NOT to include in video generation."""
|
||||
num_frames: Optional[float] = None
|
||||
num_frames: float | None = None
|
||||
"""The num_frames parameter determines how many video frames are generated."""
|
||||
num_inference_steps: Optional[int] = None
|
||||
num_inference_steps: int | None = None
|
||||
"""The number of denoising steps. More denoising steps usually lead to a higher quality
|
||||
video at the expense of slower inference.
|
||||
"""
|
||||
prompt: Optional[str] = None
|
||||
prompt: str | None = None
|
||||
"""The text prompt to guide the video generation. Either this or inputs (image) must be
|
||||
provided.
|
||||
"""
|
||||
seed: Optional[int] = None
|
||||
seed: int | None = None
|
||||
"""Seed for the random number generator."""
|
||||
target_size: Optional[ImageTextToVideoTargetSize] = None
|
||||
target_size: ImageTextToVideoTargetSize | None = None
|
||||
"""The size in pixel of the output video frames."""
|
||||
|
||||
|
||||
|
|
@ -48,12 +48,12 @@ class ImageTextToVideoInput(BaseInferenceType):
|
|||
must be provided, or both.
|
||||
"""
|
||||
|
||||
inputs: Optional[str] = None
|
||||
inputs: str | None = None
|
||||
"""The input image data as a base64-encoded string. If no `parameters` are provided, you can
|
||||
also provide the image data as a raw bytes payload. Either this or prompt must be
|
||||
provided.
|
||||
"""
|
||||
parameters: Optional[ImageTextToVideoParameters] = None
|
||||
parameters: ImageTextToVideoParameters | None = None
|
||||
"""Additional inference parameters for Image Text To Video"""
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# See:
|
||||
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
|
||||
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
from .base import BaseInferenceType, dataclass_with_extra
|
||||
|
||||
|
|
@ -22,19 +22,19 @@ class ImageToImageTargetSize(BaseInferenceType):
|
|||
class ImageToImageParameters(BaseInferenceType):
|
||||
"""Additional inference parameters for Image To Image"""
|
||||
|
||||
guidance_scale: Optional[float] = None
|
||||
guidance_scale: float | None = None
|
||||
"""For diffusion models. A higher guidance scale value encourages the model to generate
|
||||
images closely linked to the text prompt at the expense of lower image quality.
|
||||
"""
|
||||
negative_prompt: Optional[str] = None
|
||||
negative_prompt: str | None = None
|
||||
"""One prompt to guide what NOT to include in image generation."""
|
||||
num_inference_steps: Optional[int] = None
|
||||
num_inference_steps: int | None = None
|
||||
"""For diffusion models. The number of denoising steps. More denoising steps usually lead to
|
||||
a higher quality image at the expense of slower inference.
|
||||
"""
|
||||
prompt: Optional[str] = None
|
||||
prompt: str | None = None
|
||||
"""The text prompt to guide the image generation."""
|
||||
target_size: Optional[ImageToImageTargetSize] = None
|
||||
target_size: ImageToImageTargetSize | None = None
|
||||
"""The size in pixels of the output image. This parameter is only supported by some
|
||||
providers and for specific models. It will be ignored when unsupported.
|
||||
"""
|
||||
|
|
@ -48,7 +48,7 @@ class ImageToImageInput(BaseInferenceType):
|
|||
"""The input image data as a base64-encoded string. If no `parameters` are provided, you can
|
||||
also provide the image data as a raw bytes payload.
|
||||
"""
|
||||
parameters: Optional[ImageToImageParameters] = None
|
||||
parameters: ImageToImageParameters | None = None
|
||||
"""Additional inference parameters for Image To Image"""
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# See:
|
||||
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
|
||||
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
|
||||
from typing import Any, Literal, Optional, Union
|
||||
from typing import Any, Literal, Union
|
||||
|
||||
from .base import BaseInferenceType, dataclass_with_extra
|
||||
|
||||
|
|
@ -15,17 +15,17 @@ ImageToTextEarlyStoppingEnum = Literal["never"]
|
|||
class ImageToTextGenerationParameters(BaseInferenceType):
|
||||
"""Parametrization of the text generation process"""
|
||||
|
||||
do_sample: Optional[bool] = None
|
||||
do_sample: bool | None = None
|
||||
"""Whether to use sampling instead of greedy decoding when generating new tokens."""
|
||||
early_stopping: Optional[Union[bool, "ImageToTextEarlyStoppingEnum"]] = None
|
||||
early_stopping: Union[bool, "ImageToTextEarlyStoppingEnum"] | None = None
|
||||
"""Controls the stopping condition for beam-based methods."""
|
||||
epsilon_cutoff: Optional[float] = None
|
||||
epsilon_cutoff: float | None = None
|
||||
"""If set to float strictly between 0 and 1, only tokens with a conditional probability
|
||||
greater than epsilon_cutoff will be sampled. In the paper, suggested values range from
|
||||
3e-4 to 9e-4, depending on the size of the model. See [Truncation Sampling as Language
|
||||
Model Desmoothing](https://hf.co/papers/2210.15191) for more details.
|
||||
"""
|
||||
eta_cutoff: Optional[float] = None
|
||||
eta_cutoff: float | None = None
|
||||
"""Eta sampling is a hybrid of locally typical sampling and epsilon sampling. If set to
|
||||
float strictly between 0 and 1, a token is only considered if it is greater than either
|
||||
eta_cutoff or sqrt(eta_cutoff) * exp(-entropy(softmax(next_token_logits))). The latter
|
||||
|
|
@ -34,40 +34,40 @@ class ImageToTextGenerationParameters(BaseInferenceType):
|
|||
See [Truncation Sampling as Language Model Desmoothing](https://hf.co/papers/2210.15191)
|
||||
for more details.
|
||||
"""
|
||||
max_length: Optional[int] = None
|
||||
max_length: int | None = None
|
||||
"""The maximum length (in tokens) of the generated text, including the input."""
|
||||
max_new_tokens: Optional[int] = None
|
||||
max_new_tokens: int | None = None
|
||||
"""The maximum number of tokens to generate. Takes precedence over max_length."""
|
||||
min_length: Optional[int] = None
|
||||
min_length: int | None = None
|
||||
"""The minimum length (in tokens) of the generated text, including the input."""
|
||||
min_new_tokens: Optional[int] = None
|
||||
min_new_tokens: int | None = None
|
||||
"""The minimum number of tokens to generate. Takes precedence over min_length."""
|
||||
num_beam_groups: Optional[int] = None
|
||||
num_beam_groups: int | None = None
|
||||
"""Number of groups to divide num_beams into in order to ensure diversity among different
|
||||
groups of beams. See [this paper](https://hf.co/papers/1610.02424) for more details.
|
||||
"""
|
||||
num_beams: Optional[int] = None
|
||||
num_beams: int | None = None
|
||||
"""Number of beams to use for beam search."""
|
||||
penalty_alpha: Optional[float] = None
|
||||
penalty_alpha: float | None = None
|
||||
"""The value balances the model confidence and the degeneration penalty in contrastive
|
||||
search decoding.
|
||||
"""
|
||||
temperature: Optional[float] = None
|
||||
temperature: float | None = None
|
||||
"""The value used to modulate the next token probabilities."""
|
||||
top_k: Optional[int] = None
|
||||
top_k: int | None = None
|
||||
"""The number of highest probability vocabulary tokens to keep for top-k-filtering."""
|
||||
top_p: Optional[float] = None
|
||||
top_p: float | None = None
|
||||
"""If set to float < 1, only the smallest set of most probable tokens with probabilities
|
||||
that add up to top_p or higher are kept for generation.
|
||||
"""
|
||||
typical_p: Optional[float] = None
|
||||
typical_p: float | None = None
|
||||
"""Local typicality measures how similar the conditional probability of predicting a target
|
||||
token next is to the expected conditional probability of predicting a random token next,
|
||||
given the partial text already generated. If set to float < 1, the smallest set of the
|
||||
most locally typical tokens with probabilities that add up to typical_p or higher are
|
||||
kept for generation. See [this paper](https://hf.co/papers/2202.00666) for more details.
|
||||
"""
|
||||
use_cache: Optional[bool] = None
|
||||
use_cache: bool | None = None
|
||||
"""Whether the model should use the past last key/values attentions to speed up decoding"""
|
||||
|
||||
|
||||
|
|
@ -75,9 +75,9 @@ class ImageToTextGenerationParameters(BaseInferenceType):
|
|||
class ImageToTextParameters(BaseInferenceType):
|
||||
"""Additional inference parameters for Image To Text"""
|
||||
|
||||
generation_parameters: Optional[ImageToTextGenerationParameters] = None
|
||||
generation_parameters: ImageToTextGenerationParameters | None = None
|
||||
"""Parametrization of the text generation process"""
|
||||
max_new_tokens: Optional[int] = None
|
||||
max_new_tokens: int | None = None
|
||||
"""The amount of maximum tokens to generate."""
|
||||
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ class ImageToTextInput(BaseInferenceType):
|
|||
|
||||
inputs: Any
|
||||
"""The input image data"""
|
||||
parameters: Optional[ImageToTextParameters] = None
|
||||
parameters: ImageToTextParameters | None = None
|
||||
"""Additional inference parameters for Image To Text"""
|
||||
|
||||
|
||||
|
|
@ -96,5 +96,5 @@ class ImageToTextOutput(BaseInferenceType):
|
|||
"""Outputs of inference for the Image To Text task"""
|
||||
|
||||
generated_text: Any
|
||||
image_to_text_output_generated_text: Optional[str] = None
|
||||
image_to_text_output_generated_text: str | None = None
|
||||
"""The generated text."""
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# See:
|
||||
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
|
||||
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
from .base import BaseInferenceType, dataclass_with_extra
|
||||
|
||||
|
|
@ -20,23 +20,23 @@ class ImageToVideoTargetSize(BaseInferenceType):
|
|||
class ImageToVideoParameters(BaseInferenceType):
|
||||
"""Additional inference parameters for Image To Video"""
|
||||
|
||||
guidance_scale: Optional[float] = None
|
||||
guidance_scale: float | None = None
|
||||
"""For diffusion models. A higher guidance scale value encourages the model to generate
|
||||
videos closely linked to the text prompt at the expense of lower image quality.
|
||||
"""
|
||||
negative_prompt: Optional[str] = None
|
||||
negative_prompt: str | None = None
|
||||
"""One prompt to guide what NOT to include in video generation."""
|
||||
num_frames: Optional[float] = None
|
||||
num_frames: float | None = None
|
||||
"""The num_frames parameter determines how many video frames are generated."""
|
||||
num_inference_steps: Optional[int] = None
|
||||
num_inference_steps: int | None = None
|
||||
"""The number of denoising steps. More denoising steps usually lead to a higher quality
|
||||
video at the expense of slower inference.
|
||||
"""
|
||||
prompt: Optional[str] = None
|
||||
prompt: str | None = None
|
||||
"""The text prompt to guide the video generation."""
|
||||
seed: Optional[int] = None
|
||||
seed: int | None = None
|
||||
"""Seed for the random number generator."""
|
||||
target_size: Optional[ImageToVideoTargetSize] = None
|
||||
target_size: ImageToVideoTargetSize | None = None
|
||||
"""The size in pixel of the output video frames."""
|
||||
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ class ImageToVideoInput(BaseInferenceType):
|
|||
"""The input image data as a base64-encoded string. If no `parameters` are provided, you can
|
||||
also provide the image data as a raw bytes payload.
|
||||
"""
|
||||
parameters: Optional[ImageToVideoParameters] = None
|
||||
parameters: ImageToVideoParameters | None = None
|
||||
"""Additional inference parameters for Image To Video"""
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
# See:
|
||||
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
|
||||
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
|
||||
from typing import Optional
|
||||
|
||||
from .base import BaseInferenceType, dataclass_with_extra
|
||||
|
||||
|
||||
|
|
@ -12,7 +10,7 @@ from .base import BaseInferenceType, dataclass_with_extra
|
|||
class ObjectDetectionParameters(BaseInferenceType):
|
||||
"""Additional inference parameters for Object Detection"""
|
||||
|
||||
threshold: Optional[float] = None
|
||||
threshold: float | None = None
|
||||
"""The probability necessary to make a prediction."""
|
||||
|
||||
|
||||
|
|
@ -24,7 +22,7 @@ class ObjectDetectionInput(BaseInferenceType):
|
|||
"""The input image data as a base64-encoded string. If no `parameters` are provided, you can
|
||||
also provide the image data as a raw bytes payload.
|
||||
"""
|
||||
parameters: Optional[ObjectDetectionParameters] = None
|
||||
parameters: ObjectDetectionParameters | None = None
|
||||
"""Additional inference parameters for Object Detection"""
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
# See:
|
||||
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
|
||||
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
|
||||
from typing import Optional
|
||||
|
||||
from .base import BaseInferenceType, dataclass_with_extra
|
||||
|
||||
|
||||
|
|
@ -22,28 +20,28 @@ class QuestionAnsweringInputData(BaseInferenceType):
|
|||
class QuestionAnsweringParameters(BaseInferenceType):
|
||||
"""Additional inference parameters for Question Answering"""
|
||||
|
||||
align_to_words: Optional[bool] = None
|
||||
align_to_words: bool | None = None
|
||||
"""Attempts to align the answer to real words. Improves quality on space separated
|
||||
languages. Might hurt on non-space-separated languages (like Japanese or Chinese)
|
||||
"""
|
||||
doc_stride: Optional[int] = None
|
||||
doc_stride: int | None = None
|
||||
"""If the context is too long to fit with the question for the model, it will be split in
|
||||
several chunks with some overlap. This argument controls the size of that overlap.
|
||||
"""
|
||||
handle_impossible_answer: Optional[bool] = None
|
||||
handle_impossible_answer: bool | None = None
|
||||
"""Whether to accept impossible as an answer."""
|
||||
max_answer_len: Optional[int] = None
|
||||
max_answer_len: int | None = None
|
||||
"""The maximum length of predicted answers (e.g., only answers with a shorter length are
|
||||
considered).
|
||||
"""
|
||||
max_question_len: Optional[int] = None
|
||||
max_question_len: int | None = None
|
||||
"""The maximum length of the question after tokenization. It will be truncated if needed."""
|
||||
max_seq_len: Optional[int] = None
|
||||
max_seq_len: int | None = None
|
||||
"""The maximum length of the total sentence (context + question) in tokens of each chunk
|
||||
passed to the model. The context will be split in several chunks (using docStride as
|
||||
overlap) if needed.
|
||||
"""
|
||||
top_k: Optional[int] = None
|
||||
top_k: int | None = None
|
||||
"""The number of answers to return (will be chosen by order of likelihood). Note that we
|
||||
return less than topk answers if there are not enough options available within the
|
||||
context.
|
||||
|
|
@ -56,7 +54,7 @@ class QuestionAnsweringInput(BaseInferenceType):
|
|||
|
||||
inputs: QuestionAnsweringInputData
|
||||
"""One (context, question) pair to answer"""
|
||||
parameters: Optional[QuestionAnsweringParameters] = None
|
||||
parameters: QuestionAnsweringParameters | None = None
|
||||
"""Additional inference parameters for Question Answering"""
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# See:
|
||||
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
|
||||
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
from .base import BaseInferenceType, dataclass_with_extra
|
||||
|
||||
|
|
@ -23,5 +23,5 @@ class SentenceSimilarityInput(BaseInferenceType):
|
|||
"""Inputs for Sentence similarity inference"""
|
||||
|
||||
inputs: SentenceSimilarityInputData
|
||||
parameters: Optional[dict[str, Any]] = None
|
||||
parameters: dict[str, Any] | None = None
|
||||
"""Additional inference parameters for Sentence Similarity"""
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ SummarizationTruncationStrategy = Literal["do_not_truncate", "longest_first", "o
|
|||
class SummarizationParameters(BaseInferenceType):
|
||||
"""Additional inference parameters for summarization."""
|
||||
|
||||
clean_up_tokenization_spaces: Optional[bool] = None
|
||||
clean_up_tokenization_spaces: bool | None = None
|
||||
"""Whether to clean up the potential extra spaces in the text output."""
|
||||
generate_parameters: Optional[dict[str, Any]] = None
|
||||
generate_parameters: dict[str, Any] | None = None
|
||||
"""Additional parametrization of the text generation algorithm."""
|
||||
truncation: Optional["SummarizationTruncationStrategy"] = None
|
||||
"""The truncation strategy to use."""
|
||||
|
|
@ -29,7 +29,7 @@ class SummarizationInput(BaseInferenceType):
|
|||
|
||||
inputs: str
|
||||
"""The input text to summarize."""
|
||||
parameters: Optional[SummarizationParameters] = None
|
||||
parameters: SummarizationParameters | None = None
|
||||
"""Additional inference parameters for summarization."""
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -27,12 +27,12 @@ class TableQuestionAnsweringParameters(BaseInferenceType):
|
|||
|
||||
padding: Optional["Padding"] = None
|
||||
"""Activates and controls padding."""
|
||||
sequential: Optional[bool] = None
|
||||
sequential: bool | None = None
|
||||
"""Whether to do inference sequentially or as a batch. Batching is faster, but models like
|
||||
SQA require the inference to be done sequentially to extract relations within sequences,
|
||||
given their conversational nature.
|
||||
"""
|
||||
truncation: Optional[bool] = None
|
||||
truncation: bool | None = None
|
||||
"""Activates and controls truncation."""
|
||||
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ class TableQuestionAnsweringInput(BaseInferenceType):
|
|||
|
||||
inputs: TableQuestionAnsweringInputData
|
||||
"""One (table, question) pair to answer"""
|
||||
parameters: Optional[TableQuestionAnsweringParameters] = None
|
||||
parameters: TableQuestionAnsweringParameters | None = None
|
||||
"""Additional inference parameters for Table Question Answering"""
|
||||
|
||||
|
||||
|
|
@ -58,5 +58,5 @@ class TableQuestionAnsweringOutputElement(BaseInferenceType):
|
|||
"""list of strings made up of the answer cell values."""
|
||||
coordinates: list[list[int]]
|
||||
"""Coordinates of the cells of the answers."""
|
||||
aggregator: Optional[str] = None
|
||||
aggregator: str | None = None
|
||||
"""If the model has an aggregator, this returns the aggregator."""
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ Text2TextGenerationTruncationStrategy = Literal["do_not_truncate", "longest_firs
|
|||
class Text2TextGenerationParameters(BaseInferenceType):
|
||||
"""Additional inference parameters for Text2text Generation"""
|
||||
|
||||
clean_up_tokenization_spaces: Optional[bool] = None
|
||||
clean_up_tokenization_spaces: bool | None = None
|
||||
"""Whether to clean up the potential extra spaces in the text output."""
|
||||
generate_parameters: Optional[dict[str, Any]] = None
|
||||
generate_parameters: dict[str, Any] | None = None
|
||||
"""Additional parametrization of the text generation algorithm"""
|
||||
truncation: Optional["Text2TextGenerationTruncationStrategy"] = None
|
||||
"""The truncation strategy to use"""
|
||||
|
|
@ -29,7 +29,7 @@ class Text2TextGenerationInput(BaseInferenceType):
|
|||
|
||||
inputs: str
|
||||
"""The input text data"""
|
||||
parameters: Optional[Text2TextGenerationParameters] = None
|
||||
parameters: Text2TextGenerationParameters | None = None
|
||||
"""Additional inference parameters for Text2text Generation"""
|
||||
|
||||
|
||||
|
|
@ -38,5 +38,5 @@ class Text2TextGenerationOutput(BaseInferenceType):
|
|||
"""Outputs of inference for the Text2text Generation task"""
|
||||
|
||||
generated_text: Any
|
||||
text2_text_generation_output_generated_text: Optional[str] = None
|
||||
text2_text_generation_output_generated_text: str | None = None
|
||||
"""The generated text."""
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class TextClassificationParameters(BaseInferenceType):
|
|||
|
||||
function_to_apply: Optional["TextClassificationOutputTransform"] = None
|
||||
"""The function to apply to the model outputs in order to retrieve the scores."""
|
||||
top_k: Optional[int] = None
|
||||
top_k: int | None = None
|
||||
"""When specified, limits the output to the top K most probable classes."""
|
||||
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ class TextClassificationInput(BaseInferenceType):
|
|||
|
||||
inputs: str
|
||||
"""The text to classify"""
|
||||
parameters: Optional[TextClassificationParameters] = None
|
||||
parameters: TextClassificationParameters | None = None
|
||||
"""Additional inference parameters for Text Classification"""
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# See:
|
||||
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
|
||||
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
|
||||
from typing import Any, Literal, Optional
|
||||
from typing import Any, Literal
|
||||
|
||||
from .base import BaseInferenceType, dataclass_with_extra
|
||||
|
||||
|
|
@ -23,50 +23,50 @@ class TextGenerationInputGrammarType(BaseInferenceType):
|
|||
|
||||
@dataclass_with_extra
|
||||
class TextGenerationInputGenerateParameters(BaseInferenceType):
|
||||
adapter_id: Optional[str] = None
|
||||
adapter_id: str | None = None
|
||||
"""Lora adapter id"""
|
||||
best_of: Optional[int] = None
|
||||
best_of: int | None = None
|
||||
"""Generate best_of sequences and return the one if the highest token logprobs."""
|
||||
decoder_input_details: Optional[bool] = None
|
||||
decoder_input_details: bool | None = None
|
||||
"""Whether to return decoder input token logprobs and ids."""
|
||||
details: Optional[bool] = None
|
||||
details: bool | None = None
|
||||
"""Whether to return generation details."""
|
||||
do_sample: Optional[bool] = None
|
||||
do_sample: bool | None = None
|
||||
"""Activate logits sampling."""
|
||||
frequency_penalty: Optional[float] = None
|
||||
frequency_penalty: float | None = None
|
||||
"""The parameter for frequency penalty. 1.0 means no penalty
|
||||
Penalize new tokens based on their existing frequency in the text so far,
|
||||
decreasing the model's likelihood to repeat the same line verbatim.
|
||||
"""
|
||||
grammar: Optional[TextGenerationInputGrammarType] = None
|
||||
max_new_tokens: Optional[int] = None
|
||||
grammar: TextGenerationInputGrammarType | None = None
|
||||
max_new_tokens: int | None = None
|
||||
"""Maximum number of tokens to generate."""
|
||||
repetition_penalty: Optional[float] = None
|
||||
repetition_penalty: float | None = None
|
||||
"""The parameter for repetition penalty. 1.0 means no penalty.
|
||||
See [this paper](https://arxiv.org/pdf/1909.05858.pdf) for more details.
|
||||
"""
|
||||
return_full_text: Optional[bool] = None
|
||||
return_full_text: bool | None = None
|
||||
"""Whether to prepend the prompt to the generated text"""
|
||||
seed: Optional[int] = None
|
||||
seed: int | None = None
|
||||
"""Random sampling seed."""
|
||||
stop: Optional[list[str]] = None
|
||||
stop: list[str] | None = None
|
||||
"""Stop generating tokens if a member of `stop` is generated."""
|
||||
temperature: Optional[float] = None
|
||||
temperature: float | None = None
|
||||
"""The value used to module the logits distribution."""
|
||||
top_k: Optional[int] = None
|
||||
top_k: int | None = None
|
||||
"""The number of highest probability vocabulary tokens to keep for top-k-filtering."""
|
||||
top_n_tokens: Optional[int] = None
|
||||
top_n_tokens: int | None = None
|
||||
"""The number of highest probability vocabulary tokens to keep for top-n-filtering."""
|
||||
top_p: Optional[float] = None
|
||||
top_p: float | None = None
|
||||
"""Top-p value for nucleus sampling."""
|
||||
truncate: Optional[int] = None
|
||||
truncate: int | None = None
|
||||
"""Truncate inputs tokens to the given size."""
|
||||
typical_p: Optional[float] = None
|
||||
typical_p: float | None = None
|
||||
"""Typical Decoding mass
|
||||
See [Typical Decoding for Natural Language Generation](https://arxiv.org/abs/2202.00666)
|
||||
for more information.
|
||||
"""
|
||||
watermark: Optional[bool] = None
|
||||
watermark: bool | None = None
|
||||
"""Watermarking with [A Watermark for Large Language
|
||||
Models](https://arxiv.org/abs/2301.10226).
|
||||
"""
|
||||
|
|
@ -81,8 +81,8 @@ class TextGenerationInput(BaseInferenceType):
|
|||
"""
|
||||
|
||||
inputs: str
|
||||
parameters: Optional[TextGenerationInputGenerateParameters] = None
|
||||
stream: Optional[bool] = None
|
||||
parameters: TextGenerationInputGenerateParameters | None = None
|
||||
stream: bool | None = None
|
||||
|
||||
|
||||
TextGenerationOutputFinishReason = Literal["length", "eos_token", "stop_sequence"]
|
||||
|
|
@ -110,8 +110,8 @@ class TextGenerationOutputBestOfSequence(BaseInferenceType):
|
|||
generated_tokens: int
|
||||
prefill: list[TextGenerationOutputPrefillToken]
|
||||
tokens: list[TextGenerationOutputToken]
|
||||
seed: Optional[int] = None
|
||||
top_tokens: Optional[list[list[TextGenerationOutputToken]]] = None
|
||||
seed: int | None = None
|
||||
top_tokens: list[list[TextGenerationOutputToken]] | None = None
|
||||
|
||||
|
||||
@dataclass_with_extra
|
||||
|
|
@ -120,9 +120,9 @@ class TextGenerationOutputDetails(BaseInferenceType):
|
|||
generated_tokens: int
|
||||
prefill: list[TextGenerationOutputPrefillToken]
|
||||
tokens: list[TextGenerationOutputToken]
|
||||
best_of_sequences: Optional[list[TextGenerationOutputBestOfSequence]] = None
|
||||
seed: Optional[int] = None
|
||||
top_tokens: Optional[list[list[TextGenerationOutputToken]]] = None
|
||||
best_of_sequences: list[TextGenerationOutputBestOfSequence] | None = None
|
||||
seed: int | None = None
|
||||
top_tokens: list[list[TextGenerationOutputToken]] | None = None
|
||||
|
||||
|
||||
@dataclass_with_extra
|
||||
|
|
@ -134,7 +134,7 @@ class TextGenerationOutput(BaseInferenceType):
|
|||
"""
|
||||
|
||||
generated_text: str
|
||||
details: Optional[TextGenerationOutputDetails] = None
|
||||
details: TextGenerationOutputDetails | None = None
|
||||
|
||||
|
||||
@dataclass_with_extra
|
||||
|
|
@ -142,7 +142,7 @@ class TextGenerationStreamOutputStreamDetails(BaseInferenceType):
|
|||
finish_reason: "TextGenerationOutputFinishReason"
|
||||
generated_tokens: int
|
||||
input_length: int
|
||||
seed: Optional[int] = None
|
||||
seed: int | None = None
|
||||
|
||||
|
||||
@dataclass_with_extra
|
||||
|
|
@ -163,6 +163,6 @@ class TextGenerationStreamOutput(BaseInferenceType):
|
|||
|
||||
index: int
|
||||
token: TextGenerationStreamOutputToken
|
||||
details: Optional[TextGenerationStreamOutputStreamDetails] = None
|
||||
generated_text: Optional[str] = None
|
||||
top_tokens: Optional[list[TextGenerationStreamOutputToken]] = None
|
||||
details: TextGenerationStreamOutputStreamDetails | None = None
|
||||
generated_text: str | None = None
|
||||
top_tokens: list[TextGenerationStreamOutputToken] | None = None
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# See:
|
||||
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
|
||||
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
|
||||
from typing import Any, Literal, Optional, Union
|
||||
from typing import Any, Literal, Union
|
||||
|
||||
from .base import BaseInferenceType, dataclass_with_extra
|
||||
|
||||
|
|
@ -15,17 +15,17 @@ TextToAudioEarlyStoppingEnum = Literal["never"]
|
|||
class TextToAudioGenerationParameters(BaseInferenceType):
|
||||
"""Parametrization of the text generation process"""
|
||||
|
||||
do_sample: Optional[bool] = None
|
||||
do_sample: bool | None = None
|
||||
"""Whether to use sampling instead of greedy decoding when generating new tokens."""
|
||||
early_stopping: Optional[Union[bool, "TextToAudioEarlyStoppingEnum"]] = None
|
||||
early_stopping: Union[bool, "TextToAudioEarlyStoppingEnum"] | None = None
|
||||
"""Controls the stopping condition for beam-based methods."""
|
||||
epsilon_cutoff: Optional[float] = None
|
||||
epsilon_cutoff: float | None = None
|
||||
"""If set to float strictly between 0 and 1, only tokens with a conditional probability
|
||||
greater than epsilon_cutoff will be sampled. In the paper, suggested values range from
|
||||
3e-4 to 9e-4, depending on the size of the model. See [Truncation Sampling as Language
|
||||
Model Desmoothing](https://hf.co/papers/2210.15191) for more details.
|
||||
"""
|
||||
eta_cutoff: Optional[float] = None
|
||||
eta_cutoff: float | None = None
|
||||
"""Eta sampling is a hybrid of locally typical sampling and epsilon sampling. If set to
|
||||
float strictly between 0 and 1, a token is only considered if it is greater than either
|
||||
eta_cutoff or sqrt(eta_cutoff) * exp(-entropy(softmax(next_token_logits))). The latter
|
||||
|
|
@ -34,40 +34,40 @@ class TextToAudioGenerationParameters(BaseInferenceType):
|
|||
See [Truncation Sampling as Language Model Desmoothing](https://hf.co/papers/2210.15191)
|
||||
for more details.
|
||||
"""
|
||||
max_length: Optional[int] = None
|
||||
max_length: int | None = None
|
||||
"""The maximum length (in tokens) of the generated text, including the input."""
|
||||
max_new_tokens: Optional[int] = None
|
||||
max_new_tokens: int | None = None
|
||||
"""The maximum number of tokens to generate. Takes precedence over max_length."""
|
||||
min_length: Optional[int] = None
|
||||
min_length: int | None = None
|
||||
"""The minimum length (in tokens) of the generated text, including the input."""
|
||||
min_new_tokens: Optional[int] = None
|
||||
min_new_tokens: int | None = None
|
||||
"""The minimum number of tokens to generate. Takes precedence over min_length."""
|
||||
num_beam_groups: Optional[int] = None
|
||||
num_beam_groups: int | None = None
|
||||
"""Number of groups to divide num_beams into in order to ensure diversity among different
|
||||
groups of beams. See [this paper](https://hf.co/papers/1610.02424) for more details.
|
||||
"""
|
||||
num_beams: Optional[int] = None
|
||||
num_beams: int | None = None
|
||||
"""Number of beams to use for beam search."""
|
||||
penalty_alpha: Optional[float] = None
|
||||
penalty_alpha: float | None = None
|
||||
"""The value balances the model confidence and the degeneration penalty in contrastive
|
||||
search decoding.
|
||||
"""
|
||||
temperature: Optional[float] = None
|
||||
temperature: float | None = None
|
||||
"""The value used to modulate the next token probabilities."""
|
||||
top_k: Optional[int] = None
|
||||
top_k: int | None = None
|
||||
"""The number of highest probability vocabulary tokens to keep for top-k-filtering."""
|
||||
top_p: Optional[float] = None
|
||||
top_p: float | None = None
|
||||
"""If set to float < 1, only the smallest set of most probable tokens with probabilities
|
||||
that add up to top_p or higher are kept for generation.
|
||||
"""
|
||||
typical_p: Optional[float] = None
|
||||
typical_p: float | None = None
|
||||
"""Local typicality measures how similar the conditional probability of predicting a target
|
||||
token next is to the expected conditional probability of predicting a random token next,
|
||||
given the partial text already generated. If set to float < 1, the smallest set of the
|
||||
most locally typical tokens with probabilities that add up to typical_p or higher are
|
||||
kept for generation. See [this paper](https://hf.co/papers/2202.00666) for more details.
|
||||
"""
|
||||
use_cache: Optional[bool] = None
|
||||
use_cache: bool | None = None
|
||||
"""Whether the model should use the past last key/values attentions to speed up decoding"""
|
||||
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ class TextToAudioGenerationParameters(BaseInferenceType):
|
|||
class TextToAudioParameters(BaseInferenceType):
|
||||
"""Additional inference parameters for Text To Audio"""
|
||||
|
||||
generation_parameters: Optional[TextToAudioGenerationParameters] = None
|
||||
generation_parameters: TextToAudioGenerationParameters | None = None
|
||||
"""Parametrization of the text generation process"""
|
||||
|
||||
|
||||
|
|
@ -85,7 +85,7 @@ class TextToAudioInput(BaseInferenceType):
|
|||
|
||||
inputs: str
|
||||
"""The input text data"""
|
||||
parameters: Optional[TextToAudioParameters] = None
|
||||
parameters: TextToAudioParameters | None = None
|
||||
"""Additional inference parameters for Text To Audio"""
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# See:
|
||||
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
|
||||
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
from .base import BaseInferenceType, dataclass_with_extra
|
||||
|
||||
|
|
@ -12,23 +12,23 @@ from .base import BaseInferenceType, dataclass_with_extra
|
|||
class TextToImageParameters(BaseInferenceType):
|
||||
"""Additional inference parameters for Text To Image"""
|
||||
|
||||
guidance_scale: Optional[float] = None
|
||||
guidance_scale: float | None = None
|
||||
"""A higher guidance scale value encourages the model to generate images closely linked to
|
||||
the text prompt, but values too high may cause saturation and other artifacts.
|
||||
"""
|
||||
height: Optional[int] = None
|
||||
height: int | None = None
|
||||
"""The height in pixels of the output image"""
|
||||
negative_prompt: Optional[str] = None
|
||||
negative_prompt: str | None = None
|
||||
"""One prompt to guide what NOT to include in image generation."""
|
||||
num_inference_steps: Optional[int] = None
|
||||
num_inference_steps: int | None = None
|
||||
"""The number of denoising steps. More denoising steps usually lead to a higher quality
|
||||
image at the expense of slower inference.
|
||||
"""
|
||||
scheduler: Optional[str] = None
|
||||
scheduler: str | None = None
|
||||
"""Override the scheduler with a compatible one."""
|
||||
seed: Optional[int] = None
|
||||
seed: int | None = None
|
||||
"""Seed for the random number generator."""
|
||||
width: Optional[int] = None
|
||||
width: int | None = None
|
||||
"""The width in pixels of the output image"""
|
||||
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ class TextToImageInput(BaseInferenceType):
|
|||
|
||||
inputs: str
|
||||
"""The input text data (sometimes called "prompt")"""
|
||||
parameters: Optional[TextToImageParameters] = None
|
||||
parameters: TextToImageParameters | None = None
|
||||
"""Additional inference parameters for Text To Image"""
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# See:
|
||||
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
|
||||
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
|
||||
from typing import Any, Literal, Optional, Union
|
||||
from typing import Any, Literal, Union
|
||||
|
||||
from .base import BaseInferenceType, dataclass_with_extra
|
||||
|
||||
|
|
@ -15,17 +15,17 @@ TextToSpeechEarlyStoppingEnum = Literal["never"]
|
|||
class TextToSpeechGenerationParameters(BaseInferenceType):
|
||||
"""Parametrization of the text generation process"""
|
||||
|
||||
do_sample: Optional[bool] = None
|
||||
do_sample: bool | None = None
|
||||
"""Whether to use sampling instead of greedy decoding when generating new tokens."""
|
||||
early_stopping: Optional[Union[bool, "TextToSpeechEarlyStoppingEnum"]] = None
|
||||
early_stopping: Union[bool, "TextToSpeechEarlyStoppingEnum"] | None = None
|
||||
"""Controls the stopping condition for beam-based methods."""
|
||||
epsilon_cutoff: Optional[float] = None
|
||||
epsilon_cutoff: float | None = None
|
||||
"""If set to float strictly between 0 and 1, only tokens with a conditional probability
|
||||
greater than epsilon_cutoff will be sampled. In the paper, suggested values range from
|
||||
3e-4 to 9e-4, depending on the size of the model. See [Truncation Sampling as Language
|
||||
Model Desmoothing](https://hf.co/papers/2210.15191) for more details.
|
||||
"""
|
||||
eta_cutoff: Optional[float] = None
|
||||
eta_cutoff: float | None = None
|
||||
"""Eta sampling is a hybrid of locally typical sampling and epsilon sampling. If set to
|
||||
float strictly between 0 and 1, a token is only considered if it is greater than either
|
||||
eta_cutoff or sqrt(eta_cutoff) * exp(-entropy(softmax(next_token_logits))). The latter
|
||||
|
|
@ -34,40 +34,40 @@ class TextToSpeechGenerationParameters(BaseInferenceType):
|
|||
See [Truncation Sampling as Language Model Desmoothing](https://hf.co/papers/2210.15191)
|
||||
for more details.
|
||||
"""
|
||||
max_length: Optional[int] = None
|
||||
max_length: int | None = None
|
||||
"""The maximum length (in tokens) of the generated text, including the input."""
|
||||
max_new_tokens: Optional[int] = None
|
||||
max_new_tokens: int | None = None
|
||||
"""The maximum number of tokens to generate. Takes precedence over max_length."""
|
||||
min_length: Optional[int] = None
|
||||
min_length: int | None = None
|
||||
"""The minimum length (in tokens) of the generated text, including the input."""
|
||||
min_new_tokens: Optional[int] = None
|
||||
min_new_tokens: int | None = None
|
||||
"""The minimum number of tokens to generate. Takes precedence over min_length."""
|
||||
num_beam_groups: Optional[int] = None
|
||||
num_beam_groups: int | None = None
|
||||
"""Number of groups to divide num_beams into in order to ensure diversity among different
|
||||
groups of beams. See [this paper](https://hf.co/papers/1610.02424) for more details.
|
||||
"""
|
||||
num_beams: Optional[int] = None
|
||||
num_beams: int | None = None
|
||||
"""Number of beams to use for beam search."""
|
||||
penalty_alpha: Optional[float] = None
|
||||
penalty_alpha: float | None = None
|
||||
"""The value balances the model confidence and the degeneration penalty in contrastive
|
||||
search decoding.
|
||||
"""
|
||||
temperature: Optional[float] = None
|
||||
temperature: float | None = None
|
||||
"""The value used to modulate the next token probabilities."""
|
||||
top_k: Optional[int] = None
|
||||
top_k: int | None = None
|
||||
"""The number of highest probability vocabulary tokens to keep for top-k-filtering."""
|
||||
top_p: Optional[float] = None
|
||||
top_p: float | None = None
|
||||
"""If set to float < 1, only the smallest set of most probable tokens with probabilities
|
||||
that add up to top_p or higher are kept for generation.
|
||||
"""
|
||||
typical_p: Optional[float] = None
|
||||
typical_p: float | None = None
|
||||
"""Local typicality measures how similar the conditional probability of predicting a target
|
||||
token next is to the expected conditional probability of predicting a random token next,
|
||||
given the partial text already generated. If set to float < 1, the smallest set of the
|
||||
most locally typical tokens with probabilities that add up to typical_p or higher are
|
||||
kept for generation. See [this paper](https://hf.co/papers/2202.00666) for more details.
|
||||
"""
|
||||
use_cache: Optional[bool] = None
|
||||
use_cache: bool | None = None
|
||||
"""Whether the model should use the past last key/values attentions to speed up decoding"""
|
||||
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ class TextToSpeechGenerationParameters(BaseInferenceType):
|
|||
class TextToSpeechParameters(BaseInferenceType):
|
||||
"""Additional inference parameters for Text To Speech"""
|
||||
|
||||
generation_parameters: Optional[TextToSpeechGenerationParameters] = None
|
||||
generation_parameters: TextToSpeechGenerationParameters | None = None
|
||||
"""Parametrization of the text generation process"""
|
||||
|
||||
|
||||
|
|
@ -85,7 +85,7 @@ class TextToSpeechInput(BaseInferenceType):
|
|||
|
||||
inputs: str
|
||||
"""The input text data"""
|
||||
parameters: Optional[TextToSpeechParameters] = None
|
||||
parameters: TextToSpeechParameters | None = None
|
||||
"""Additional inference parameters for Text To Speech"""
|
||||
|
||||
|
||||
|
|
@ -95,5 +95,5 @@ class TextToSpeechOutput(BaseInferenceType):
|
|||
|
||||
audio: Any
|
||||
"""The generated audio"""
|
||||
sampling_rate: Optional[float] = None
|
||||
sampling_rate: float | None = None
|
||||
"""The sampling rate of the generated audio waveform."""
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# See:
|
||||
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
|
||||
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
from .base import BaseInferenceType, dataclass_with_extra
|
||||
|
||||
|
|
@ -12,19 +12,19 @@ from .base import BaseInferenceType, dataclass_with_extra
|
|||
class TextToVideoParameters(BaseInferenceType):
|
||||
"""Additional inference parameters for Text To Video"""
|
||||
|
||||
guidance_scale: Optional[float] = None
|
||||
guidance_scale: float | None = None
|
||||
"""A higher guidance scale value encourages the model to generate videos closely linked to
|
||||
the text prompt, but values too high may cause saturation and other artifacts.
|
||||
"""
|
||||
negative_prompt: Optional[list[str]] = None
|
||||
negative_prompt: list[str] | None = None
|
||||
"""One or several prompt to guide what NOT to include in video generation."""
|
||||
num_frames: Optional[float] = None
|
||||
num_frames: float | None = None
|
||||
"""The num_frames parameter determines how many video frames are generated."""
|
||||
num_inference_steps: Optional[int] = None
|
||||
num_inference_steps: int | None = None
|
||||
"""The number of denoising steps. More denoising steps usually lead to a higher quality
|
||||
video at the expense of slower inference.
|
||||
"""
|
||||
seed: Optional[int] = None
|
||||
seed: int | None = None
|
||||
"""Seed for the random number generator."""
|
||||
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ class TextToVideoInput(BaseInferenceType):
|
|||
|
||||
inputs: str
|
||||
"""The input text data (sometimes called "prompt")"""
|
||||
parameters: Optional[TextToVideoParameters] = None
|
||||
parameters: TextToVideoParameters | None = None
|
||||
"""Additional inference parameters for Text To Video"""
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@ class TokenClassificationParameters(BaseInferenceType):
|
|||
|
||||
aggregation_strategy: Optional["TokenClassificationAggregationStrategy"] = None
|
||||
"""The strategy used to fuse tokens based on model predictions"""
|
||||
ignore_labels: Optional[list[str]] = None
|
||||
ignore_labels: list[str] | None = None
|
||||
"""A list of labels to ignore"""
|
||||
stride: Optional[int] = None
|
||||
stride: int | None = None
|
||||
"""The number of overlapping tokens between chunks when splitting the input text."""
|
||||
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ class TokenClassificationInput(BaseInferenceType):
|
|||
|
||||
inputs: str
|
||||
"""The input text data"""
|
||||
parameters: Optional[TokenClassificationParameters] = None
|
||||
parameters: TokenClassificationParameters | None = None
|
||||
"""Additional inference parameters for Token Classification"""
|
||||
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ class TokenClassificationOutputElement(BaseInferenceType):
|
|||
"""The character position in the input where this group begins."""
|
||||
word: str
|
||||
"""The corresponding text"""
|
||||
entity: Optional[str] = None
|
||||
entity: str | None = None
|
||||
"""The predicted label for a single token"""
|
||||
entity_group: Optional[str] = None
|
||||
entity_group: str | None = None
|
||||
"""The predicted label for a group of one or more tokens"""
|
||||
|
|
|
|||
|
|
@ -15,15 +15,15 @@ TranslationTruncationStrategy = Literal["do_not_truncate", "longest_first", "onl
|
|||
class TranslationParameters(BaseInferenceType):
|
||||
"""Additional inference parameters for Translation"""
|
||||
|
||||
clean_up_tokenization_spaces: Optional[bool] = None
|
||||
clean_up_tokenization_spaces: bool | None = None
|
||||
"""Whether to clean up the potential extra spaces in the text output."""
|
||||
generate_parameters: Optional[dict[str, Any]] = None
|
||||
generate_parameters: dict[str, Any] | None = None
|
||||
"""Additional parametrization of the text generation algorithm."""
|
||||
src_lang: Optional[str] = None
|
||||
src_lang: str | None = None
|
||||
"""The source language of the text. Required for models that can translate from multiple
|
||||
languages.
|
||||
"""
|
||||
tgt_lang: Optional[str] = None
|
||||
tgt_lang: str | None = None
|
||||
"""Target language to translate to. Required for models that can translate to multiple
|
||||
languages.
|
||||
"""
|
||||
|
|
@ -37,7 +37,7 @@ class TranslationInput(BaseInferenceType):
|
|||
|
||||
inputs: str
|
||||
"""The text to translate."""
|
||||
parameters: Optional[TranslationParameters] = None
|
||||
parameters: TranslationParameters | None = None
|
||||
"""Additional inference parameters for Translation"""
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -15,13 +15,13 @@ VideoClassificationOutputTransform = Literal["sigmoid", "softmax", "none"]
|
|||
class VideoClassificationParameters(BaseInferenceType):
|
||||
"""Additional inference parameters for Video Classification"""
|
||||
|
||||
frame_sampling_rate: Optional[int] = None
|
||||
frame_sampling_rate: int | None = None
|
||||
"""The sampling rate used to select frames from the video."""
|
||||
function_to_apply: Optional["VideoClassificationOutputTransform"] = None
|
||||
"""The function to apply to the model outputs in order to retrieve the scores."""
|
||||
num_frames: Optional[int] = None
|
||||
num_frames: int | None = None
|
||||
"""The number of sampled frames to consider for classification."""
|
||||
top_k: Optional[int] = None
|
||||
top_k: int | None = None
|
||||
"""When specified, limits the output to the top K most probable classes."""
|
||||
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ class VideoClassificationInput(BaseInferenceType):
|
|||
|
||||
inputs: Any
|
||||
"""The input video data"""
|
||||
parameters: Optional[VideoClassificationParameters] = None
|
||||
parameters: VideoClassificationParameters | None = None
|
||||
"""Additional inference parameters for Video Classification"""
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# See:
|
||||
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
|
||||
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
from .base import BaseInferenceType, dataclass_with_extra
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ class VisualQuestionAnsweringInputData(BaseInferenceType):
|
|||
class VisualQuestionAnsweringParameters(BaseInferenceType):
|
||||
"""Additional inference parameters for Visual Question Answering"""
|
||||
|
||||
top_k: Optional[int] = None
|
||||
top_k: int | None = None
|
||||
"""The number of answers to return (will be chosen by order of likelihood). Note that we
|
||||
return less than topk answers if there are not enough options available within the
|
||||
context.
|
||||
|
|
@ -35,7 +35,7 @@ class VisualQuestionAnsweringInput(BaseInferenceType):
|
|||
|
||||
inputs: VisualQuestionAnsweringInputData
|
||||
"""One (image, question) pair to answer"""
|
||||
parameters: Optional[VisualQuestionAnsweringParameters] = None
|
||||
parameters: VisualQuestionAnsweringParameters | None = None
|
||||
"""Additional inference parameters for Visual Question Answering"""
|
||||
|
||||
|
||||
|
|
@ -45,5 +45,5 @@ class VisualQuestionAnsweringOutputElement(BaseInferenceType):
|
|||
|
||||
score: float
|
||||
"""The associated score / probability"""
|
||||
answer: Optional[str] = None
|
||||
answer: str | None = None
|
||||
"""The answer to the question"""
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
# See:
|
||||
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
|
||||
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
|
||||
from typing import Optional
|
||||
|
||||
from .base import BaseInferenceType, dataclass_with_extra
|
||||
|
||||
|
||||
|
|
@ -14,11 +12,11 @@ class ZeroShotClassificationParameters(BaseInferenceType):
|
|||
|
||||
candidate_labels: list[str]
|
||||
"""The set of possible class labels to classify the text into."""
|
||||
hypothesis_template: Optional[str] = None
|
||||
hypothesis_template: str | None = None
|
||||
"""The sentence used in conjunction with `candidate_labels` to attempt the text
|
||||
classification by replacing the placeholder with the candidate labels.
|
||||
"""
|
||||
multi_label: Optional[bool] = None
|
||||
multi_label: bool | None = None
|
||||
"""Whether multiple candidate labels can be true. If false, the scores are normalized such
|
||||
that the sum of the label likelihoods for each sequence is 1. If true, the labels are
|
||||
considered independent and probabilities are normalized for each candidate.
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
# See:
|
||||
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
|
||||
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
|
||||
from typing import Optional
|
||||
|
||||
from .base import BaseInferenceType, dataclass_with_extra
|
||||
|
||||
|
||||
|
|
@ -14,7 +12,7 @@ class ZeroShotImageClassificationParameters(BaseInferenceType):
|
|||
|
||||
candidate_labels: list[str]
|
||||
"""The candidate labels for this image"""
|
||||
hypothesis_template: Optional[str] = None
|
||||
hypothesis_template: str | None = None
|
||||
"""The sentence used in conjunction with `candidate_labels` to attempt the image
|
||||
classification by replacing the placeholder with the candidate labels.
|
||||
"""
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -150,7 +150,7 @@ async def run_agent(
|
|||
config["apiKey"] = substituted_api_key
|
||||
# Main agent loop
|
||||
async with Agent(
|
||||
provider=config.get("provider"), # type: ignore[arg-type]
|
||||
provider=config.get("provider"), # type: ignore
|
||||
model=config.get("model"),
|
||||
base_url=config.get("endpointUrl"), # type: ignore[arg-type]
|
||||
api_key=config.get("apiKey"),
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ problem and think insightfully.
|
|||
|
||||
MAX_NUM_TURNS = 10
|
||||
|
||||
TASK_COMPLETE_TOOL: ChatCompletionInputTool = ChatCompletionInputTool.parse_obj( # type: ignore[assignment]
|
||||
TASK_COMPLETE_TOOL: ChatCompletionInputTool = ChatCompletionInputTool.parse_obj( # type: ignore
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
|
|
@ -61,7 +61,7 @@ TASK_COMPLETE_TOOL: ChatCompletionInputTool = ChatCompletionInputTool.parse_obj(
|
|||
}
|
||||
)
|
||||
|
||||
ASK_QUESTION_TOOL: ChatCompletionInputTool = ChatCompletionInputTool.parse_obj( # type: ignore[assignment]
|
||||
ASK_QUESTION_TOOL: ChatCompletionInputTool = ChatCompletionInputTool.parse_obj( # type: ignore
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
|
|
|
|||
|
|
@ -39,33 +39,35 @@ def format_result(result: "mcp_types.CallToolResult") -> str:
|
|||
formatted_parts: list[str] = []
|
||||
|
||||
for item in content:
|
||||
if item.type == "text":
|
||||
formatted_parts.append(item.text)
|
||||
match item.type:
|
||||
case "text":
|
||||
formatted_parts.append(item.text)
|
||||
|
||||
elif item.type == "image":
|
||||
formatted_parts.append(
|
||||
f"[Binary Content: Image {item.mimeType}, {_get_base64_size(item.data)} bytes]\n"
|
||||
f"The task is complete and the content accessible to the User"
|
||||
)
|
||||
|
||||
elif item.type == "audio":
|
||||
formatted_parts.append(
|
||||
f"[Binary Content: Audio {item.mimeType}, {_get_base64_size(item.data)} bytes]\n"
|
||||
f"The task is complete and the content accessible to the User"
|
||||
)
|
||||
|
||||
elif item.type == "resource":
|
||||
resource = item.resource
|
||||
|
||||
if hasattr(resource, "text") and isinstance(resource.text, str):
|
||||
formatted_parts.append(resource.text)
|
||||
|
||||
elif hasattr(resource, "blob") and isinstance(resource.blob, str):
|
||||
case "image":
|
||||
formatted_parts.append(
|
||||
f"[Binary Content ({resource.uri}): {resource.mimeType}, {_get_base64_size(resource.blob)} bytes]\n"
|
||||
f"[Binary Content: Image {item.mimeType}, {_get_base64_size(item.data)} bytes]\n"
|
||||
f"The task is complete and the content accessible to the User"
|
||||
)
|
||||
|
||||
case "audio":
|
||||
formatted_parts.append(
|
||||
f"[Binary Content: Audio {item.mimeType}, {_get_base64_size(item.data)} bytes]\n"
|
||||
f"The task is complete and the content accessible to the User"
|
||||
)
|
||||
|
||||
case "resource":
|
||||
resource = item.resource
|
||||
|
||||
if hasattr(resource, "text") and isinstance(resource.text, str):
|
||||
formatted_parts.append(resource.text)
|
||||
|
||||
elif hasattr(resource, "blob") and isinstance(resource.blob, str):
|
||||
formatted_parts.append(
|
||||
f"[Binary Content ({resource.uri}): {resource.mimeType},"
|
||||
f" {_get_base64_size(resource.blob)} bytes]\n"
|
||||
f"The task is complete and the content accessible to the User"
|
||||
)
|
||||
|
||||
return "\n".join(formatted_parts)
|
||||
|
||||
|
||||
|
|
@ -102,7 +104,7 @@ def _load_agent_config(agent_path: Optional[str]) -> tuple[AgentConfig, Optional
|
|||
return config, prompt
|
||||
|
||||
if agent_path is None:
|
||||
return DEFAULT_AGENT, None # type: ignore[return-value]
|
||||
return DEFAULT_AGENT, None # type: ignore
|
||||
|
||||
path = Path(agent_path).expanduser()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Literal, Optional, Union
|
||||
from typing import Literal, Union
|
||||
|
||||
from huggingface_hub.inference._providers.featherless_ai import (
|
||||
FeatherlessConversationalTask,
|
||||
|
|
@ -11,6 +11,7 @@ from .black_forest_labs import BlackForestLabsTextToImageTask
|
|||
from .cerebras import CerebrasConversationalTask
|
||||
from .clarifai import ClarifaiConversationalTask
|
||||
from .cohere import CohereConversationalTask
|
||||
from .deepinfra import DeepInfraConversationalTask, DeepInfraTextGenerationTask
|
||||
from .fal_ai import (
|
||||
FalAIAutomaticSpeechRecognitionTask,
|
||||
FalAIImageSegmentationTask,
|
||||
|
|
@ -37,6 +38,7 @@ from .nebius import (
|
|||
)
|
||||
from .novita import NovitaConversationalTask, NovitaTextGenerationTask, NovitaTextToVideoTask
|
||||
from .nscale import NscaleConversationalTask, NscaleTextToImageTask
|
||||
from .nvidia import NvidiaConversationalTask
|
||||
from .openai import OpenAIConversationalTask
|
||||
from .ovhcloud import OVHcloudConversationalTask
|
||||
from .publicai import PublicAIConversationalTask
|
||||
|
|
@ -49,7 +51,16 @@ from .replicate import (
|
|||
)
|
||||
from .sambanova import SambanovaConversationalTask, SambanovaFeatureExtractionTask
|
||||
from .scaleway import ScalewayConversationalTask, ScalewayFeatureExtractionTask
|
||||
from .together import TogetherConversationalTask, TogetherTextGenerationTask, TogetherTextToImageTask
|
||||
from .together import (
|
||||
TogetherConversationalTask,
|
||||
TogetherFeatureExtractionTask,
|
||||
TogetherImageToImageTask,
|
||||
TogetherImageToVideoTask,
|
||||
TogetherTextGenerationTask,
|
||||
TogetherTextToImageTask,
|
||||
TogetherTextToSpeechTask,
|
||||
TogetherTextToVideoTask,
|
||||
)
|
||||
from .wavespeed import (
|
||||
WavespeedAIImageToImageTask,
|
||||
WavespeedAIImageToVideoTask,
|
||||
|
|
@ -67,6 +78,7 @@ PROVIDER_T = Literal[
|
|||
"cerebras",
|
||||
"clarifai",
|
||||
"cohere",
|
||||
"deepinfra",
|
||||
"fal-ai",
|
||||
"featherless-ai",
|
||||
"fireworks-ai",
|
||||
|
|
@ -76,6 +88,7 @@ PROVIDER_T = Literal[
|
|||
"nebius",
|
||||
"novita",
|
||||
"nscale",
|
||||
"nvidia",
|
||||
"openai",
|
||||
"ovhcloud",
|
||||
"publicai",
|
||||
|
|
@ -104,6 +117,10 @@ PROVIDERS: dict[PROVIDER_T, dict[str, TaskProviderHelper]] = {
|
|||
"cohere": {
|
||||
"conversational": CohereConversationalTask(),
|
||||
},
|
||||
"deepinfra": {
|
||||
"conversational": DeepInfraConversationalTask(),
|
||||
"text-generation": DeepInfraTextGenerationTask(),
|
||||
},
|
||||
"fal-ai": {
|
||||
"automatic-speech-recognition": FalAIAutomaticSpeechRecognitionTask(),
|
||||
"text-to-image": FalAITextToImageTask(),
|
||||
|
|
@ -171,6 +188,9 @@ PROVIDERS: dict[PROVIDER_T, dict[str, TaskProviderHelper]] = {
|
|||
"conversational": NscaleConversationalTask(),
|
||||
"text-to-image": NscaleTextToImageTask(),
|
||||
},
|
||||
"nvidia": {
|
||||
"conversational": NvidiaConversationalTask(),
|
||||
},
|
||||
"openai": {
|
||||
"conversational": OpenAIConversationalTask(),
|
||||
},
|
||||
|
|
@ -196,9 +216,14 @@ PROVIDERS: dict[PROVIDER_T, dict[str, TaskProviderHelper]] = {
|
|||
"feature-extraction": ScalewayFeatureExtractionTask(),
|
||||
},
|
||||
"together": {
|
||||
"text-to-image": TogetherTextToImageTask(),
|
||||
"conversational": TogetherConversationalTask(),
|
||||
"feature-extraction": TogetherFeatureExtractionTask(),
|
||||
"image-to-image": TogetherImageToImageTask(),
|
||||
"image-to-video": TogetherImageToVideoTask(),
|
||||
"text-generation": TogetherTextGenerationTask(),
|
||||
"text-to-image": TogetherTextToImageTask(),
|
||||
"text-to-speech": TogetherTextToSpeechTask(),
|
||||
"text-to-video": TogetherTextToVideoTask(),
|
||||
},
|
||||
"wavespeed": {
|
||||
"text-to-image": WavespeedAITextToImageTask(),
|
||||
|
|
@ -213,9 +238,7 @@ PROVIDERS: dict[PROVIDER_T, dict[str, TaskProviderHelper]] = {
|
|||
}
|
||||
|
||||
|
||||
def get_provider_helper(
|
||||
provider: Optional[PROVIDER_OR_POLICY_T], task: str, model: Optional[str]
|
||||
) -> TaskProviderHelper:
|
||||
def get_provider_helper(provider: PROVIDER_OR_POLICY_T | None, task: str, model: str | None) -> TaskProviderHelper:
|
||||
"""Get provider helper instance by name and task.
|
||||
|
||||
Args:
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue