import os import google.generativeai as genai from modules.logger import log_event def interroger_gemini(prompt_securise): api_key = os.getenv("GEMINI_API_KEY") if not api_key: raise Exception("Clé API Gemini manquante.") client = genai.Client(api_key=api_key) modeles = ["gemini-3.1-pro-preview", "gemini-3.1-pro", "gemini-2.5-pro", "gemini-3.7-flash"] for modele in modeles: try: config = {"system_instruction": "Réponds en français et en Markdown sans code LaTeX."} resp = client.chats.create(model=modele, config=config).send_message(prompt_securise) if resp and resp.text: log_event("INFO", f"GEMINI-{modele}", "Succès de la requête.") return resp.text, "#3b82f6", "GOOGLE GEMINI", modele except Exception as e: log_event("WARNING", f"GEMINI-{modele}", f"Erreur: {e}") raise Exception("Tous les modèles Gemini ont échoué.")