File size: 4,000 Bytes
d28f1ed | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | # 🚀 Guide de Démarrage Rapide
## Installation en 5 minutes
### 1. Prérequis
- Python 3.12+
- Clés API OpenAI et Mistral AI
### 2. Installation
```bash
# 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:
```env
OPENAI_API_KEY=sk-votre-cle-openai
MISTRALAI_API_KEY=votre-cle-mistral
JWT_SECRET_KEY=changez-moi-en-production
```
### 4. Lancement
```bash
python app.py
```
L'API sera accessible sur: http://localhost:7860
Documentation interactive: http://localhost:7860/docs
## 🎯 Premier test
### 1. Obtenir un token JWT
```bash
curl -X POST http://localhost:7860/auth/token
```
Vous obtiendrez:
```json
{
"access_token": "eyJhbG...",
"token_type": "bearer",
"expires_in": 3600
}
```
### 2. Tester la completion
```bash
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
```bash
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
```bash
curl -X GET http://localhost:7860/models \
-H "Authorization: Bearer $TOKEN"
```
### 5. Transcription audio
```bash
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`:
```env
LANGCHAIN_TRACING_V2=true
LANGCHAIN_API_KEY=votre-cle-langsmith
LANGCHAIN_PROJECT=routeur-ia
```
### Production
```bash
# 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
```bash
# 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](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
```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
```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! 🎉
|