Add Légifrance API integration for live legal text injection

Implements a two-layer approach to ensure legal texts are accurate and current:

Option A — runtime injection (legifrance_client.py):
- LegifranceClient: OAuth2 via PISTE (oauth.piste.gouv.fr), fetches consolidated
  article text via api.piste.gouv.fr/dila/legifrance/lf-engine-app
- Redis cache with 24h TTL (in-memory fallback if no Redis)
- build_filter_prompt() injects live texts into the prompt with explicit priority
  over static descriptions — model uses official Légifrance text, not training memory
- Graceful fallback to static prompt if API is unavailable — filtering never blocks

Option B — weekly sync script (scripts/check_legal_refs.py):
- Reads legal_refs.yaml (11 tracked articles, priority critical/high/medium)
- Fetches current text from Légifrance, diffs against stored baseline
- --init: resolves LEGIARTI IDs on first run
- --check: report only; --update: saves new texts to YAML
- Exit code 2 when changes detected (CI/n8n-compatible)

Supporting changes:
- legal_refs.yaml: tracked articles with code LEGITEXT IDs, priorities, rationale
- requirements.txt: add pyyaml>=6.0.2 and requests>=2.32.0
- .env.example: document PISTE_CLIENT_ID, PISTE_CLIENT_SECRET, LEGIFRANCE_CACHE_TTL
- transparence.tsx: document the Légifrance injection for public transparency
- Fixed portal URL: piste.gouv.fr (not piste.api.gouv.fr — verified June 2026)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-24 09:19:23 +02:00
parent e8b4bde2f4
commit 67bb0095fa
8 changed files with 764 additions and 2 deletions
+21
View File
@@ -41,6 +41,27 @@ PORT=8080
# HCAPTCHA_SECRET_KEY=votre-cle-secrete-hcaptcha
# VITE_HCAPTCHA_SITE_KEY=votre-cle-de-site-hcaptcha # Nécessite rebuild frontend
# ─── API Légifrance — Injection dynamique des textes légaux (optionnel) ───────
# Permet de récupérer les textes des articles légaux en vigueur depuis Légifrance
# et de les injecter dans le prompt de filtrage, garantissant que le modèle IA
# travaille sur les textes officiels consolidés du jour, et non sa mémoire d'entraînement.
#
# Inscription gratuite sur https://piste.gouv.fr
# Créez une application → activez l'API Légifrance → copiez Client ID et Client Secret.
#
# PISTE_CLIENT_ID=votre-client-id
# PISTE_CLIENT_SECRET=votre-client-secret
#
# Durée de cache des textes légaux (Redis, défaut 24h) :
# LEGIFRANCE_CACHE_TTL=86400
#
# Initialisation (première fois, pour résoudre les LEGIARTI IDs) :
# python scripts/check_legal_refs.py --init
# Vérification hebdomadaire des changements :
# python scripts/check_legal_refs.py --check
# Mise à jour du YAML après changement :
# python scripts/check_legal_refs.py --update
# ─── Frontend ─────────────────────────────────────────────────────────────────
# URL publique du site (utilisée par le QR code et les exports)
VITE_APP_URL=https://votredomaine.fr