2 Commits
+13 -3
View File
@@ -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)