Skip to main content

YandexGPT Python SDK

Introduction

The YandexGPT Python SDK provides an easy-to-use interface for interacting with the Yandex GPT API. It includes asynchronous methods for sending requests to the Yandex GPT API, handling authentication, and processing responses. This SDK is designed to simplify the integration of Yandex GPT functionalities into Python applications.

Table of Contents

Features

  • Asynchronous API calls to Yandex GPT.
  • Easy configuration of API credentials and model parameters.
  • Supports multiple GPT models.
  • Includes utility for managing API request headers and payload.

The SDK depends on several Python libraries for its operation. These dependencies are specified in the requirements.txt file.

Documentation

For more detailed information, including installation guides, usage examples, and API references, please visit the YandexGPT Python SDK Documentation.

Installation using pip

To install the YandexGPT Python SDK as a package using pip, run the following command:

pip install yandexgpt-python

Local installation using pip

If you want to install the SDK locally (for example, if you want to modify SDK code), you can do so by cloning the repository and running the setup script:

git clone https://github.com/allseeteam/yandexgpt-python.git
cd yandexgpt-python
pip install -e .

Usage

The YandexGPT SDK is designed for asynchronous operation. To use it, instantiate the YandexGPT class with a configuration manager that includes your Yandex Cloud catalog ID, API key/IAM token, and the desired GPT model type. Currently, the supported model types are:

  • yandexgpt
  • yandexgpt-lite
  • summarization

Configuration

Configuration for the YandexGPT SDK involves setting up the model type, catalog ID, and API key/IAM token. This can be done through the YandexGPTConfigManagerBase class or its subclasses, which allows for easy management of these settings either directly or via environment variables (see examples in env directory).

Examples

Using API key for authentication

from yandex_gpt import YandexGPT, YandexGPTConfigManagerForAPIKey

# Setup configuration (input fields may be empty if they are set in environment variables)
config = YandexGPTConfigManagerForAPIKey(model_type="yandexgpt", catalog_id="your_catalog_id", api_key="your_api_key")

# Instantiate YandexGPT
yandex_gpt = YandexGPT(config_manager=config)

# Async function to get completion
async def get_completion():
    messages = [{"role": "user", "text": "Hello, world!"}]
    completion = await yandex_gpt.get_async_completion(messages=messages)
    print(completion)

# Run the async function
import asyncio
asyncio.run(get_completion())

Using IAM token for authentication

from dotenv import load_dotenv
from yandex_gpt import YandexGPT, YandexGPTConfigManagerForAPIKey

# Load environment variables
load_dotenv('../env/.env.iam_token_generation')

# Setup configuration (input fields are empty, because iam_token will be generated from environment variables)
config = YandexGPTConfigManagerForIAMToken()

# Instantiate YandexGPT
yandex_gpt = YandexGPT(config_manager=config)

# Async function to get completion
async def get_completion():
    messages = [{"role": "user", "text": "Hello, world!"}]
    completion = await yandex_gpt.get_async_completion(messages=messages)
    print(completion)

# Run the async function
import asyncio
asyncio.run(get_completion())

Troubleshooting

For any issues related to the configuration or usage of the SDK, ensure that the catalog ID, API key, and model type are correctly set and that the environment variables (if used) are properly configured.

Contributors

This project is developed and maintained by ALL SEE LLC. Contributions are welcome.

License

This project is licensed under the MIT License. For more information, see the LICENSE file in the project's GitHub repository.

Release files for yandexgpt-python 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yandexgpt-python 0.2.3
File Size Uploaded
yandexgpt-python-0.2.3.tar.gz 11.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yandexgpt-python 0.2.3
File Interpreter ABI Platform
yandexgpt_python-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 23.8 kB

Release files / yandexgpt-python-0.2.3.tar.gz

Download URL yandexgpt-python-0.2.3.tar.gz
Size 11.9 kB
Tags Source
SHA-256 checksum
How to use checksums
3a4251f0b4e804669377d669271e664df3c55d193666fbb24988c1725d7db1cc
BLAKE2b-256 checksum
How to use checksums
874dc260ede9d1b56ed995014ed993f82213f083ecbd13a4bc03a0942bb0fc2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.8

Release files / yandexgpt_python-0.2.3-py3-none-any.whl

Download URL yandexgpt_python-0.2.3-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6a29b1a3b765da3ecea8517ab77ca10c19d88cf2969fd78acc535ab0e686f9c2
BLAKE2b-256 checksum
How to use checksums
8d0cc136a8078d606744262b12f5e4d323b373efd4dad4bab81b73e015e84414
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.8

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page