Skip to main content

SDK Python para serviços de IA da AppServer com suporte a contagem de tokens

Project description

AppServer SDK Python AI

Python Version License: MIT Code style: ruff

SDK Python para integração com serviços de IA da AppServer.

🚀 Características

  • Cliente HTTP assíncrono e síncrono
  • Modelos Pydantic para validação de dados
  • Retry automático com backoff exponencial
  • Type hints completos
  • Suporte a múltiplos provedores de IA
  • Logging estruturado
  • Testes abrangentes

📦 Instalação

Via Poetry (Recomendado)

poetry add appserver-sdk-python-ai

Via pip

pip install appserver-sdk-python-ai

Via GitHub (Desenvolvimento)

# Via Poetry
poetry add git+https://github.com/appserver/appserver-sdk-python-ai.git

# Via pip
pip install git+https://github.com/appserver/appserver-sdk-python-ai.git

🔧 Uso Básico

Cliente Síncrono

from appserver_sdk_python_ai import AIClient
from appserver_sdk_python_ai.models import AIRequest

# Configurar cliente
client = AIClient(
    base_url="https://api.appserver.com.br/ai/v1",
    api_key="sua-api-key"
)

# Fazer requisição
request = AIRequest(
    prompt="Explique machine learning em termos simples",
    model="gpt-4",
    max_tokens=500
)

response = client.chat_completion(request)
print(response.content)

Cliente Assíncrono

import asyncio
from appserver_sdk_python_ai import AsyncAIClient

async def main():
    client = AsyncAIClient(
        base_url="https://api.appserver.com.br/ai/v1",
        api_key="sua-api-key"
    )
    
    request = AIRequest(
        prompt="O que é inteligência artificial?",
        model="gpt-3.5-turbo"
    )
    
    response = await client.chat_completion(request)
    print(response.content)
    
    await client.close()

asyncio.run(main())

Configuração Avançada

from appserver_sdk_python_ai import AIClient, AIConfig

config = AIConfig(
    base_url="https://api.appserver.com.br/ai/v1",
    api_key="sua-api-key",
    timeout=30,
    max_retries=3,
    retry_delay=1.0,
    debug=True
)

client = AIClient(config=config)

🛠️ Desenvolvimento

Pré-requisitos

  • Python 3.11+
  • Poetry

Configuração do Ambiente

# Clonar repositório
git clone https://github.com/appserver/appserver-sdk-python-ai.git
cd appserver-sdk-python-ai

# Instalar dependências
poetry install

# Configurar pre-commit hooks
poetry run pre-commit install

# Ativar ambiente virtual
poetry shell

Executar Testes

# Todos os testes
poetry run pytest

# Com cobertura
poetry run pytest --cov=appserver_sdk_python_ai --cov-report=html

# Apenas testes unitários
poetry run pytest -m unit

# Apenas testes de integração
poetry run pytest -m integration

Linting e Formatação

# Verificar e corrigir código
poetry run ruff check . --fix
poetry run ruff format .

# Verificar tipos
poetry run mypy src/

# Verificar segurança
poetry run bandit -r src/
poetry run safety check

Executar Exemplo

# Exemplo básico
poetry run python examples/basic_usage.py

# Exemplo assíncrono
poetry run python examples/async_usage.py

📚 Documentação

Estrutura do Projeto

appserver-sdk-python-ai/
├── src/
│   └── appserver_sdk_python_ai/
│       ├── __init__.py
│       ├── client/
│       │   ├── sync_client.py
│       │   └── async_client.py
│       ├── models/
│       │   ├── request_models.py
│       │   ├── response_models.py
│       │   └── config_models.py
│       ├── exceptions/
│       │   └── ai_exceptions.py
│       └── utils/
│           ├── retry.py
│           └── logging.py
├── tests/
├── examples/
├── docs/
└── pyproject.toml

Modelos Disponíveis

  • AIRequest: Modelo de requisição
  • AIResponse: Modelo de resposta
  • AIConfig: Configuração do cliente
  • AIError: Modelo de erro

Exceções

  • AIException: Exceção base
  • AIConnectionError: Erro de conexão
  • AIAuthenticationError: Erro de autenticação
  • AIRateLimitError: Erro de limite de taxa
  • AITimeoutError: Erro de timeout

🤝 Contribuindo

  1. Fork o projeto
  2. Crie uma branch para sua feature (git checkout -b feature/nova-feature)
  3. Commit suas mudanças (git commit -m 'feat: adiciona nova feature')
  4. Push para a branch (git push origin feature/nova-feature)
  5. Abra um Pull Request

Padrões de Commit

Seguimos o padrão Conventional Commits:

  • feat: nova funcionalidade
  • fix: correção de bug
  • docs: mudanças na documentação
  • style: formatação de código
  • refactor: refatoração de código
  • test: adição ou correção de testes
  • chore: tarefas de manutenção

📄 Licença

Este projeto está licenciado sob a Licença MIT - veja o arquivo LICENSE para detalhes.

🆘 Suporte

📊 Status do Projeto

  • ✅ Cliente básico implementado
  • ✅ Modelos Pydantic
  • ✅ Testes unitários
  • 🔄 Documentação (em andamento)
  • 🔄 Testes de integração (em andamento)
  • ⏳ Suporte a streaming (planejado)
  • ⏳ Cache de respostas (planejado)

Desenvolvido com ❤️ pela equipe AppServer

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

appserver_sdk_python_ai-0.0.3.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

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

appserver_sdk_python_ai-0.0.3-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file appserver_sdk_python_ai-0.0.3.tar.gz.

File metadata

  • Download URL: appserver_sdk_python_ai-0.0.3.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.3 Windows/11

File hashes

Hashes for appserver_sdk_python_ai-0.0.3.tar.gz
Algorithm Hash digest
SHA256 232646dbf67f3042a020fb720b5bfd42bf9381f611bbf690c0f2b24ebd2dd9d2
MD5 e031442a8ad3090c34c1988d00f91a45
BLAKE2b-256 2f523e9edacb5ffb09d1511b3a6e268ba3699a2e0e0232a6aa7b764aa4497cfc

See more details on using hashes here.

File details

Details for the file appserver_sdk_python_ai-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for appserver_sdk_python_ai-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b9f3b0a68822bb078872dd54962ce4fa00213ac8581476f8740a8248ce5498cc
MD5 513fbe3b8725d9141cd720ec6f8dc056
BLAKE2b-256 c37dfcf4be914b5001385b8a63b6f8e5aba3415292b2006b6f59ef9194a6b7d4

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