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:
+4
-3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user