Warm up local LLM before live corrections
This commit is contained in:
@@ -43,8 +43,34 @@ def run_llm_processor(in_queue, out_queue, args):
|
||||
print(f"[LLM] Ollama health check failed ({exc}). Local LLM features may fall back.")
|
||||
return False
|
||||
|
||||
def warmup_ollama_model():
|
||||
try:
|
||||
response = requests.post(
|
||||
getattr(args, "post_correct_ollama_url", "http://127.0.0.1:11434/api/generate"),
|
||||
json={
|
||||
"model": args.post_correct_model,
|
||||
"prompt": "Return exactly: ok",
|
||||
"stream": False,
|
||||
"options": {"temperature": 0.0},
|
||||
"keep_alive": getattr(args, "post_correct_keep_alive", "30m"),
|
||||
},
|
||||
timeout=getattr(args, "post_correct_warmup_timeout", 20.0),
|
||||
)
|
||||
response.raise_for_status()
|
||||
body = response.json()
|
||||
if body.get("response", "").strip():
|
||||
total_s = body.get("total_duration", 0) / 1_000_000_000
|
||||
load_s = body.get("load_duration", 0) / 1_000_000_000
|
||||
print(f"[LLM] Ollama warmup OK for {args.post_correct_model} (load={load_s:.2f}s total={total_s:.2f}s).")
|
||||
return True
|
||||
except Exception as exc:
|
||||
print(f"[LLM] Ollama warmup failed for {args.post_correct_model} ({exc}).")
|
||||
return False
|
||||
|
||||
if not is_openai:
|
||||
check_ollama_health()
|
||||
if getattr(args, "post_correct_llm", False) or getattr(args, "llm_paragraph", False):
|
||||
warmup_ollama_model()
|
||||
|
||||
def normalize_english_caption(text):
|
||||
normalized = " ".join((text or "").split()).strip()
|
||||
|
||||
Reference in New Issue
Block a user