Skip to main content

SDK Python para serviços de IA da AppServer

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.6.tar.gz (14.5 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.6-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: appserver_sdk_python_ai-0.0.6.tar.gz
  • Upload date:
  • Size: 14.5 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.6.tar.gz
Algorithm Hash digest
SHA256 5027adcf221698efd197ae65e3429af7405e1cb8c5af21cf7123c18919358831
MD5 10f2004afbeb1d4b3a7f5f6c03a15fbd
BLAKE2b-256 51fa108667785f00e8baf621226729c63573c09808f94a94618623c44efe41bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for appserver_sdk_python_ai-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 347eedf012249b0aedc38cb872b6fe2d09559bd06c47ab5a9891824c29dbe9ed
MD5 ea1a75482406e2722295b1251fce2468
BLAKE2b-256 4cf8f8b9c4eae8de58309873fa2da2bca883e8053154286f676629bba52def80

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