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
+38
-9
@@ -3,6 +3,7 @@ from modules.logger import log_event
|
||||
from modules.ai_gemini import interroger_gemini
|
||||
from modules.ai_local import interroger_local_ollama
|
||||
from modules.ai_openrouter import interroger_openrouter, interroger_openrouter_multi
|
||||
from modules.ai_huggingface import interroger_huggingface
|
||||
|
||||
SYSTEM_CONFIDENTIALITY_INSTRUCTION = (
|
||||
"RÈGLE DE CONFIDENTIALITÉ ABSOLUE : Tu es un assistant intégré à la plateforme privée Aethas38. "
|
||||
@@ -12,9 +13,33 @@ SYSTEM_CONFIDENTIALITY_INSTRUCTION = (
|
||||
)
|
||||
|
||||
def executer_synthese_multi_ia(prompt_securise: str, fournisseur: str, mode_payant: bool = False, chat_id: str = None):
|
||||
reponses_brutes = []
|
||||
|
||||
try:
|
||||
# Passage du chat_id (code hexadécimal) à l'API Multi
|
||||
reponses_brutes = interroger_openrouter_multi(prompt_securise, type_modele=fournisseur, premium=mode_payant, chat_id=chat_id)
|
||||
# 1. Lancement PARALLÈLE vers OpenRouter et Hugging Face
|
||||
with concurrent.futures.ThreadPoolExecutor() as executor:
|
||||
future_or = executor.submit(interroger_openrouter_multi, prompt_securise, type_modele=fournisseur, premium=mode_payant, chat_id=chat_id)
|
||||
future_hf = executor.submit(interroger_huggingface, prompt_securise)
|
||||
|
||||
# 2. Récupération des résultats OpenRouter
|
||||
try:
|
||||
resultat_or = future_or.result()
|
||||
if resultat_or:
|
||||
reponses_brutes.extend(resultat_or)
|
||||
except Exception as e:
|
||||
log_event("WARNING", "MULTI_IA", f"Échec OpenRouter : {e}")
|
||||
|
||||
# 3. Récupération des résultats Hugging Face
|
||||
try:
|
||||
resultat_hf = future_hf.result()
|
||||
if resultat_hf and resultat_hf[0]:
|
||||
texte_hf, _, _, modele_hf = resultat_hf
|
||||
# Formatage identique à OpenRouter pour la synthèse
|
||||
reponses_brutes.append({"modele": f"HuggingFace ({modele_hf})", "texte": texte_hf})
|
||||
except Exception as e:
|
||||
log_event("WARNING", "MULTI_IA", f"Échec HuggingFace : {e}")
|
||||
|
||||
# 4. Synthèse par Gemini si au moins un modèle a répondu
|
||||
if len(reponses_brutes) >= 1:
|
||||
instruction_synthese = (
|
||||
"RÈGLE DE CONFIDENTIALITÉ : Tu es un assistant IA. "
|
||||
@@ -29,9 +54,13 @@ def executer_synthese_multi_ia(prompt_securise: str, fournisseur: str, mode_paya
|
||||
|
||||
prompt_synthese += f"Demande initiale :\n{prompt_securise}"
|
||||
texte, couleur, _, _ = interroger_gemini(prompt_synthese)
|
||||
return texte, couleur, "Multi-IA (Synthèse Gemini)", "Pipeline Multi-Modèles"
|
||||
|
||||
# Mise à jour du nom de fournisseur pour refléter le travail de l'orchestrateur
|
||||
vrai_fournisseur = f"Multi-IA (OR + HF -> Gemini)" if len(reponses_brutes) > 1 else "Multi-IA (Partiel -> Gemini)"
|
||||
return texte, couleur, vrai_fournisseur, f"Synthèse de {len(reponses_brutes)} modèles"
|
||||
|
||||
except Exception as e:
|
||||
log_event("WARNING", "MULTI_IA", f"Échec synthèse, repli : {e}")
|
||||
log_event("WARNING", "MULTI_IA", f"Échec total synthèse : {e}")
|
||||
|
||||
return None
|
||||
|
||||
@@ -42,14 +71,14 @@ def executer_requete_ia(fournisseur: str, prompt: str, mode_payant: bool = False
|
||||
if multi_ia or fournisseur in ["openrouter_code", "openrouter_droit"]:
|
||||
resultat_multi = executer_synthese_multi_ia(prompt_securise, fournisseur, mode_payant, chat_id)
|
||||
if resultat_multi:
|
||||
return resultat_multi[0], resultat_multi[1], resultat_multi[2], resultat_multi[3], ["🟢 Multi-IA / Synthèse Gemini réussie"]
|
||||
return resultat_multi[0], resultat_multi[1], resultat_multi[2], resultat_multi[3], [f"🟢 {resultat_multi[2]} réussie"]
|
||||
|
||||
if fournisseur == "gemini":
|
||||
ordre_repli = [interroger_gemini, interroger_openrouter, interroger_local_ollama]
|
||||
ordre_repli = [interroger_gemini, interroger_openrouter, interroger_huggingface, interroger_local_ollama]
|
||||
elif fournisseur in ["openrouter_code", "openrouter_chat", "openrouter_droit"]:
|
||||
ordre_repli = [interroger_openrouter, interroger_gemini, interroger_local_ollama]
|
||||
ordre_repli = [interroger_openrouter, interroger_gemini, interroger_huggingface, interroger_local_ollama]
|
||||
else:
|
||||
ordre_repli = [interroger_local_ollama, interroger_openrouter, interroger_gemini]
|
||||
ordre_repli = [interroger_local_ollama, interroger_openrouter, interroger_huggingface, interroger_gemini]
|
||||
|
||||
for fonction_api in ordre_repli:
|
||||
nom_tente = fonction_api.__name__.replace("interroger_", "")
|
||||
@@ -65,7 +94,7 @@ def executer_requete_ia(fournisseur: str, prompt: str, mode_payant: bool = False
|
||||
trace_tentatives.append(f"🟢 {nom_tente.upper()} ({nom_modele}) : Succès")
|
||||
return texte, couleur, nom_fournisseur, nom_modele, trace_tentatives
|
||||
except Exception as e:
|
||||
msg_err = str(e).split("-")[0].strip()[:50] # On raccourcit l'erreur pour l'affichage
|
||||
msg_err = str(e).split("-")[0].strip()[:50]
|
||||
trace_tentatives.append(f"🔴 {nom_tente.upper()} : Échec ({msg_err})")
|
||||
log_event("WARNING", "ORCHESTRATEUR", f"Basculement suite à l'échec de {fonction_api.__name__} : {e}")
|
||||
continue
|
||||
|
||||
Reference in new issue
Block a user