SDK Python para serviços de IA da AppServer
Project description
AppServer SDK Python AI
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çãoAIResponse: Modelo de respostaAIConfig: Configuração do clienteAIError: Modelo de erro
Exceções
AIException: Exceção baseAIConnectionError: Erro de conexãoAIAuthenticationError: Erro de autenticaçãoAIRateLimitError: Erro de limite de taxaAITimeoutError: Erro de timeout
🤝 Contribuindo
- Fork o projeto
- Crie uma branch para sua feature (
git checkout -b feature/nova-feature) - Commit suas mudanças (
git commit -m 'feat: adiciona nova feature') - Push para a branch (
git push origin feature/nova-feature) - Abra um Pull Request
Padrões de Commit
Seguimos o padrão Conventional Commits:
feat:nova funcionalidadefix:correção de bugdocs:mudanças na documentaçãostyle:formatação de códigorefactor:refatoração de códigotest:adição ou correção de testeschore:tarefas de manutenção
📄 Licença
Este projeto está licenciado sob a Licença MIT - veja o arquivo LICENSE para detalhes.
🆘 Suporte
- Email: suporte@appserver.com.br
- Issues: GitHub Issues
- Documentação: Wiki
📊 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file appserver_sdk_python_ai-0.0.5.tar.gz.
File metadata
- Download URL: appserver_sdk_python_ai-0.0.5.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.3 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4eec97c2382accb63c020a705f299bc4796b687c3c01e635f8f366182c66156
|
|
| MD5 |
da59be48397fb5fe5f85f8a547b4e6ea
|
|
| BLAKE2b-256 |
c27124cd5bb0270bd7ef258e680c845d02793a34e1420c7e19979b8699e8cbdb
|
File details
Details for the file appserver_sdk_python_ai-0.0.5-py3-none-any.whl.
File metadata
- Download URL: appserver_sdk_python_ai-0.0.5-py3-none-any.whl
- Upload date:
- Size: 19.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.3 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c48939aea49af35531385de133f9c8cfcae820c34d92400e352079a586a49cdc
|
|
| MD5 |
583100d0f99210d2631a68cf2cd64d89
|
|
| BLAKE2b-256 |
aefb3d5b75cf7f06f543382b369c255829995879d3578dcdb25aa0466920b0d7
|