genai.text.tokenization.tokenization_service module#
- pydantic model genai.text.tokenization.tokenization_service.BaseConfig[source]#
Bases:
BaseServiceConfig
- Config:
extra: str = forbid
validate_assignment: bool = True
validate_default: bool = True
- field create_execution_options: CreateExecutionOptions = CreateExecutionOptions(throw_on_error=True, ordered=True, concurrency_limit=None, batch_size=None, rate_limit_options=None, callback=None)#
- pydantic model genai.text.tokenization.tokenization_service.CreateExecutionOptions[source]#
Bases:
BaseServiceConfig
Execution options for tokenization process.
- Config:
extra: str = forbid
validate_assignment: bool = True
validate_default: bool = True
- field batch_size: int | None = None#
Upper limit for size of single batch of prompts (the size can be actually lower in case the payload is large enough).
- field callback: Callable[[TextTokenizationCreateResponse], None] | None = None#
Callback which is called everytime the response comes.
- field concurrency_limit: int | None = None#
Upper bound for concurrent executions (in case the passed value is higher than the API allows, the API’s limit will be used).
- Constraints:
ge = 1
- field ordered: bool = True#
Items will be yielded in the order they were passed in, although they may be processed on the server in different order.
- field rate_limit_options: dict | None = None#
HTTPX Transport Options to limit number of requests per second.
- field throw_on_error: bool = True#
Flag indicating whether to throw an error if any error occurs during execution (if disabled, ‘None’ may be returned in case of error).
- class genai.text.tokenization.tokenization_service.TokenizationService[source]#
Bases:
BaseService
[BaseConfig
,BaseServiceServices
]- Config#
alias of
BaseConfig
- create(*, input, model_id=None, prompt_id=None, parameters=None, execution_options=None)[source]#
- Parameters:
input (str | list[str]) – The input data for tokenization. It can be a single string or a list of strings.
model_id (str | None) – The ID of the model to use for tokenization. Eiter ‘model_id’ or ‘prompt_id’ must be provided.
prompt_id (str | None) – The ID of the prompt to use for tokenization. Eiter ‘model_id’ or ‘prompt_id’ must be provided.
parameters (dict | TextTokenizationParameters | None) – The parameters for tokenization, like return options.
execution_options (dict | CreateExecutionOptions | None) – The execution options for tokenization like batch size, callbacks and cetra.
- Raises:
ApiResponseException – In case of a known API error.
ApiNetworkException – In case of unhandled network error.
ValidationError – In case of provided parameters are invalid.
- Return type:
Generator[TextTokenizationCreateResponse, None, None]