This commit is contained in:
team3
2026-07-27 16:43:11 +02:00
parent 23c908534f
commit 7912eae715
14 changed files with 596 additions and 27 deletions

View File

@@ -2,6 +2,8 @@
Konfiguration oder antwortet der Provider nicht, bricht der Aufruf mit sichtbarer
Meldung ab."""
import asyncio
import httpx
import config
@@ -10,6 +12,11 @@ ZEITLIMIT = 180.0
MAX_TOKENS = 8000
API_VERSION = "2023-06-01"
# Der Provider drosselt bei vielen gleichzeitigen Anfragen
WIEDERHOLBAR = (429, 500, 502, 503, 504)
WIEDERHOLUNGEN = 4
PAUSE = 2.0
class NichtKonfiguriert(ValueError):
"""Zugangsdaten fehlen. Eigener Typ, damit die Route das nicht mit
@@ -44,11 +51,19 @@ async def frage(system: str, inhalt: str, temperatur: float = 0.0) -> str:
"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,
)
for versuch in range(WIEDERHOLUNGEN):
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 not in WIEDERHOLBAR or versuch == WIEDERHOLUNGEN - 1:
break
# Zu viele Anfragen oder Serverfehler: warten und noch einmal.
# Ohne das fielen bei großen Läufen ganze Stimmen aus — und ein
# fehlendes Urteil sah aus wie „nichts gefunden".
await asyncio.sleep(PAUSE * (2 ** versuch))
if res.status_code != 200:
raise RuntimeError(f"Provider antwortet mit HTTP {res.status_code}")
antwort = res.json()