routeur_ia_api / QUICKSTART.md
Cyril Dupland
FIrst Commit
d28f1ed
|
raw
history blame
4 kB

🚀 Guide de Démarrage Rapide

Installation en 5 minutes

1. Prérequis

  • Python 3.12+
  • Clés API OpenAI et Mistral AI

2. Installation

# Créer environnement virtuel
python -m venv venv
source venv/bin/activate  # Linux/Mac
# ou venv\Scripts\activate sur Windows

# Installer dépendances
pip install -r requirements.txt

3. Configuration

Copiez .env.example vers .env et remplissez vos clés API:

OPENAI_API_KEY=sk-votre-cle-openai
MISTRALAI_API_KEY=votre-cle-mistral
JWT_SECRET_KEY=changez-moi-en-production

4. Lancement

python app.py

L'API sera accessible sur: http://localhost:7860

Documentation interactive: http://localhost:7860/docs

🎯 Premier test

1. Obtenir un token JWT

curl -X POST http://localhost:7860/auth/token

Vous obtiendrez:

{
  "access_token": "eyJhbG...",
  "token_type": "bearer",
  "expires_in": 3600
}

2. Tester la completion

TOKEN="<votre-token>"

curl -X POST http://localhost:7860/completion \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Dis bonjour en français",
    "model": "gpt-4o",
    "stream": false
  }'

3. Tester le streaming

curl -N -X POST http://localhost:7860/completion \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Compte de 1 à 10",
    "model": "gpt-3.5-turbo",
    "stream": true
  }'

4. Lister les modèles disponibles

curl -X GET http://localhost:7860/models \
  -H "Authorization: Bearer $TOKEN"

5. Transcription audio

curl -X POST http://localhost:7860/transcription \
  -H "Authorization: Bearer $TOKEN" \
  -F "file=@votre-fichier.mp3"

🔧 Configuration avancée

LangSmith (monitoring)

Activez LangSmith dans .env:

LANGCHAIN_TRACING_V2=true
LANGCHAIN_API_KEY=votre-cle-langsmith
LANGCHAIN_PROJECT=routeur-ia

Production

# Générer un secret JWT sécurisé
python -c "import secrets; print(secrets.token_urlsafe(32))"

# Lancer en production
uvicorn app:app --host 0.0.0.0 --port 7860 --workers 4

🐳 Docker

# Build
docker build -t routeur-ia-api .

# Run
docker run -p 7860:7860 --env-file .env routeur-ia-api

📚 Prochaines étapes

  • Consultez le README.md pour la documentation complète
  • Explorez la documentation interactive sur /docs
  • Ajoutez vos propres graphes LangGraph dans graphs/
  • Personnalisez les agents dans services/agent_registry.py

❓ Problèmes courants

Erreur "Could not validate credentials"

→ Vérifiez que vous incluez le token dans le header Authorization: Bearer <token>

Erreur "API key not found"

→ Vérifiez votre fichier .env et que les clés API sont correctes

Erreur au lancement

→ Vérifiez que toutes les dépendances sont installées: pip install -r requirements.txt

💡 Exemples de code

Python

import requests

# Obtenir token
token_response = requests.post("http://localhost:7860/auth/token")
token = token_response.json()["access_token"]

# Completion
headers = {"Authorization": f"Bearer {token}"}
response = requests.post(
    "http://localhost:7860/completion",
    headers=headers,
    json={
        "message": "Bonjour!",
        "model": "gpt-4o",
        "stream": False
    }
)
print(response.json())

JavaScript

// Obtenir token
const tokenRes = await fetch('http://localhost:7860/auth/token', {
  method: 'POST'
});
const { access_token } = await tokenRes.json();

// Completion
const response = await fetch('http://localhost:7860/completion', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${access_token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    message: 'Hello!',
    model: 'gpt-4o',
    stream: false
  })
});
const data = await response.json();
console.log(data);

Bon codage! 🎉