Skip to main content

Python SDK для ArizonaAI API

Project description

ArizonaAI Python SDK

Профессиональная Python-библиотека для взаимодействия с API ArizonaAI.

Особенности

  • 🔄 Sync/Async — полная поддержка синхронных и асинхронных операций
  • 📦 Типизация — полные type hints и dataclass модели
  • 🔁 Retry Logic — автоматические повторы при ошибках
  • 📡 Streaming — потоковая передача ответов
  • Модульность — отдельные API модули (chat, models, user, configs, forum)
  • 🛡️ Error Handling — детальные исключения для всех типов ошибок

Установка

pip install arizona_ai_sdk

Быстрый старт

Базовое использование

from arizona_ai_sdk import ArizonaAIClient

client = ArizonaAIClient(api_key="your-api-key")

response = client.ask("Какие правила Arizona RP?")
print(response)

Асинхронное использование

import asyncio
from arizona_ai_sdk import ArizonaAIClient

async def main():
    async with ArizonaAIClient(api_key="your-api-key") as client:
        response = await client.aask(model="arizona-lm-game", message="Расскажи про систему домов")
        print(response)

asyncio.run(main())

Работа с сообщениями

from arizona_ai_sdk import ArizonaAIClient, Message

client = ArizonaAIClient(api_key="your-api-key")

messages = [
    Message.system("Ты помощник по Arizona RP"),
    Message.user("Как получить лицензию на оружие?"),
]

completion = client.chat.completions(
    messages=messages,
    model="arizona-lm-game",
)

print(completion.content)

Streaming

from arizona_ai_sdk import ArizonaAIClient

client = ArizonaAIClient(api_key="your-api-key")

response = client.chat.stream(
    messages="Объясни систему организаций",
    model="arizona-lm-game",
    callback=lambda chunk: print(chunk, end="", flush=True)
)

Async Streaming

import asyncio
from arizona_ai_sdk import ArizonaAIClient

async def main():
    client = ArizonaAIClient(api_key="your-api-key")
    
    async for chunk in client.chat.astream("Расскажи про автосалоны"):
        print(chunk.content, end="", flush=True)
    
    await client.aclose()

asyncio.run(main())

API Модули

Chat API

client.chat.completions(messages, model, temperature, config_id, attachments)
client.chat.acompletions(...)
client.chat.stream(messages, callback=...)
client.chat.astream(messages)
client.chat.astream_text(messages)

Models API

models = client.models.list()
model = client.models.get("arizona-lm-forum")
available = client.models.get_available()
found = client.models.find("gemini")

User API

limits = client.user.get_limits()
is_valid = client.user.validate_token()
history = client.user.get_history(page=1, per_page=20)
can_request = client.user.can_make_request()

Configs API

configs = client.configs.list(scope="all")
config = client.configs.find_by_name("My Config")

Tokens API

count = client.tokens.count("Привет, мир!", model="arizona-lm-forum")
print(count.token_count)
print(count.exceeds_request_limit())

Forum API

servers = client.forum.get_servers()
category = client.forum.get_category(123)
thread = client.forum.get_thread(456)
post = client.forum.get_post(789)
member = client.forum.get_member(111)

threads = client.forum.get_category_threads(123, page=1)
posts = client.forum.get_thread_posts(456, page=1)

results = client.forum.search_threads("правила", sort="relevance")
members = client.forum.search_members("Admin")

Работа с вложениями

from arizona_ai_sdk import ArizonaAIClient
from arizona_ai_sdk.utils import file_to_attachment

client = ArizonaAIClient(api_key="your-api-key")

attachment = file_to_attachment("screenshot.png")

response = client.chat.completions(
    messages="Что на этом скриншоте?",
    model="gemini-2.5-flash",
    attachments=[attachment]
)

Обработка ошибок

from arizona_ai_sdk import ArizonaAIClient
from arizona_ai_sdk.exceptions import (
    AuthenticationError,
    RateLimitError,
    NotFoundError,
    ValidationError,
)

client = ArizonaAIClient(api_key="your-api-key")

try:
    response = client.ask("Вопрос")
except AuthenticationError:
    print("Неверный API ключ")
except RateLimitError as e:
    print(f"Превышен лимит. Подождите {e.retry_after} секунд")
except NotFoundError:
    print("Ресурс не найден")
except ValidationError as e:
    print(f"Ошибка валидации: {e.message}")

Конфигурация

client = ArizonaAIClient(
    api_key="your-api-key",
    base_url="https://arizona-ai.ru",
    timeout=60.0,
    max_retries=3,
    verify_ssl=True,
    custom_headers={"X-Custom-Header": "value"}
)

Модели данных

  • Message — сообщение чата
  • ChatCompletion — ответ на запрос
  • ChatCompletionChunk — чанк стриминга
  • Model — информация о модели
  • UserLimits — лимиты пользователя
  • TokenValidation — результат валидации токена
  • Config — конфигурация
  • TokenCount — подсчёт токенов
  • ForumThread, ForumPost, ForumMember — данные форума

Лицензия

GPL-2.0 license

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

arizona_ai_sdk-1.0.0.tar.gz (25.6 kB view details)

Uploaded Source

Built Distribution

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

arizona_ai_sdk-1.0.0-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file arizona_ai_sdk-1.0.0.tar.gz.

File metadata

  • Download URL: arizona_ai_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 25.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.6

File hashes

Hashes for arizona_ai_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3c9e2ede0d9f69821ae5c3904281425e57b8c1dbdec2af119f4917a635e7aece
MD5 f19ba8ef159de0eff7d10c6cee2245f5
BLAKE2b-256 f2a7b77d0cf8c44c8934494c24a06d5777121b181efbf89479014b6345567556

See more details on using hashes here.

File details

Details for the file arizona_ai_sdk-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: arizona_ai_sdk-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.6

File hashes

Hashes for arizona_ai_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b822f69e50547ff5b9faa9e6cc0c6b3c5cb77fccab58eeaa39c7e92ad7589c6c
MD5 be29c6f502be6cd18ae5d749f887a912
BLAKE2b-256 f32f02da4464da019956c34049a3144c4736f6c437bdd84fd887ffc4979b7ac5

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