Public Access
Ajout du connecteur Hugging Face et mise à jour du Multi-IA
Build and Push Docker Image / build-and-push (push) Successful in 37s
Build and Push Docker Image / build-and-push (push) Successful in 37s
This commit is contained in:
1 parent
a510916247
commit
eab18d8324
4 files changed
+131
-32
No files matched your search
@@ -7,6 +7,41 @@ from modules.logger import log_event
|
||||
|
||||
CATALOGUE_FILE = "/DATA/AppData/MULTI-IA-AETHAS38/catalogue_dynamique.json"
|
||||
|
||||
def recuperer_modeles_hf():
|
||||
"""
|
||||
Récupère les modèles populaires de Hugging Face (Texte, Image, Vidéo).
|
||||
Les identifiants sont préfixés par 'huggingface/' pour le routage Multi-IA.
|
||||
"""
|
||||
api_key = os.getenv("HUGGINGFACE_API_KEY")
|
||||
headers = {"Authorization": f"Bearer {api_key}"} if api_key else {}
|
||||
|
||||
# Catégories et nombre limite de modèles à récupérer pour garantir les plus fiables
|
||||
categories = {
|
||||
"text-generation": 20, # 20 LLMs texte
|
||||
"text-to-image": 5, # 5 Générateurs d'images
|
||||
"text-to-video": 2 # 2 Générateurs vidéo
|
||||
}
|
||||
|
||||
hf_models = []
|
||||
for tag, limit in categories.items():
|
||||
url = "https://huggingface.co/api/models"
|
||||
params = {
|
||||
"pipeline_tag": tag,
|
||||
"sort": "downloads",
|
||||
"direction": -1,
|
||||
"limit": limit
|
||||
}
|
||||
try:
|
||||
resp = requests.get(url, headers=headers, params=params, timeout=15)
|
||||
if resp.status_code == 200:
|
||||
for m in resp.json():
|
||||
# Formatage identifiable pour l'orchestrateur
|
||||
hf_models.append(f"huggingface/{m['id']}")
|
||||
except Exception as e:
|
||||
log_event("WARNING", "UPDATER", f"Erreur de récupération HF pour {tag}: {e}")
|
||||
|
||||
return hf_models
|
||||
|
||||
def _do_update():
|
||||
ollama_host = os.getenv("OLLAMA_HOST", "http://192.168.1.20:11434")
|
||||
try:
|
||||
@@ -21,25 +56,32 @@ def _do_update():
|
||||
|
||||
# MAJ DU CATALOGUE COMPLET OPENROUTER
|
||||
resp_or = requests.get("https://openrouter.ai/api/v1/models", timeout=30)
|
||||
modeles_gratuits = []
|
||||
modeles_payants = []
|
||||
|
||||
if resp_or.status_code == 200:
|
||||
data = resp_or.json().get("data", [])
|
||||
modeles_gratuits = []
|
||||
modeles_payants = []
|
||||
|
||||
for m in data:
|
||||
pricing = m.get("pricing", {})
|
||||
|
||||
# S'il est 100% gratuit
|
||||
if pricing.get("prompt") == "0" and pricing.get("completion") == "0":
|
||||
if "nvidia/nemotron" not in m["id"].lower(): # On garde juste cette exclusion sécurité
|
||||
if "nvidia/nemotron" not in m["id"].lower(): # On garde l'exclusion sécurité
|
||||
modeles_gratuits.append(m["id"])
|
||||
else:
|
||||
# On intègre TOUS les modèles payants (Texte, Vision, 3D, etc.)
|
||||
# Intégration de TOUS les modèles payants
|
||||
modeles_payants.append(m["id"])
|
||||
|
||||
with open(CATALOGUE_FILE, "w", encoding="utf-8") as f:
|
||||
json.dump({"free_models": modeles_gratuits, "paid_models": modeles_payants}, f)
|
||||
log_event("INFO", "UPDATER", f"Catalogue Global mis à jour : {len(modeles_gratuits)} gratuits, {len(modeles_payants)} payants détectés.")
|
||||
else:
|
||||
log_event("WARNING", "UPDATER", "Échec de récupération du catalogue OpenRouter.")
|
||||
|
||||
# MAJ DU CATALOGUE HUGGING FACE
|
||||
hf_gratuits = recuperer_modeles_hf()
|
||||
modeles_gratuits.extend(hf_gratuits)
|
||||
|
||||
with open(CATALOGUE_FILE, "w", encoding="utf-8") as f:
|
||||
json.dump({"free_models": modeles_gratuits, "paid_models": modeles_payants}, f)
|
||||
|
||||
log_event("INFO", "UPDATER", f"Catalogue Global mis à jour : {len(modeles_gratuits)} gratuits (dont {len(hf_gratuits)} HF), {len(modeles_payants)} payants détectés.")
|
||||
|
||||
except Exception as e:
|
||||
log_event("ERROR", "UPDATER", f"Erreur lors de la MAJ auto : {e}")
|
||||
|
||||
Reference in new issue
Block a user