smart_ide/docs/API/langextract-api.md
Nicolas Cantu 088eab84b7 Platform docs, services, ia_dev submodule, smart_ide project config
- Add ia_dev submodule (projects/smart_ide on forge 4nk)
- Document APIs, orchestrator, gateway, local-office, rollout
- Add systemd/scripts layout; relocate setup scripts
- Remove obsolete nginx/enso-only docs from this repo scope
2026-04-03 16:07:58 +02:00

88 lines
2.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# API — langextract-api
Service FastAPI : enveloppe [LangExtract](https://github.com/google/langextract) pour extractions structurées depuis du texte.
- **Code** : [`services/langextract-api/`](../../services/langextract-api/)
- **Bind** : `LANGEXTRACT_API_HOST` (défaut `127.0.0.1`)
- **Port** : `LANGEXTRACT_API_PORT` (défaut `37141`)
- **OpenAPI** : `GET http://<host>:<port>/docs` une fois le service lancé
## Authentification
Si `LANGEXTRACT_SERVICE_TOKEN` est défini (non vide), toutes les routes **sauf** celles sans dépendance explicite doivent envoyer :
```http
Authorization: Bearer <LANGEXTRACT_SERVICE_TOKEN>
```
Actuellement **`/health`** nimpose pas le Bearer ; **`/extract`** impose le Bearer lorsque le token service est configuré.
## Endpoints
### `GET /health`
**Réponse `200`**
```json
{ "status": "ok" }
```
### `POST /extract`
Exécute une extraction LangExtract.
**Corps JSON** (modèle Pydantic `ExtractRequest`)
| Champ | Obligatoire | Description |
|-------|-------------|-------------|
| `text` | oui | Texte source |
| `prompt_description` | oui | Consigne dextraction |
| `examples` | oui | Liste dexemples (voir ci-dessous) |
| `model_id` | oui | Identifiant modèle (ex. tag Ollama) |
| `model_url` | non | URL du serveur modèle (ex. Ollama `http://127.0.0.1:11434`) |
| `extraction_passes` | non | Passes dextraction |
| `max_workers` | non | Parallélisme |
| `max_char_buffer` | non | Taille tampon caractères |
| `api_key` | non | Clé cloud (sinon `LANGEXTRACT_API_KEY` en env) |
| `fence_output` | non | Option LangExtract |
| `use_schema_constraints` | non | Option LangExtract |
**Élément `examples`**
Chaque entrée : `{ "text": "...", "extractions": [ { "extraction_class", "extraction_text", "attributes": {} } ] }`.
**Réponse `200`**
```json
{
"documents": [
{
"extractions": [
{
"extraction_class": "...",
"extraction_text": "...",
"attributes": {},
"char_interval": { "start": 0, "end": 0 }
}
]
}
]
}
```
`char_interval` est présent lorsque le moteur le fournit.
**Erreurs**
- `400` : corps invalide ou exception LangExtract (`detail` message texte)
- `401` : Bearer attendu mais absent ou incorrect (si token service configuré)
## Variables denvironnement
| Variable | Obligatoire | Description |
|----------|-------------|-------------|
| `LANGEXTRACT_SERVICE_TOKEN` | non | Si défini, protège `/extract` |
| `LANGEXTRACT_API_HOST` | non | Bind |
| `LANGEXTRACT_API_PORT` | non | Port |
| `LANGEXTRACT_API_KEY` | non | Clé par défaut pour modèles cloud si le client nenvoie pas `api_key` |