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

Uploaded Python 3

File details

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

File metadata

  • Download URL: appserver_sdk_python_ai-0.0.7.tar.gz
  • Upload date:
  • Size: 15.3 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.7.tar.gz
Algorithm Hash digest
SHA256 b27ebebeda196688fd9ed4f36b347d8bbe68ccf01d02ea4afc59a48449eaa6e7
MD5 4a001c4eff59b410c1c8af71fbd66292
BLAKE2b-256 53e7407bc6228a78e40c6a6098f27ddd1fb7d56dfce8857e3430eebd2042edeb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for appserver_sdk_python_ai-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 c264b61a7efbc672e57e912c2d88c80c91395b56e114c0fe58cb7247e4df73fb
MD5 fa6eef07656a74f80b07e6b911bdbb8b
BLAKE2b-256 d25cb553b4eade9d280d6a6e6227f130fa45e79795da4ba607b946847449bfe1

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