fix(ai): configure OLLAMA_KEEP_ALIVE=5m to automatically release RAM after inactivity

This commit is contained in:
2026-10-07 15:30:36 +03:00
parent 03c692fe43
commit 3b1cb85ba2
4 changed files with 8 additions and 5 deletions
+4 -4
View File
@@ -251,7 +251,7 @@ async def translate_sentence_ai(
"prompt": prompt,
"stream": False,
"format": "json",
"keep_alive": "24h",
"keep_alive": config.OLLAMA_KEEP_ALIVE,
"options": {
"temperature": 0.2,
"num_predict": 300,
@@ -367,10 +367,10 @@ async def warmup_ollama_model() -> bool:
client = get_ollama_client()
resp = await client.post(
f"{config.OLLAMA_BASE_URL}/api/generate",
json={"model": config.OLLAMA_MODEL, "keep_alive": "24h"},
json={"model": config.OLLAMA_MODEL, "keep_alive": config.OLLAMA_KEEP_ALIVE},
)
if resp.status_code == 200:
logger.info(f"Ollama model '{config.OLLAMA_MODEL}' warmed up successfully (keep_alive=24h).")
logger.info(f"Ollama model '{config.OLLAMA_MODEL}' warmed up successfully (keep_alive={config.OLLAMA_KEEP_ALIVE}).")
return True
else:
logger.warning(f"Ollama warmup returned HTTP {resp.status_code}: {resp.text}")
@@ -567,7 +567,7 @@ async def generate_lesson_ai_debrief(
"prompt": prompt,
"stream": False,
"format": "json",
"keep_alive": "24h",
"keep_alive": config.OLLAMA_KEEP_ALIVE,
"options": {
"temperature": 0.3,
"num_predict": 450,
+1
View File
@@ -43,4 +43,5 @@ DB_PATH.parent.mkdir(parents=True, exist_ok=True)
OLLAMA_BASE_URL = os.getenv("OLLAMA_BASE_URL", "http://127.0.0.1:11434").rstrip("/")
OLLAMA_MODEL = os.getenv("OLLAMA_MODEL", "qwen2.5:3b")
OLLAMA_KEEP_ALIVE = os.getenv("OLLAMA_KEEP_ALIVE", "5m")