https://github.com/allseeteam/yandexgpt-python
Python SDK for YaGPT API
https://github.com/allseeteam/yandexgpt-python
python sdk-python yandexgpt yandexgpt-2-wrapper
Last synced: 7 months ago
JSON representation
Python SDK for YaGPT API
- Host: GitHub
- URL: https://github.com/allseeteam/yandexgpt-python
- Owner: allseeteam
- License: mit
- Created: 2024-04-11T13:14:31.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-15T07:18:26.000Z (over 1 year ago)
- Last Synced: 2024-06-22T15:07:24.786Z (over 1 year ago)
- Topics: python, sdk-python, yandexgpt, yandexgpt-2-wrapper
- Language: Python
- Homepage:
- Size: 35.2 KB
- Stars: 10
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
- [Introduction](#Introduction)
- [Features](#Features)
- [Documentation](#Documentation)
- [Installation using pip](#Installation-using-pip)
- [Local installation using pip](#Local-installation-using-pip)
- [Usage](#Usage)
- [Configuration](#Configuration)
- [Examples](#Examples)
- [Troubleshooting](#Troubleshooting)
- [Contributors](#Contributors)
- [License](#License)## 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](requirements.txt) file.
## Documentation
For more detailed information, including installation guides, usage examples, and API references, please visit the [YandexGPT Python SDK Documentation](https://yandexgpt-python.readthedocs.io/en/latest/).## Installation using pip
To install the YandexGPT Python SDK as a package using pip, run the following command:
```shell
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:
```shell
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](yandex_gpt/yandex_gpt.py) 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](yandex_gpt/config_manager.py) class or [its subclasses](yandex_gpt/config_manager.py), which allows for easy management of these settings either directly or via environment variables (see examples in [env](env) directory).## Examples
### Using API key for authentication
```python
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
```python
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.