refactor(config): use Vite proxy for API requests and change backend port

- Configure Vite dev server to proxy /v1 requests to backend
- Change backend port from 8000 to 8001
- Simplify API URLs to relative paths instead of absolute localhost URLs
- Increase debounce delay from 500ms to 1000ms for better stability
- Update README documentation to reflect all changes
This commit is contained in:
2026-02-15 23:23:00 +08:00
parent 1e58c18bbc
commit eb6e8bbfff
4 changed files with 16 additions and 23 deletions
+6 -4
View File
@@ -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 功能
## 许可证
+1 -1
View File
@@ -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)
+2 -17
View File
@@ -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'
+7 -1
View File
@@ -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: {