Public Access
Ajout du module multimédia (Text-to-Image via HuggingFace et Cloudflare) et sécurisation du routeur Multi-IA
Build and Push Docker Image / build-and-push (push) Successful in 38s
Build and Push Docker Image / build-and-push (push) Successful in 38s
This commit is contained in:
1 parent
c82e12f49a
commit
519a42107f
8 files changed
+284
-82
No files matched your search
+68
-59
@@ -16,6 +16,7 @@ from modules.logger import log_event
|
||||
from modules.billing_manager import verifier_et_valider_budget, obtenir_solde
|
||||
from modules.rag_manager import rechercher_contexte_rag, auto_apprendre_rag
|
||||
from modules.moderator import analyser_intention_illicite, appliquer_sanction_et_archiver
|
||||
from modules.ai_media import router_media # <--- IMPORT DU NOUVEAU MODULE
|
||||
|
||||
def check_and_update_resource_quota(utilisateur_nom, role_utilisateur):
|
||||
quota_file = "/DATA/AppData/MULTI-IA-AETHAS38/Utilisateurs/quotas_ressources.json"
|
||||
@@ -45,7 +46,9 @@ async def handle_chat_request(request, session):
|
||||
|
||||
mode_payant = form.get("mode_payant") == "on"
|
||||
mode_multi_ia = form.get("mode_multi_ia") == "on"
|
||||
mode_education = form.get("mode_education") == "on" # INTERCEPTION DU MODE EDU
|
||||
mode_education = form.get("mode_education") == "on"
|
||||
media_mode = form.get("media_mode", "texte")
|
||||
|
||||
validation_acquise = form.get("validation_acquise") == "true"
|
||||
choix_utilisateur = form.get("choix_utilisateur", "aucun")
|
||||
|
||||
@@ -81,69 +84,75 @@ async def handle_chat_request(request, session):
|
||||
file_summary.append(f"\n--- Fichier : {f.filename} ---\n{content.decode('utf-8', errors='ignore')}")
|
||||
|
||||
liste_fichiers_str = ", ".join(file_names) if file_names else "Aucun fichier"
|
||||
log_event("INFO", "SYSTEM", f"Requête reçue (Edu: {mode_education} / Payant: {mode_payant})")
|
||||
log_event("INFO", "SYSTEM", f"Requête reçue (Mode: {media_mode.upper()} / Payant: {mode_payant})")
|
||||
|
||||
sec_prompt = f"""Tu es l'Orchestrateur système. Analyse la requête et choisis le meilleur fournisseur IA..."""
|
||||
try:
|
||||
texte_routeur, _, _, _ = interroger_local_ollama(sec_prompt)
|
||||
decision = nettoyer_decision_router(texte_routeur)
|
||||
except:
|
||||
decision = {"intention": "Analyse", "fournisseur": "openrouter_chat", "theme_rag": "aucun"}
|
||||
# --- AIGUILLAGE MULTIMÉDIA ---
|
||||
if media_mode in ["image", "video"]:
|
||||
reponse, couleur, fournisseur_nom, modele, trace_route = router_media(prompt, type_media=media_mode, premium=mode_payant, fichiers=file_names)
|
||||
intention = f"Génération {media_mode.capitalize()}"
|
||||
thematique_rag = "aucun"
|
||||
|
||||
# --- AIGUILLAGE TEXTE (CLASSIQUE) ---
|
||||
else:
|
||||
sec_prompt = f"""Tu es l'Orchestrateur système. Analyse la requête et choisis le meilleur fournisseur IA..."""
|
||||
try:
|
||||
texte_routeur, _, _, _ = interroger_local_ollama(sec_prompt)
|
||||
decision = nettoyer_decision_router(texte_routeur)
|
||||
except:
|
||||
decision = {"intention": "Analyse", "fournisseur": "openrouter_chat", "theme_rag": "aucun"}
|
||||
|
||||
intention = decision.get("intention", "Analyse")
|
||||
fournisseur = decision.get("fournisseur", "openrouter_chat").lower()
|
||||
thematique_rag = decision.get("theme_rag", "aucun").lower()
|
||||
|
||||
if mode_payant or mode_multi_ia:
|
||||
fournisseur = "openrouter_code"
|
||||
intention += " (API Premium/Multi)"
|
||||
|
||||
if file_names:
|
||||
fournisseur = "gemini"
|
||||
|
||||
if mode_education:
|
||||
fournisseur = "openrouter_chat"
|
||||
thematique_rag = "Education_Nationale"
|
||||
intention = "Éducation Nationale " + ("(Payant)" if mode_payant else "(IA Gratuite)")
|
||||
instruction_edu = "[SYSTÈME] RÈGLE ÉDUCATION NATIONALE : Agis comme un expert de l'Éducation Nationale française. Pédagogie stricte, respect du B.O.\n\n"
|
||||
prompt = instruction_edu + prompt
|
||||
|
||||
contexte_rag = ""
|
||||
if thematique_rag != "aucun":
|
||||
contexte_rag = rechercher_contexte_rag(prompt, categorie=thematique_rag)
|
||||
|
||||
urls = re.findall(r"https?://[^\s]+", prompt)
|
||||
if any(m in prompt.lower() for m in ["cherche", "recherche", "sur le web"]):
|
||||
urls.extend(rechercher_sur_google(prompt))
|
||||
web_text = extraire_contenu_urls(list(set(urls))) if urls else ""
|
||||
|
||||
intention = decision.get("intention", "Analyse")
|
||||
fournisseur = decision.get("fournisseur", "openrouter_chat").lower()
|
||||
thematique_rag = decision.get("theme_rag", "aucun").lower()
|
||||
full_prompt = prompt + ("\n" + "\n".join(file_summary) if file_summary else "")
|
||||
if contexte_rag: full_prompt += f"\n\n[Contexte RAG :\n{contexte_rag}]"
|
||||
if web_text: full_prompt += f"\n\n[Contexte web :\n{web_text}]"
|
||||
|
||||
if mode_payant or mode_multi_ia:
|
||||
fournisseur = "openrouter_code"
|
||||
intention += " (API Premium/Multi)"
|
||||
if "openrouter" in fournisseur:
|
||||
modele_estime = "anthropic/claude-3.5-sonnet" if mode_payant else "cohere/north-mini-code:free"
|
||||
|
||||
if mode_payant and not validation_acquise:
|
||||
from modules.billing_manager import estimer_cout_facture
|
||||
_, prix_estime, _ = estimer_cout_facture(full_prompt, modele_estime, rang_utilisateur=role_utilisateur, multi_ia=mode_multi_ia)
|
||||
if prix_estime > 0:
|
||||
return render_popup_paiement(prix_estime, prompt, chat_id, mode_multi_ia, mode_education)
|
||||
|
||||
if file_names:
|
||||
fournisseur = "gemini"
|
||||
if mode_payant and role_utilisateur.lower() not in ["super admin", "admin", "vip", "famille"]:
|
||||
from modules.billing_manager import estimer_cout_facture
|
||||
_, prix_estime, _ = estimer_cout_facture(full_prompt, modele_estime, rang_utilisateur=role_utilisateur, multi_ia=mode_multi_ia)
|
||||
if prix_estime > obtenir_solde(utilisateur_nom):
|
||||
return Div(H3("❌ Solde Insuffisant", style="color:red;"), P("Rechargez votre compte."), style="background:#300; padding:15px;")
|
||||
|
||||
# --- LOGIQUE EDUCATION NATIONALE ---
|
||||
if mode_education:
|
||||
fournisseur = "openrouter_chat"
|
||||
thematique_rag = "Education_Nationale"
|
||||
intention = "Éducation Nationale " + ("(Payant)" if mode_payant else "(IA Gratuite)")
|
||||
# Marqueur secret pour ai_openrouter.py
|
||||
instruction_edu = "[SYSTÈME] RÈGLE ÉDUCATION NATIONALE : Agis comme un expert de l'Éducation Nationale française. Pédagogie stricte, respect du B.O.\n\n"
|
||||
prompt = instruction_edu + prompt
|
||||
|
||||
contexte_rag = ""
|
||||
if thematique_rag != "aucun":
|
||||
contexte_rag = rechercher_contexte_rag(prompt, categorie=thematique_rag)
|
||||
|
||||
urls = re.findall(r"https?://[^\s]+", prompt)
|
||||
if any(m in prompt.lower() for m in ["cherche", "recherche", "sur le web"]):
|
||||
urls.extend(rechercher_sur_google(prompt))
|
||||
web_text = extraire_contenu_urls(list(set(urls))) if urls else ""
|
||||
|
||||
full_prompt = prompt + ("\n" + "\n".join(file_summary) if file_summary else "")
|
||||
if contexte_rag: full_prompt += f"\n\n[Contexte RAG :\n{contexte_rag}]"
|
||||
if web_text: full_prompt += f"\n\n[Contexte web :\n{web_text}]"
|
||||
|
||||
if "openrouter" in fournisseur:
|
||||
modele_estime = "anthropic/claude-3.5-sonnet" if mode_payant else "cohere/north-mini-code:free"
|
||||
reponse, couleur, fournisseur_nom, modele, trace_route = executer_requete_ia(
|
||||
fournisseur, full_prompt, mode_payant=mode_payant, multi_ia=mode_multi_ia, chat_id=chat_id
|
||||
)
|
||||
|
||||
if mode_payant and not validation_acquise:
|
||||
from modules.billing_manager import estimer_cout_facture
|
||||
_, prix_estime, _ = estimer_cout_facture(full_prompt, modele_estime, rang_utilisateur=role_utilisateur, multi_ia=mode_multi_ia)
|
||||
if prix_estime > 0:
|
||||
return render_popup_paiement(prix_estime, prompt, chat_id, mode_multi_ia, mode_education)
|
||||
|
||||
if mode_payant and role_utilisateur.lower() not in ["super admin", "admin", "vip", "famille"]:
|
||||
from modules.billing_manager import estimer_cout_facture
|
||||
_, prix_estime, _ = estimer_cout_facture(full_prompt, modele_estime, rang_utilisateur=role_utilisateur, multi_ia=mode_multi_ia)
|
||||
if prix_estime > obtenir_solde(utilisateur_nom):
|
||||
return Div(H3("❌ Solde Insuffisant", style="color:red;"), P("Rechargez votre compte."), style="background:#300; padding:15px;")
|
||||
|
||||
reponse, couleur, fournisseur_nom, modele, trace_route = executer_requete_ia(
|
||||
fournisseur, full_prompt, mode_payant=mode_payant, multi_ia=mode_multi_ia, chat_id=chat_id
|
||||
)
|
||||
|
||||
if "openrouter" in fournisseur_nom.lower() and mode_payant:
|
||||
verifier_et_valider_budget(full_prompt, modele, utilisateur_nom=utilisateur_nom, rang_utilisateur=role_utilisateur, multi_ia=mode_multi_ia)
|
||||
if "openrouter" in fournisseur_nom.lower() and mode_payant:
|
||||
verifier_et_valider_budget(full_prompt, modele, utilisateur_nom=utilisateur_nom, rang_utilisateur=role_utilisateur, multi_ia=mode_multi_ia)
|
||||
|
||||
if thematique_rag != "aucun" and reponse:
|
||||
auto_apprendre_rag(prompt, reponse, thematique_rag)
|
||||
@@ -164,7 +173,7 @@ async def handle_chat_request(request, session):
|
||||
"modele": modele,
|
||||
"couleur": couleur,
|
||||
"execution_time": execution_time,
|
||||
"trace": trace_route # <--- Ajout de la traçabilité
|
||||
"trace": trace_route
|
||||
})
|
||||
save_history(history)
|
||||
|
||||
|
||||
Reference in new issue
Block a user