YandexGPTThread#

class yandex_gpt.YandexGPTThread(config_manager: YandexGPTConfigManagerBase | Dict[str, Any], messages: List[YandexGPTMessage] | None = None)#

Bases: YandexGPT

A thread-based interface for interacting with the Yandex GPT model.

This class manages asynchronous messaging and maintains the state of conversation threads.

Variables:
  • messages – List of messages maintained in the conversation thread.

  • status – Tracks the current status and last error message of the thread.

Attributes#

messagesList[YandexGPTMessage]

Maintained list of messages in the conversation thread.

statusYandexGPTThreadStatus

Current status and last error information of the thread.

add_message(role: str, text: str) None#

Appends a new message to the conversation thread.

Parameters#

rolestr

The role of the message, typically ‘user’ or ‘assistant’.

textstr

The content of the message.

async run_async(temperature: float = 0.6, max_tokens: int = 1000, stream: bool = False, completion_url: str = 'https://llm.api.cloud.yandex.net/foundationModels/v1/completionAsync', timeout: int = 15)#

Runs the thread asynchronously, requesting and appending completion from the Yandex GPT model.

Parameters#

temperaturefloat

Sampling temperature, scales the likelihood of less probable tokens. Value from 0 to 1.

max_tokensint

Maximum number of tokens to generate.

streambool

Stream responses from the API (not currently supported).

completion_urlstr

URL of the asynchronous completion API.

timeoutint

Timeout in seconds for the asynchronous call.

Raises#

Exception

If the thread is already running.

run_sync(temperature: float = 0.6, max_tokens: int = 1000, stream: bool = False, completion_url: str = 'https://llm.api.cloud.yandex.net/foundationModels/v1/completion')#

Runs the thread synchronously, requesting and appending completion from the Yandex GPT model.

Parameters#

temperaturefloat

Sampling temperature, scales the likelihood of less probable tokens. Value from 0 to 1.

max_tokensint

Maximum number of tokens to generate.

streambool

Stream responses from the API (not currently supported).

completion_urlstr

URL of the synchronous completion API.

Raises#

Exception

If the thread is already running.