Public Access
Test : Intégration bouton PayPal Sandbox et activation du Serveur Mail
Build and Push Docker Image / build-and-push (push) Successful in 1m45s
Build and Push Docker Image / build-and-push (push) Successful in 1m45s
This commit is contained in:
1 parent
632c23069a
commit
2ea18701b5
12 files changed
+486
-187
No files matched your search
+15
-10
@@ -9,8 +9,6 @@ load_dotenv()
|
||||
|
||||
api_key_openrouter = os.getenv("OPENROUTER_API_KEY") or "sk-or-v1-cle-non-definie"
|
||||
client = OpenAI(base_url="https://openrouter.ai/api/v1", api_key=api_key_openrouter)
|
||||
|
||||
# Chemin ABSOLU strict
|
||||
CATALOGUE_FILE = "/DATA/AppData/MULTI-IA-AETHAS38/catalogue_dynamique.json"
|
||||
|
||||
def verifier_cle_api():
|
||||
@@ -19,8 +17,10 @@ def verifier_cle_api():
|
||||
raise Exception("Clé OPENROUTER_API_KEY absente dans le fichier .env.")
|
||||
return cle
|
||||
|
||||
def obtenir_modele_dynamique(premium: bool):
|
||||
"""Charge le catalogue dynamiquement selon l'état Premium ou Gratuit."""
|
||||
def obtenir_modele_dynamique(premium: bool, prompt: str = ""):
|
||||
"""Charge le catalogue dynamiquement et adapte le modèle si la règle Éducation est détectée."""
|
||||
est_education = "RÈGLE ÉDUCATION NATIONALE" in prompt
|
||||
|
||||
try:
|
||||
if os.path.exists(CATALOGUE_FILE):
|
||||
with open(CATALOGUE_FILE, "r", encoding="utf-8") as f:
|
||||
@@ -30,20 +30,25 @@ def obtenir_modele_dynamique(premium: bool):
|
||||
claude = [m for m in paid_models if "claude-3.5-sonnet" in m.lower()]
|
||||
return claude[0] if claude else (paid_models[0] if paid_models else "anthropic/claude-3.5-sonnet")
|
||||
else:
|
||||
# En mode gratuit + Education, Mistral est le plus pointu en syntaxe française
|
||||
if est_education:
|
||||
return "mistralai/mistral-small-24b-instruct-2501:free"
|
||||
|
||||
free_models = data.get("free_models", [])
|
||||
priorites = [m for m in free_models if "gemma" in m.lower() or "nemotron" in m.lower()]
|
||||
return priorites[0] if priorites else (free_models[0] if free_models else "google/gemma-2-9b-it:free")
|
||||
except Exception:
|
||||
pass
|
||||
return "anthropic/claude-3.5-sonnet" if premium else "google/gemma-2-9b-it:free"
|
||||
|
||||
if premium: return "anthropic/claude-3.5-sonnet"
|
||||
return "mistralai/mistral-small-24b-instruct-2501:free" if est_education else "google/gemma-2-9b-it:free"
|
||||
|
||||
def interroger_openrouter(prompt: str, type_modele: str = "openrouter_chat", premium: bool = False, max_retries: int = 2, chat_id: str = None):
|
||||
verifier_cle_api()
|
||||
nom_modele_api = obtenir_modele_dynamique(premium)
|
||||
nom_modele_api = obtenir_modele_dynamique(premium, prompt) # On passe le prompt pour détecter le marqueur
|
||||
nom_affichage = f"OpenRouter ({nom_modele_api.split('/')[-1]})"
|
||||
couleur = "#d97757" if premium else "#4a90e2"
|
||||
|
||||
# Injection du Tracker Financier OpenRouter
|
||||
extra_body_data = {"session_id": chat_id} if chat_id else {}
|
||||
|
||||
for tentative in range(max_retries):
|
||||
@@ -53,7 +58,7 @@ def interroger_openrouter(prompt: str, type_modele: str = "openrouter_chat", pre
|
||||
messages=[{"role": "user", "content": prompt}],
|
||||
extra_headers={"HTTP-Referer": "https://aethas38.duckdns.org", "X-Title": "Aethas38 Multi-IA"},
|
||||
extra_body=extra_body_data,
|
||||
timeout=90.0 # TIMEOUT MONTE A 90s
|
||||
timeout=90.0
|
||||
)
|
||||
texte = response.choices[0].message.content
|
||||
usage = response.usage
|
||||
@@ -78,7 +83,7 @@ def interroger_openrouter_multi(prompt: str, type_modele: str = "openrouter_code
|
||||
verifier_cle_api()
|
||||
extra_body_data = {"session_id": chat_id} if chat_id else {}
|
||||
|
||||
modeles = [obtenir_modele_dynamique(premium)]
|
||||
modeles = [obtenir_modele_dynamique(premium, prompt)]
|
||||
if premium:
|
||||
modeles.append("openai/gpt-4o-mini")
|
||||
else:
|
||||
@@ -92,7 +97,7 @@ def interroger_openrouter_multi(prompt: str, type_modele: str = "openrouter_code
|
||||
messages=[{"role": "user", "content": prompt}],
|
||||
extra_headers={"HTTP-Referer": "https://aethas38.duckdns.org", "X-Title": "Aethas38 Multi-IA"},
|
||||
extra_body=extra_body_data,
|
||||
timeout=90.0 # TIMEOUT MONTE A 90s
|
||||
timeout=90.0
|
||||
)
|
||||
contenu = res.choices[0].message.content
|
||||
if contenu:
|
||||
|
||||
Reference in new issue
Block a user