feat(api): add system prompt support for LLM completion

Separate prompt generation into system and user prompts for better LLM instruction following. Backend now builds a detailed system prompt with constraints for math formatting, code block handling, boundary newlines, and OCR safety, while user prompt contains context and completion state flags. Added corresponding tests for both modules.
This commit is contained in:
2026-02-23 15:17:36 +08:00
parent ce0731c2f2
commit e28125079c
7 changed files with 649 additions and 118 deletions
+4 -3
View File
@@ -8,7 +8,7 @@ import base64
import uuid
import logging
from prompt import build_prompt, prepare_prompt_context
from prompt import build_completion_prompts, prepare_prompt_context
from llm import call_ollama, call_vlm_ocr
from geoip import get_ip_location_text
@@ -98,7 +98,7 @@ async def create_completion(request: Request, req: CompletionRequest, api_key: s
logger.info("[%s] llm_input_prefix=%r", request_id, llm_prefix)
logger.info("[%s] llm_input_suffix=%r", request_id, llm_suffix)
prompt = build_prompt(
system_prompt, user_prompt = build_completion_prompts(
req.prefix,
req.suffix,
req.languageId,
@@ -107,7 +107,8 @@ async def create_completion(request: Request, req: CompletionRequest, api_key: s
preferences=req.user_preferences
)
result = await call_ollama(
prompt,
user_prompt,
system_prompt=system_prompt,
tag=f"{request_id}-primary",
temperature=0.7,
thinking=req.model_thinking if req.model_thinking != "none" else None