Align Ollama system prompts with OpenAI
This commit is contained in:
+10
-2
@@ -51,6 +51,7 @@ def run_llm_processor(in_queue, out_queue, args):
|
|||||||
json={
|
json={
|
||||||
"model": args.post_correct_model,
|
"model": args.post_correct_model,
|
||||||
"prompt": "Return exactly: ok",
|
"prompt": "Return exactly: ok",
|
||||||
|
"system": "You are a concise assistant.",
|
||||||
"stream": False,
|
"stream": False,
|
||||||
"options": {"temperature": 0.0},
|
"options": {"temperature": 0.0},
|
||||||
"keep_alive": getattr(args, "post_correct_keep_alive", "30m"),
|
"keep_alive": getattr(args, "post_correct_keep_alive", "30m"),
|
||||||
@@ -112,12 +113,13 @@ def run_llm_processor(in_queue, out_queue, args):
|
|||||||
raise RuntimeError(f"OpenAI API error {response.status_code}: {detail}")
|
raise RuntimeError(f"OpenAI API error {response.status_code}: {detail}")
|
||||||
return response.json()["choices"][0]["message"]["content"].strip()
|
return response.json()["choices"][0]["message"]["content"].strip()
|
||||||
|
|
||||||
def call_ollama(prompt, temperature):
|
def call_ollama(prompt, temperature, system=None):
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
getattr(args, "post_correct_ollama_url", "http://127.0.0.1:11434/api/generate"),
|
getattr(args, "post_correct_ollama_url", "http://127.0.0.1:11434/api/generate"),
|
||||||
json={
|
json={
|
||||||
"model": args.post_correct_model,
|
"model": args.post_correct_model,
|
||||||
"prompt": prompt,
|
"prompt": prompt,
|
||||||
|
"system": system or "",
|
||||||
"stream": False,
|
"stream": False,
|
||||||
"options": {"temperature": temperature},
|
"options": {"temperature": temperature},
|
||||||
"keep_alive": getattr(args, "post_correct_keep_alive", "30m"),
|
"keep_alive": getattr(args, "post_correct_keep_alive", "30m"),
|
||||||
@@ -133,7 +135,13 @@ def run_llm_processor(in_queue, out_queue, args):
|
|||||||
if not api_key:
|
if not api_key:
|
||||||
raise RuntimeError("OPENAI_API_KEY is not set")
|
raise RuntimeError("OPENAI_API_KEY is not set")
|
||||||
return call_openai(messages)
|
return call_openai(messages)
|
||||||
return call_ollama(prompt, temperature)
|
system = ""
|
||||||
|
if messages:
|
||||||
|
for message in messages:
|
||||||
|
if message.get("role") == "system":
|
||||||
|
system = message.get("content", "")
|
||||||
|
break
|
||||||
|
return call_ollama(prompt, temperature, system=system)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
if not llm_state[warn_key]:
|
if not llm_state[warn_key]:
|
||||||
label = "Paragraph LLM" if warn_key == "paragraph_warned" else "Line LLM"
|
label = "Paragraph LLM" if warn_key == "paragraph_warned" else "Line LLM"
|
||||||
|
|||||||
Reference in New Issue
Block a user