Files
llm-in-text/backend/prompt.py
T

35 lines
904 B
Python
Raw Normal View History

import os
from typing import Tuple
def build_prompt(prefix: str, suffix: str) -> str:
"""
改进后的提示词构建函数。
使用更明确的指令来引导模型生成高质量的续写内容。
"""
MAX_CONTEXT_LINES = 30
prefix_lines = prefix.split('\n')
suffix_lines = suffix.split('\n') if suffix else []
recent_prefix = '\n'.join(prefix_lines[-MAX_CONTEXT_LINES:])
recent_suffix = '\n'.join(suffix_lines[:5])
prompt = f"""You are an expert writing assistant. Continue the text naturally.
CONTEXT:
⟨CURSOR⟩ marks where to continue.
- Before ⟨CURSOR⟩: existing text
- After ⟨CURSOR⟩: following context (if any)
RULES:
- Match existing style, tone, and terminology
- Maintain logical flow
- Write only the continuation, nothing else
TEXT:
{recent_prefix}⟨CURSOR⟩{recent_suffix}
CONTINUATION:"""
return prompt.strip()