From 5679940fa7af32416c2b6df68fe781ce35500269 Mon Sep 17 00:00:00 2001 From: Antoine Piron Date: Mon, 12 Oct 2026 14:52:25 +0200 Subject: [PATCH] Fetch GitHub Models catalog with httpx and documented headers Co-Authored-By: Claude Sonnet 5.5 --- artifacts/flask-api/ai_agent.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/artifacts/flask-api/ai_agent.py b/artifacts/flask-api/ai_agent.py index 0defe41..386114a 100644 --- a/artifacts/flask-api/ai_agent.py +++ b/artifacts/flask-api/ai_agent.py @@ -8,6 +8,7 @@ Supporte Mistral AI (par défaut) et tout fournisseur compatible OpenAI. import json import os import logging +import httpx from openai import OpenAI, BadRequestError from legal_framework import LEGAL_FILTER_PROMPT, SYNTHESIS_PROMPT, LAW_CHECK_PROMPT, build_filter_prompt from legifrance_client import get_legifrance_client @@ -84,9 +85,18 @@ def list_model_ids() -> list[str]: """Modèles accessibles avec la clé en place (GitHub Models : catalogue dédié, /models n'est pas OpenAI-compatible).""" client = get_client() if "models.github.ai" in str(client.base_url): - raw = client.get(GITHUB_CATALOG_URL, cast_to=object) - if isinstance(raw, (str, bytes)): # content-type non-JSON : le SDK rend le texte brut - raw = json.loads(raw) + r = httpx.get( + GITHUB_CATALOG_URL, + headers={ + "Authorization": f"Bearer {client.api_key}", + "Accept": "application/vnd.github+json", + "X-GitHub-Api-Version": "2022-11-28", + }, + timeout=10, + ) + if r.status_code != 200 or not r.content: + raise RuntimeError(f"catalogue GitHub HTTP {r.status_code} : {r.text[:120]!r}") + raw = r.json() if isinstance(raw, dict): raw = next((v for v in raw.values() if isinstance(v, list)), []) return sorted(m["id"] if isinstance(m, dict) else str(m) for m in raw) -- 2.39.5