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()