YandexGPTBase#
- class yandex_gpt.YandexGPTBase#
Bases:
objectThis class is used to interact with the Yandex GPT API, providing asynchronous and synchronous methods to send requests and poll for their completion. Currently, only asynchronous methods are implemented fully.
Methods#
- send_async_completion_request(headers: Dict[str, str], payload: Dict[str, Any], completion_url: str) -> str
Sends an asynchronous request to the Yandex GPT completion API.
- poll_async_completion(operation_id: str, headers: Dict[str, str], timeout: int, poll_url: str) -> Dict[str, Any]
Polls the status of an asynchronous completion operation until it completes or times out.
- send_sync_completion_request(headers: Dict[str, str], payload: Dict[str, Any], completion_url: str) -> Dict[str, Any]
Sends a synchronous request to the Yandex GPT completion API.
- async static poll_async_completion(operation_id: str, headers: Dict[str, str], timeout: int = 5, poll_url: str = 'https://llm.api.cloud.yandex.net/operations/') Dict[str, Any]#
Polls the status of an asynchronous completion operation until it completes or times out.
Parameters#
- operation_idstr
ID of the completion operation to poll.
- headersDict[str, str]
Dictionary containing the authorization token (IAM).
- timeoutint
Time in seconds after which the operation is considered timed out.
- poll_urlstr
Poll URL.
Returns#
- Dict[str, Any]
Completion result.
- async static send_async_completion_request(headers: Dict[str, str], payload: Dict[str, Any], completion_url: str = 'https://llm.api.cloud.yandex.net/foundationModels/v1/completionAsync') str#
Sends an asynchronous request to the Yandex GPT completion API.
Parameters#
- headersDict[str, str]
Dictionary containing the authorization token (IAM), content type, and x-folder-id (YandexCloud catalog ID).
- payloadDict[str, Any]
Dictionary with the model URI, completion options, and messages.
- completion_urlstr
URL of the completion API.
Returns#
- str
ID of the completion operation to poll.
- static send_sync_completion_request(headers: Dict[str, str], payload: Dict[str, Any], completion_url: str = 'https://llm.api.cloud.yandex.net/foundationModels/v1/completion') Dict[str, Any]#
Sends a synchronous request to the Yandex GPT completion API.
Parameters#
- headersDict[str, str]
Dictionary containing the authorization token (IAM), content type, and x-folder-id (YandexCloud catalog ID).
- payloadDict[str, Any]
Dictionary with the model URI, completion options, and messages.
- completion_urlstr
URL of the completion API.
Returns#
- Dict[str, Any]
Completion result.