- 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
42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
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()
|