Skip to main content

PydanticAI integration for GigaChat

Project description

pydantic-ai-gigachat

CI

PydanticAI integration for GigaChat.

This package implements a native PydanticAI Model against GigaChat's own /chat/completions API (not the OpenAI-compatibility shim), so all GigaChat features — Russian profanity filter, repetition penalty, function calling, streaming — are first-class.

Install

pip install pydantic-ai-gigachat

Requires Python 3.10+ and pydantic-ai-slim>=1.90.

Quick start

import asyncio
from pydantic_ai import Agent
from pydantic_ai_gigachat import GigaChatModel, GigaChatProvider

async def main():
    provider = GigaChatProvider()  # reads GIGACHAT_CREDENTIALS env
    model = GigaChatModel("GigaChat", provider=provider)
    agent = Agent(model, system_prompt="Отвечай коротко.")

    result = await agent.run("Привет, как дела?")
    print(result.output)

    await provider.aclose()

asyncio.run(main())

Configuration

Credentials

Get your Authorization key from the Sber developer cabinet (it's the base64-encoded client_id:client_secret). Pass it explicitly or via env:

export GIGACHAT_CREDENTIALS="<authorization key>"
provider = GigaChatProvider(
    authorization_key="...",
    scope=GigaChatScope.PERS,        # PERS / B2B / CORP
)

TLS certificates

GigaChat endpoints serve certificates signed by the Russian Trusted Root CA, which is not in the standard certifi bundle. Three options:

  1. Production — download the CA from gu-st.ru and point the provider at it:

    export GIGACHAT_CA_BUNDLE_FILE=/path/to/russian_trusted_root_ca.cer
    
  2. Append to certifi (one-shot, affects the whole venv):

    curl -k "https://gu-st.ru/content/Other/doc/russian_trusted_root_ca.cer" \
        >> $(python -m certifi)
    
  3. Dev onlyGigaChatProvider(verify_ssl=False).

Features

Feature Status
Chat completions
Streaming (SSE)
Function calling
OAuth2 token cache + refresh
Custom CA bundle
Pre-flight token counting (Model.count_tokens)
Prompt cache reporting (cache_read_tokens)
Embeddings ⏭ planned
/files (vision/RAG inputs) ⏭ planned

Available models

GigaChat, GigaChat-Pro, GigaChat-Max, GigaChat-2, GigaChat-2-Pro, GigaChat-2-Max (and -preview early-access variants).

model = GigaChatModel("GigaChat-Max", provider=provider)

Settings passthrough

PydanticAI's ModelSettings map cleanly to GigaChat parameters: temperature, top_p, max_tokens, n. GigaChat-specific knobs (repetition_penalty, update_interval, profanity_check) work via extra_body:

result = await agent.run(
    "...",
    model_settings={
        "temperature": 0.3,
        "max_tokens": 256,
        "extra_body": {"profanity_check": True, "repetition_penalty": 1.1},
    },
)

Examples

See examples/:

  • basic.py — minimal agent
  • tools.py — function calling
  • streaming.py — streamed response

Development

python -m venv .venv
.venv/bin/pip install -e ".[dev]"
.venv/bin/pytest

License

MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydantic_ai_gigachat-0.1.0.tar.gz (60.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydantic_ai_gigachat-0.1.0-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_ai_gigachat-0.1.0.tar.gz.

File metadata

  • Download URL: pydantic_ai_gigachat-0.1.0.tar.gz
  • Upload date:
  • Size: 60.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for pydantic_ai_gigachat-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4e2c56a9bc7b2bca87d69ec4f091d15866cefadf136b9f7a524023f089c24c5b
MD5 dd560c7f48089b49def61360cbc2d9f4
BLAKE2b-256 e62b13d895ea8bd7a777b46d2763ca021ce6efbc55e6de66d176a3cc4a1b1569

See more details on using hashes here.

File details

Details for the file pydantic_ai_gigachat-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_ai_gigachat-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 96821274a485fe16e145418c88ec21204d9f82fa4dc23dc64beb7997e61e2d11
MD5 116672416f301ca606f795395e8acbdf
BLAKE2b-256 bf6d6fcf0fa9e7225aef4e78b1993e5098fd85f55f41816638643cb6f8982dee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page