genai.text.generation.generation_service module#
- pydantic model genai.text.generation.generation_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, callback=None)#
- pydantic model genai.text.generation.generation_service.BaseServices[source]#
Bases:
BaseServiceServices
- Config:
extra: str = forbid
validate_assignment: bool = True
validate_default: bool = True
- field LimitService: type[LimitService] = <class 'genai.text.generation.limits.limit_service.LimitService'>#
- pydantic model genai.text.generation.generation_service.CreateExecutionOptions[source]#
Bases:
BaseModel
- field callback: Callable[[TextGenerationStreamCreateResponse | TextGenerationCreateResponse], 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 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.generation.generation_service.GenerationService[source]#
Bases:
BaseService
[BaseConfig
,BaseServices
]- Config#
alias of
BaseConfig
- Services#
alias of
BaseServices
- __init__(*, api_client, services=None, config=None)[source]#
- Parameters:
api_client (ApiClient) –
services (BaseServices | None) –
config (BaseConfig | dict | None) –
- compare(*, request, compare_parameters=None, name=None)[source]#
- Raises:
ApiResponseException – In case of a known API error.
ApiNetworkException – In case of unhandled network error.
ValidationError – In case of provided parameters are invalid.
- Parameters:
request (TextGenerationComparisonCreateRequestRequest) –
compare_parameters (dict | TextGenerationComparisonParameters | None) –
name (str | None) –
- Return type:
- create(*, model_id=None, prompt_id=None, input=None, inputs=None, parameters=None, moderations=None, data=None, execution_options=None)[source]#
- Parameters:
model_id (str | None) – The ID of the model.
prompt_id (str | None) – The ID of the prompt which should be used.
input (str | None) – Prompt to process. It is recommended not to leave any trailing spaces.
inputs (str | list[str] | None) – Prompt/prompts to process. It is recommended not to leave any trailing spaces.
parameters (dict | TextGenerationParameters | None) – Parameters for text generation.
moderations (dict | ModerationParameters | None) – Parameters for moderation.
data (dict | PromptTemplateData | None) – An optional data object for underlying prompt.
execution_options (dict | CreateExecutionOptions | None) – An optional configuration how SDK should work (error handling, limits, callbacks, …)
- Yields:
TextGenerationCreateResponse object (server response without modification).
- 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[TextGenerationCreateResponse, None, None]
Note
To limit number of concurrent requests or change execution procedure, see ‘execute_options’ parameter.
- create_stream(*, input=None, model_id=None, prompt_id=None, parameters=None, moderations=None, data=None)[source]#
- Yields:
TextGenerationStreamCreateResponse (raw server response object)
- Raises:
ApiResponseException – In case of a known API error.
ApiNetworkException – In case of unhandled network error.
ValidationError – In case of provided parameters are invalid.
- Parameters:
input (str | None) –
model_id (str | None) –
prompt_id (str | None) –
parameters (dict | TextGenerationParameters | None) –
moderations (dict | ModerationParameters | None) –
data (dict | PromptTemplateData | None) –
- Return type:
Generator[TextGenerationStreamCreateResponse, None, None]