The workspace now carries the pro editing flow, streaming completion path, and lighter Office preview state as one checkpoint so the remote has the current runnable project shape. Constraint: Preserve the current workspace as a single reviewable project commit while excluding local agent state and verification artifacts. Removed stale Univer runtime dependencies from the lockfile so installs match package.json. Rejected: Commit runtime screenshots, .omx state, and coverage files | they are local artifacts rather than source state. Confidence: medium Scope-risk: broad Directive: Keep package.json and package-lock.json synchronized when changing frontend dependencies. Tested: npm run build; C:\Users\ydy\.conda\envs\llmwebsite\python.exe -m pytest backend/tests/test_main_endpoints.py backend/tests/test_main_cancel.py backend/tests/test_llm.py backend/tests/test_llm_extended.py -v -o addopts= (44 passed). Not-tested: Full pytest with repository coverage addopts currently reports 0% coverage because pytest-cov watches backend.* module names while tests import top-level backend modules. Co-authored-by: OmX <omx@oh-my-codex.dev>
LLM in Text - 智能写作助手
基于 Vue3 和 FastAPI 的智能 Markdown 编辑器,集成大语言模型(LLM)实时补全建议功能。
功能特性
Markdown 编辑器
- 基于 Milkdown Crepe 的所见即所得编辑体验
- 支持 Markdown 语法和 LaTeX 公式
- 支持 Mermaid 图表渲染
- 导入/导出 Markdown 文件
- 导出 DOCX 和 PDF 格式
AI 智能补全
- 实时生成文本补全建议(灰色显示)
- 流式响应,低延迟体验
- 多种交互方式:Tab接受、Esc拒绝、点击接受
文档处理
- OCR 图片识别:上传图片自动识别文字
- 文档转换:PDF、DOCX、PPTX、TXT 转 Markdown
- 文档块嵌入:可折叠的文档预览块
- 智能大小限制:32KB自动禁用AI
设置面板
- 外观主题:亮色/暗色/跟随系统
- 背景模式:默认/暖色/阅读灯/自定义图片
- 模型智能:低/中/高思考级别
- 隐私控制:隐私模式防止发送IP
- 多语言界面:中英日韩德法
语音功能
- TTS文字转语音(macOS优化,支持Apple Silicon M1/M2/M3)
- STT语音转文字(支持多种模型大小和量化)
- 自动设备检测(MPS/CUDA/CPU智能切换)
- 离线模式支持(模型缓存检查)
技术架构
前端: Vue3 + Vite + Milkdown + ProseMirror 后端: FastAPI + Python + Ollama
快速开始
环境: Node.js 18+、Python 3.8+、Ollama
安装:
- 前端: npm install
- 后端: pip install -r backend/requirements.txt
启动:
- 后端: python backend/main.py (端口8001)
- 前端: npm run dev (端口5173)
API接口
- POST /v1/completions 流式补全建议
- POST /v1/ocr 图片文字识别
- POST /v1/convert 文档转换
- POST /v1/completions/cancel 取消请求
- GET /v1/tts-asr/status TTS/ASR模型状态
- GET /v1/tts-asr/config TTS/ASR配置信息
- POST /v1/tts-asr/warmup 模型预热
- POST /v1/tts-asr/tts 文字转语音
- POST /v1/tts-asr/asr 语音转文字
TTS/ASR环境变量配置
支持以下环境变量来配置TTS/ASR模块:
| 变量名 | 说明 | 默认值 |
|---|---|---|
TTS_ASR_DEVICE |
设备选择 (auto/mps/cuda/cpu) | auto |
TTS_ASR_MODEL_SIZE |
ASR模型大小 (tiny/base/small/medium/large/turbo) | auto |
TTS_ASR_QUANTIZE |
是否使用INT8量化 (true/false) | false |
TTS_ASR_OFFLINE_MODE |
离线模式,仅使用缓存模型 (true/false) | false |
TTS_ASR_WARMUP |
启动时预热模型 (true/false) | true |
TTS_ASR_WARMUP_TIMEOUT |
预热超时时间(秒) | 120 |
TTS_ASR_IDLE_TIMEOUT |
空闲卸载时间(秒,0=不卸载) | 0 |
TTS_ASR_MPS_MEMORY_LIMIT_MB |
MPS内存限制(MB) | 8192 |
Apple Silicon优化建议:
- 系统自动检测Apple Silicon并推荐使用
small模型 - MPS内存限制默认为系统内存的60%
- 建议使用
small或medium模型以获得更好的性能 - 可通过
TTS_ASR_MODEL_SIZE=medium手动指定模型大小
核心实现
后端
- main.py: FastAPI服务器、SSE流式响应
- llm.py: 异步Ollama调用、超时控制
- prompt.py: 7条Prompt规则
- tts_asr.py: macOS/Apple Silicon优化的TTS/ASR处理
- 自动检测Apple Silicon (M1/M2/M3)
- MPS/CUDA/CPU智能降级
- 支持多种Whisper模型大小
- INT8量化支持
- 离线模式支持
- 健壮的音频重采样
前端
- copilotPlugin.ts: ProseMirror Mark系统
- 关键函数: scheduleFetch、insertGhostText
- Pinia Store状态管理
设计亮点
- 前后端分离
- 低延迟优化:防抖+SSE+AbortController
- ProseMirror Mark系统
- 多种交互方式
- 智能大小限制
- 隐私保护
- 多语言支持
- 主题定制
- 文档处理
- 语音功能
开发指南
代码风格: Python(4空格,snake_case) JS/TS(2空格,camelCase) 测试: pytest 构建: npm run build
运行测试
项目提供完整的测试套件,包括单元测试、集成测试和macOS环境模拟测试:
# 快速运行单元测试
python backend/tests/run_tests.py unit
# 运行集成测试(需要启动后端服务)
python backend/tests/run_tests.py integration
# 运行macOS环境模拟测试(在非Mac环境测试)
python backend/tests/run_tests.py simulate
# 运行所有测试
python backend/tests/run_tests.py all
详细测试说明请参考: 测试指南
许可证
MIT License
Languages
Vue
37.9%
Python
26.6%
JavaScript
16.7%
TypeScript
14.4%
CSS
2.7%
Other
1.7%