feat: implement inline autocomplete suggestions with FastAPI backend and Milkdown editor integration

This commit is contained in:
2026-01-18 19:42:58 +08:00
parent ba49f82953
commit 6102f905ee
10 changed files with 633 additions and 52 deletions
+28
View File
@@ -0,0 +1,28 @@
import os
from typing import Tuple
def build_prompt(prefix: str, suffix: str) -> str:
"""
构建用于代码补全的 Prompt。
参考 completions-sample-code 的 extractPrompt 逻辑简化实现。
"""
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 a helpful writing assistant. Continue the text naturally based on the context.
Context (before cursor):
{recent_prefix}
Complete this:
{suffix if suffix else '(cursor here)'}
Continue:"""
return prompt.strip()