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

This commit is contained in:
Antigravity committed 2026-10-07 15:30:36 +03:00
1 parent 03c692fe43
commit 3b1cb85ba2
4 files changed
+8 -5

No files matched your search

+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")
+2 -1
View File
@@ -18,6 +18,7 @@ services:
- DB_PATH=/app/data/notes.db
- OLLAMA_BASE_URL=http://ollama:11434
- OLLAMA_MODEL=qwen2.5:3b
- OLLAMA_KEEP_ALIVE=5m
depends_on:
- ollama
@@ -30,4 +31,4 @@ services:
volumes:
- ./data/ollama:/root/.ollama
environment:
- OLLAMA_KEEP_ALIVE=24h
- OLLAMA_KEEP_ALIVE=5m
+1
View File
@@ -16,3 +16,4 @@ typing-inspection==0.4.4
typing_extensions==4.16.0
uvicorn==0.53.0
pypdf>=5.0.0
pytest>=8.0.0