Files
llm-in-text/backend/prompt.py
“ydy0615” 65d4a57d33 refactor(editor): migrate to ProseMirror Mark-based ghost text system
- Replace overlay-based GhostTextOverlay.vue with ProseMirror Mark system
- Add AI toggle button with enable/disable functionality
- Implement new copilotPlugin.ts using copilotGhostMark for inline suggestions
- Fix cursor position offset in prompt.py by moving first suffix char to prefix
- Improve API error handling with abort signal support and debug logging
- Update model configuration from gpt-oss:120b to gpt-oss:20b
- Add button tooltips and improve editor styling
- Remove deprecated inlineSuggestionPlugin.ts
- Update README with new architecture diagram and feature documentation
2026-02-13 09:24:50 +08:00

42 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
from typing import Tuple
def build_prompt(prefix: str, suffix: str) -> str:
"""
改进后的提示词构建函数。
使用更明确的指令来引导模型生成高质量的续写内容。
"""
MAX_CONTEXT_LINES = 30
# 修正把suffix的第一个字符移到prefix末尾解决光标位置偏差
if suffix:
first_char = suffix[0]
prefix = prefix + first_char
suffix = suffix[1:]
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
- IMPORTANT: Start continuation directly from ⟨CURSOR⟩ position
TEXT:
{recent_prefix}⟨CURSOR⟩{recent_suffix}
CONTINUATION:"""
return prompt.strip()