feat: switch from OpenAI API to native Ollama Python client
This commit refactors the LLM integration to use Ollama's native Python client instead of OpenAI-compatible API, while fixing critical template syntax errors and improving project structure. Key changes: - Replace openai package with ollama package in backend requirements - Rewrite llm.py to use ollama.AsyncClient for direct Ollama API calls - Update main.py to use non-streaming Ollama responses with thinking extraction - Fix template syntax error in MilkdownEditor.vue (GhostTextOverlay component tags) - Fix string截取错误 by using slice() instead of substring() - Add src/utils/api.js and src/utils/config.js for shared configuration - Add CORS middleware to FastAPI backend - Update prompt.py with clearer instructions for continuation generation - Add comprehensive README.md documentation BREAKING CHANGE: Environment variables OLLAMA_BASE_URL changed to OLLAMA_HOST (remove /v1/ suffix)
This commit is contained in:
+15
-9
@@ -3,8 +3,8 @@ from typing import Tuple
|
||||
|
||||
def build_prompt(prefix: str, suffix: str) -> str:
|
||||
"""
|
||||
构建用于代码补全的 Prompt。
|
||||
参考 completions-sample-code 的 extractPrompt 逻辑简化实现。
|
||||
改进后的提示词构建函数。
|
||||
使用更明确的指令来引导模型生成高质量的续写内容。
|
||||
"""
|
||||
MAX_CONTEXT_LINES = 30
|
||||
|
||||
@@ -14,15 +14,21 @@ def build_prompt(prefix: str, suffix: str) -> str:
|
||||
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.
|
||||
prompt = f"""You are an expert writing assistant. Continue the text naturally.
|
||||
|
||||
Context (before cursor):
|
||||
{recent_prefix}
|
||||
CONTEXT:
|
||||
⟨CURSOR⟩ marks where to continue.
|
||||
- Before ⟨CURSOR⟩: existing text
|
||||
- After ⟨CURSOR⟩: following context (if any)
|
||||
|
||||
Complete this:
|
||||
{suffix if suffix else '(cursor here)'}
|
||||
RULES:
|
||||
- Match existing style, tone, and terminology
|
||||
- Maintain logical flow
|
||||
- Write only the continuation, nothing else
|
||||
|
||||
Continue:"""
|
||||
TEXT:
|
||||
{recent_prefix}⟨CURSOR⟩{recent_suffix}
|
||||
|
||||
CONTINUATION:"""
|
||||
|
||||
return prompt.strip()
|
||||
|
||||
Reference in New Issue
Block a user