Compare commits
6
Commits
80ee96444e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e9f9c831c | ||
|
|
5679940fa7 | ||
|
|
51d91b91c4 | ||
|
|
9368f64a9b | ||
|
|
c53330c3bd | ||
|
|
5721a0a36f |
No files matched your search
@@ -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
|
||||
@@ -77,6 +78,31 @@ def get_client() -> OpenAI:
|
||||
return _client
|
||||
|
||||
|
||||
GITHUB_CATALOG_URL = "https://models.github.ai/catalog/models"
|
||||
|
||||
|
||||
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):
|
||||
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)
|
||||
return sorted(m.id for m in client.models.list().data)
|
||||
|
||||
|
||||
def filter_idea(content: str) -> dict:
|
||||
"""
|
||||
Filtre une idée selon le cadre légal international des droits humains
|
||||
|
||||
@@ -60,7 +60,7 @@ from database import (
|
||||
check_ip_blacklist, record_ip_rejection, get_ip_blacklist, remove_ip_blacklist,
|
||||
set_setting,
|
||||
)
|
||||
from ai_agent import filter_idea, synthesize_ideas, check_existing_law, get_client, get_model
|
||||
from ai_agent import filter_idea, synthesize_ideas, check_existing_law, get_client, get_model, list_model_ids
|
||||
|
||||
# ─── Logging ────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -1297,7 +1297,7 @@ def admin_ai_models():
|
||||
"""Modèles actuellement actifs + liste de ceux accessibles avec la clé en place."""
|
||||
out = {"filter": get_model("filter"), "synthesis": get_model("synthesis"), "available": [], "error": None}
|
||||
try:
|
||||
out["available"] = sorted(m.id for m in get_client().models.list().data)
|
||||
out["available"] = list_model_ids()
|
||||
except Exception as e:
|
||||
logger.warning("Admin — liste des modèles IA impossible : %s", type(e).__name__)
|
||||
out["error"] = f"{type(e).__name__}: {str(e)[:200]}"
|
||||
|
||||
Reference in new issue
Block a user