diff --git a/README.md b/README.md index b3e8097..4000e01 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,8 @@ llm-in-text/ │ │ └── index.ts # 插件导出 │ ├── utils/ │ │ ├── api.js # API 调用封装 -│ │ └── config.js # 配置文件 +│ │ ├── config.js # 配置文件 +│ │ └── ocrCache.js # OCR 缓存管理 │ ├── App.vue │ └── main.js ├── backend/ @@ -189,7 +190,7 @@ export const copilotGhostMark = $markSchema('copilot_ghost', () => ({ flowchart LR A[用户输入] --> B{文档变化?} B -->|是| C[清除旧建议] - C --> D[防抖 500ms] + C --> D[防抖 1000ms] D --> E[发送 API 请求] E --> F[收到建议] F --> G[插入 Ghost Text] @@ -225,7 +226,7 @@ sequenceDiagram U->>E: 输入文本 E->>P: view.update() P->>P: 清除旧建议 - P->>P: 防抖 500ms + P->>P: 防抖 1000ms P->>A: fetchSuggestion(prefix, suffix) A->>B: POST /v1/completions B->>B: build_prompt() @@ -254,9 +255,10 @@ sequenceDiagram ## 设计亮点 1. **前后端分离**:前端只负责渲染和数据回传,后端负责 LLM 调用、Prompt 构建和数据解析 -2. **低延迟优化**:防抖机制 (500ms) + SSE 流式响应 + AbortController 取消过期请求 +2. **低延迟优化**:防抖机制 (1000ms) + SSE 流式响应 + AbortController 取消过期请求 3. **ProseMirror Mark 系统**:与编辑器状态完美集成,支持 Undo/Redo 4. **多种交互方式**:Tab/Esc/点击/输入,用户体验友好 +5. **智能大小限制**:文档超过 32KB 自动禁用 AI 功能 ## 许可证 diff --git a/backend/main.py b/backend/main.py index 9f422c6..c8415c8 100644 --- a/backend/main.py +++ b/backend/main.py @@ -109,4 +109,4 @@ async def ocr_image(request: OCRRequest): if __name__ == "__main__": import uvicorn - uvicorn.run(app, host="0.0.0.0", port=8000) + uvicorn.run(app, host="0.0.0.0", port=8001) diff --git a/src/utils/config.js b/src/utils/config.js index d216c9f..cc817e5 100644 --- a/src/utils/config.js +++ b/src/utils/config.js @@ -1,18 +1,3 @@ export const DEBUG = import.meta.env.DEV -export const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:8000/v1/completions' - -const buildDefaultOcrUrl = (apiUrl) => { - if (typeof window === 'undefined') { - return 'http://localhost:8000/v1/ocr' - } - - try { - const url = new URL(apiUrl, window.location.origin) - url.pathname = '/v1/ocr' - return url.toString() - } catch { - return 'http://localhost:8000/v1/ocr' - } -} - -export const OCR_URL = import.meta.env.VITE_OCR_URL || buildDefaultOcrUrl(API_URL) +export const API_URL = import.meta.env.VITE_API_URL || '/v1/completions' +export const OCR_URL = import.meta.env.VITE_OCR_URL || '/v1/ocr' diff --git a/vite.config.js b/vite.config.js index 526c009..35f6eb8 100644 --- a/vite.config.js +++ b/vite.config.js @@ -5,7 +5,13 @@ export default defineConfig({ plugins: [vue()], server: { host: true, - port: 5173 + port: 5173, + proxy: { + '/v1': { + target: 'http://localhost:8001', + changeOrigin: true + } + } }, build: { rollupOptions: {