fix(ai): configure OLLAMA_KEEP_ALIVE=5m to automatically release RAM after inactivity
This commit is contained in:
@@ -251,7 +251,7 @@ async def translate_sentence_ai(
|
|||||||
"prompt": prompt,
|
"prompt": prompt,
|
||||||
"stream": False,
|
"stream": False,
|
||||||
"format": "json",
|
"format": "json",
|
||||||
"keep_alive": "24h",
|
"keep_alive": config.OLLAMA_KEEP_ALIVE,
|
||||||
"options": {
|
"options": {
|
||||||
"temperature": 0.2,
|
"temperature": 0.2,
|
||||||
"num_predict": 300,
|
"num_predict": 300,
|
||||||
@@ -367,10 +367,10 @@ async def warmup_ollama_model() -> bool:
|
|||||||
client = get_ollama_client()
|
client = get_ollama_client()
|
||||||
resp = await client.post(
|
resp = await client.post(
|
||||||
f"{config.OLLAMA_BASE_URL}/api/generate",
|
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:
|
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
|
return True
|
||||||
else:
|
else:
|
||||||
logger.warning(f"Ollama warmup returned HTTP {resp.status_code}: {resp.text}")
|
logger.warning(f"Ollama warmup returned HTTP {resp.status_code}: {resp.text}")
|
||||||
@@ -567,7 +567,7 @@ async def generate_lesson_ai_debrief(
|
|||||||
"prompt": prompt,
|
"prompt": prompt,
|
||||||
"stream": False,
|
"stream": False,
|
||||||
"format": "json",
|
"format": "json",
|
||||||
"keep_alive": "24h",
|
"keep_alive": config.OLLAMA_KEEP_ALIVE,
|
||||||
"options": {
|
"options": {
|
||||||
"temperature": 0.3,
|
"temperature": 0.3,
|
||||||
"num_predict": 450,
|
"num_predict": 450,
|
||||||
|
|||||||
@@ -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_BASE_URL = os.getenv("OLLAMA_BASE_URL", "http://127.0.0.1:11434").rstrip("/")
|
||||||
OLLAMA_MODEL = os.getenv("OLLAMA_MODEL", "qwen2.5:3b")
|
OLLAMA_MODEL = os.getenv("OLLAMA_MODEL", "qwen2.5:3b")
|
||||||
|
OLLAMA_KEEP_ALIVE = os.getenv("OLLAMA_KEEP_ALIVE", "5m")
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -18,6 +18,7 @@ services:
|
|||||||
- DB_PATH=/app/data/notes.db
|
- DB_PATH=/app/data/notes.db
|
||||||
- OLLAMA_BASE_URL=http://ollama:11434
|
- OLLAMA_BASE_URL=http://ollama:11434
|
||||||
- OLLAMA_MODEL=qwen2.5:3b
|
- OLLAMA_MODEL=qwen2.5:3b
|
||||||
|
- OLLAMA_KEEP_ALIVE=5m
|
||||||
depends_on:
|
depends_on:
|
||||||
- ollama
|
- ollama
|
||||||
|
|
||||||
@@ -30,4 +31,4 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./data/ollama:/root/.ollama
|
- ./data/ollama:/root/.ollama
|
||||||
environment:
|
environment:
|
||||||
- OLLAMA_KEEP_ALIVE=24h
|
- OLLAMA_KEEP_ALIVE=5m
|
||||||
|
|||||||
@@ -16,3 +16,4 @@ typing-inspection==0.4.4
|
|||||||
typing_extensions==4.16.0
|
typing_extensions==4.16.0
|
||||||
uvicorn==0.53.0
|
uvicorn==0.53.0
|
||||||
pypdf>=5.0.0
|
pypdf>=5.0.0
|
||||||
|
pytest>=8.0.0
|
||||||
|
|||||||
Reference in New Issue
Block a user