2026-01-18 19:42:58 +08:00
|
|
|
import os
|
|
|
|
|
from typing import Tuple
|
|
|
|
|
|
|
|
|
|
def build_prompt(prefix: str, suffix: str) -> str:
|
|
|
|
|
"""
|
2026-02-07 08:53:37 +08:00
|
|
|
改进后的提示词构建函数。
|
|
|
|
|
使用更明确的指令来引导模型生成高质量的续写内容。
|
2026-01-18 19:42:58 +08:00
|
|
|
"""
|
|
|
|
|
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])
|
|
|
|
|
|
2026-02-07 08:53:37 +08:00
|
|
|
prompt = f"""You are an expert writing assistant. Continue the text naturally.
|
2026-01-18 19:42:58 +08:00
|
|
|
|
2026-02-07 08:53:37 +08:00
|
|
|
CONTEXT:
|
|
|
|
|
⟨CURSOR⟩ marks where to continue.
|
|
|
|
|
- Before ⟨CURSOR⟩: existing text
|
|
|
|
|
- After ⟨CURSOR⟩: following context (if any)
|
2026-01-18 19:42:58 +08:00
|
|
|
|
2026-02-07 08:53:37 +08:00
|
|
|
RULES:
|
|
|
|
|
- Match existing style, tone, and terminology
|
|
|
|
|
- Maintain logical flow
|
|
|
|
|
- Write only the continuation, nothing else
|
2026-01-18 19:42:58 +08:00
|
|
|
|
2026-02-07 08:53:37 +08:00
|
|
|
TEXT:
|
|
|
|
|
{recent_prefix}⟨CURSOR⟩{recent_suffix}
|
|
|
|
|
|
|
|
|
|
CONTINUATION:"""
|
2026-01-18 19:42:58 +08:00
|
|
|
|
|
|
|
|
return prompt.strip()
|