"""Anbindung an MiniMax über das Anthropic-Messages-Format. Kein Fallback: fehlt die Konfiguration oder antwortet der Provider nicht, bricht der Aufruf mit sichtbarer Meldung ab.""" import httpx import config ZEITLIMIT = 180.0 MAX_TOKENS = 8000 API_VERSION = "2023-06-01" def pruefe_konfiguration(): fehlend = [ name for name, wert in ( ("MINIMAX_API_KEY", config.MINIMAX_API_KEY), ("MINIMAX_MODELL", config.MINIMAX_MODELL), ("MINIMAX_URL", config.MINIMAX_URL), ) if not wert ] if fehlend: raise ValueError(f"Nicht konfiguriert: {', '.join(fehlend)} in .env fehlt") async def frage(system: str, inhalt: str) -> str: """Eine Anfrage, eine Antwort — der Text der Modellantwort. Kalt geroutet: niedrige Temperatur, kein Thinking; die Prüfung soll nicht raten.""" pruefe_konfiguration() daten = { "model": config.MINIMAX_MODELL, "max_tokens": MAX_TOKENS, "system": system, "messages": [{"role": "user", "content": inhalt}], "temperature": 0.2, "thinking": {"type": "disabled"}, } async with httpx.AsyncClient(timeout=httpx.Timeout(ZEITLIMIT, connect=30)) as client: res = await client.post( config.MINIMAX_URL, headers={"x-api-key": config.MINIMAX_API_KEY, "anthropic-version": API_VERSION}, json=daten, ) if res.status_code != 200: raise RuntimeError(f"Provider antwortet mit HTTP {res.status_code}") antwort = res.json() text = "".join( b.get("text", "") for b in antwort.get("content", []) if b.get("type") == "text" ) if not text.strip(): raise RuntimeError(f"Leere Antwort (stop_reason={antwort.get('stop_reason')})") return text