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:
BaseServiceConfigExecution options for tokenization process.
- Config:
 extra: str = forbid
validate_assignment: bool = True
validate_default: bool = True
- field batch_size: Annotated[int | None, FieldInfo(annotation=NoneType, required=True, description='Upper limit for size of single batch of prompts (the size can be actually lower in case the payload is large enough).')] = 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: Annotated[Callable[[TextTokenizationCreateResponse], None] | None, FieldInfo(annotation=NoneType, required=True, description='Callback which is called everytime the response comes.')] = None¶
 Callback which is called everytime the response comes.
- field concurrency_limit: Annotated[int | None, FieldInfo(annotation=NoneType, required=True, description="Upper bound for concurrent executions (in case the passed value is higher than the API allows, the API's limit will be used).", metadata=[Ge(ge=1)])] = 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: Annotated[bool, FieldInfo(annotation=NoneType, required=True, description='Items will be yielded in the order they were passed in, although they may be processed on the server in different order.')] = 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: Annotated[dict | None, FieldInfo(annotation=NoneType, required=True, description='HTTPX Transport Options to limit number of requests per second.')] = None¶
 HTTPX Transport Options to limit number of requests per second.
- field throw_on_error: Annotated[bool, FieldInfo(annotation=NoneType, required=True, description="Flag indicating whether to throw an error if any error occurs during execution (if disabled, 'None' may be returned in case of error).")] = 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]