Amélioration modules updater et sélection des IA suivant disponibilités
Build and Push Docker Image / build-and-push (push) Successful in 35s

This commit is contained in:
xavier committed 2026-08-29 12:40:56 +02:00
1 parent 3553809df3
commit d36cb07ab1
2 files changed
+96 -39

No files matched your search

+22 -5
View File
@@ -1,16 +1,34 @@
import os
import json
import requests
from modules.logger import log_event
def interroger_huggingface(prompt: str, modele_cible="mistralai/Mistral-7B-Instruct-v0.3"):
CATALOGUE_FILE = "/DATA/AppData/MULTI-IA-AETHAS38/catalogue_dynamique.json"
def interroger_huggingface(prompt: str, modele_cible=None):
"""
Connecteur pour l'API Serverless gratuite de Hugging Face.
S'intègre nativement dans la boucle de repli de ai_engine.py.
Connecteur pour l'API Serverless de Hugging Face.
Sélectionne dynamiquement le modèle le plus populaire scanné par l'Updater.
"""
api_key = os.getenv("HUGGINGFACE_API_KEY")
if not api_key:
raise Exception("Clé API HuggingFace manquante dans le .env")
# Extraction dynamique du meilleur modèle Hugging Face gratuit disponible
if not modele_cible:
try:
if os.path.exists(CATALOGUE_FILE):
with open(CATALOGUE_FILE, "r", encoding="utf-8") as f:
data = json.load(f)
hf_models = [m.replace("huggingface/", "") for m in data.get("free_models", []) if m.startswith("huggingface/")]
if hf_models:
modele_cible = hf_models[0] # Modèle le plus téléchargé selon l'Updater
except Exception:
pass
if not modele_cible:
modele_cible = "mistralai/Mistral-7B-Instruct-v0.3"
url = f"https://router.huggingface.co/hf-inference/models/{modele_cible}"
headers = {
"Authorization": f"Bearer {api_key}",
@@ -33,10 +51,9 @@ def interroger_huggingface(prompt: str, modele_cible="mistralai/Mistral-7B-Instr
data = resp.json()
if isinstance(data, list) and len(data) > 0 and "generated_text" in data[0]:
texte = data[0]["generated_text"].strip()
# Renvoie la signature exacte attendue par ai_engine (texte, couleur, fournisseur, modele)
return texte, "#ffb000", "HuggingFace", modele_cible
raise Exception(f"Erreur {resp.status_code} : {resp.text}")
except Exception as e:
log_event("WARNING", "HUGGINGFACE", f"Échec de la requête : {e}")
log_event("WARNING", "HUGGINGFACE", f"Échec de la requête pour {modele_cible} : {e}")
raise e