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
+68
-12
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import json
|
||||
import time
|
||||
import requests
|
||||
from datetime import datetime
|
||||
import tiktoken
|
||||
from modules.logger import log_event
|
||||
@@ -10,19 +11,50 @@ BASE_DIR = "/DATA/AppData/MULTI-IA-AETHAS38"
|
||||
os.makedirs(BASE_DIR, exist_ok=True)
|
||||
BALANCES_FILE = os.path.join(BASE_DIR, "aethas_balances.json")
|
||||
AUDIT_FILE = os.path.join(BASE_DIR, "aethas_financial_audit.json")
|
||||
|
||||
TARIFS_OPENROUTER = {
|
||||
"meta-llama/llama-3.1-8b-instruct:free": 0.0,
|
||||
"qwen/qwen-2.5-coder-32b-instruct:free": 0.0,
|
||||
"mistralai/mistral-small-24b-instruct-2501:free": 0.0,
|
||||
"openai/gpt-4o-mini": 0.0000015,
|
||||
"anthropic/claude-3.5-sonnet": 0.000015,
|
||||
"mistralai/mistral-large-2411": 0.000006,
|
||||
"google/gemini-2.5-pro": 0.000005
|
||||
}
|
||||
TARIFS_FILE = os.path.join(BASE_DIR, "tarifs_openrouter.json")
|
||||
|
||||
VIP_ADMIN_USERS = ["xavier", "céline", "celine", "anaëlle", "anaelle", "renan", "audric"]
|
||||
|
||||
def obtenir_tarifs_dynamiques() -> dict:
|
||||
"""Récupère les tarifs via API toutes les 2 heures maximum pour éviter le hardcoding."""
|
||||
maintenant = time.time()
|
||||
|
||||
if os.path.exists(TARIFS_FILE):
|
||||
if maintenant - os.path.getmtime(TARIFS_FILE) < 7200:
|
||||
try:
|
||||
with open(TARIFS_FILE, "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
tarifs = {}
|
||||
try:
|
||||
resp = requests.get("https://openrouter.ai/api/v1/models", timeout=10)
|
||||
if resp.status_code == 200:
|
||||
data = resp.json().get("data", [])
|
||||
for m in data:
|
||||
pricing = m.get("pricing", {})
|
||||
p_prompt = float(pricing.get("prompt", 0.0))
|
||||
p_comp = float(pricing.get("completion", 0.0))
|
||||
# On sécurise l'estimation en prenant la valeur la plus haute entre tokens in et out
|
||||
tarifs[m["id"]] = max(p_prompt, p_comp)
|
||||
|
||||
with open(TARIFS_FILE, "w", encoding="utf-8") as f:
|
||||
json.dump(tarifs, f, indent=4)
|
||||
log_event("INFO", "BILLING", "Tarifs OpenRouter mis à jour dynamiquement.")
|
||||
return tarifs
|
||||
except Exception as e:
|
||||
log_event("ERROR", "BILLING", f"Échec récupération des tarifs : {e}")
|
||||
|
||||
# Repli sur le cache si l'API est injoignable
|
||||
if os.path.exists(TARIFS_FILE):
|
||||
try:
|
||||
with open(TARIFS_FILE, "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
except Exception:
|
||||
pass
|
||||
return {}
|
||||
|
||||
def charger_soldes() -> dict:
|
||||
if os.path.exists(BALANCES_FILE):
|
||||
try:
|
||||
@@ -71,7 +103,8 @@ def compter_tokens(texte: str, modele: str = "cl100k_base") -> int:
|
||||
|
||||
def estimer_cout_facture(prompt: str, modele_id: str, rang_utilisateur: str = "standard", multi_ia: bool = False) -> tuple[float, float, int]:
|
||||
tokens = compter_tokens(prompt)
|
||||
cout_unitaire = TARIFS_OPENROUTER.get(modele_id, 0.0)
|
||||
tarifs = obtenir_tarifs_dynamiques()
|
||||
cout_unitaire = tarifs.get(modele_id, 0.0)
|
||||
cout_brut = tokens * cout_unitaire
|
||||
|
||||
if multi_ia and cout_brut > 0:
|
||||
@@ -144,4 +177,27 @@ def generer_dossier_litige(utilisateur_nom: str, est_admin: bool = False) -> lis
|
||||
"tokens": item.get("tokens"),
|
||||
"montant_facture_ttc": item.get("prix_facture_client")
|
||||
})
|
||||
return dossier
|
||||
return dossier
|
||||
|
||||
def calculer_prix_recharge_ttc(montant_credits_usd: float, methode: str = "paypal") -> float:
|
||||
"""
|
||||
Calcule le coût final pour l'utilisateur qui souhaite acheter une recharge de crédits.
|
||||
Le coût final répercute les frais bancaires pour que l'entreprise soit à l'équilibre.
|
||||
|
||||
Frais estimés (Variables selon devises, basés sur des profils Sandbox/Standard) :
|
||||
- PayPal : 2.9% + 0.35$ fixes par transaction
|
||||
- Revolut Business : 1.0% + 0.20$ fixes par transaction en ligne
|
||||
|
||||
Formule d'absorption des frais : Montant_Final = (Credits + Frais_Fixes) / (1 - Pourcentage_Frais)
|
||||
"""
|
||||
if methode.lower() == "paypal":
|
||||
frais_fixes = 0.35
|
||||
frais_variable = 0.029
|
||||
elif methode.lower() == "revolut":
|
||||
frais_fixes = 0.20
|
||||
frais_variable = 0.010
|
||||
else:
|
||||
return montant_credits_usd # Aucune méthode bancaire spécifiée
|
||||
|
||||
montant_a_payer = (montant_credits_usd + frais_fixes) / (1 - frais_variable)
|
||||
return round(montant_a_payer, 2)
|
||||
Reference in new issue
Block a user