Files
llm-in-text/AGENTS.md
ydy0615 d8b7832b14 refactor: improve codebase structure and Univer integration
- Add AGENTS.md knowledge base with project documentation
- Move UserPreferences model to separate models.py file
- Extract API_KEY to environment variable for security
- Enhance Univer Editor with PPTX support and improved UI
- Improve file system handling with binary file detection
- Add HF_ENDPOINT mirror for better China connectivity
- Clean up unused imports and code structure
2026-04-11 09:24:14 +08:00

3.4 KiB
Raw Blame History

LLM in Text 项目知识库

生成时间: 2025-04-10 Commit: 2fdc996 Branch: main

概述

智能 Markdown 编辑器,集成 LLM 实时补全建议。前端 Vue3 + Vite + Milkdown后端 FastAPI + Python + Ollama。核心功能AI 补全、OCR 图片识别、文档转换、TTS/ASR 语音功能。

结构

llm-in-text/
├── backend/           # FastAPI 后端 (Python)
│   ├── main.py        # API 入口,路由定义
│   ├── llm.py         # Ollama 调用封装
│   ├── prompt.py      # Prompt 构建逻辑
│   ├── prompts/       # JSON 格式的提示模板
│   └── tests/         # pytest 测试套件
├── src/               # 前端源码 (Vue3 + Vite)
│   ├── main.js        # Vue 入口
│   ├── App.vue        # 根组件
│   ├── components/    # Vue 组件
│   ├── plugins/       # Milkdown/Copilot 插件
│   ├── stores/        # Pinia 状态管理
│   ├── views/         # 页面视图
│   └── utils/         # 工具函数
├── public/            # 静态资源
├── milkdown-docs/     # Milkdown 官方文档(只读)
└── index.html         # HTML 入口

查找指南

任务 位置 说明
后端 API 入口 backend/main.py FastAPI 路由、CORS、启动逻辑
LLM 调用 backend/llm.py Ollama 异步调用、超时控制
Prompt 构建 backend/prompt.py 系统提示、上下文准备
AI 补全核心 src/plugins/copilotPlugin.ts ProseMirror Mark、ghost text
编辑器组件 src/components/MilkdownEditor.vue Milkdown 编辑器封装
状态管理 src/stores/settings.js 用户设置、主题、偏好
API 调用 src/utils/api.js fetchSuggestion、TTS 接口
测试运行 pytest.ini + backend/tests/ 测试配置与用例

约定(项目特定)

  • 前端入口src/main.js(非 TypeScript使用 Vue3 + Pinia + Vue Router
  • 后端入口backend/main.py,端口 8001uvicorn 启动
  • 代理配置:开发时 /v1 代理到远程 API生产需调整
  • 文件命名:全小写+短横线(my-module.pymy-component.vue
  • 语言UI 默认中文,响应必须使用中文

反模式(本项目禁止)

  • 硬编码 API_KEY必须从环境变量读取
  • 在前端暴露密钥(应通过后端代理)
  • npm run dev 运行网页(无法看到内容)
  • 修改 milkdown-docs/ 目录
  • 类型错误使用 as any / @ts-ignore
  • 空的 catch 块

命令

# 前端开发
npm install
npm run dev          # 端口 5173
npm run build        # 构建到 dist/

# 后端运行
pip install -r backend/requirements.txt
python backend/main.py    # 端口 8001
# 或
uvicorn backend.main:app --reload --port 8001

# 测试
pytest               # 运行所有测试,覆盖率要求 90%
python backend/tests/run_tests.py unit      # 单元测试
python backend/tests/run_tests.py integration  # 集成测试

注意事项

  • 架构分离:前端仅渲染和数据回传,后端负责 LLM API 调用和数据解析
  • 延迟优先:代码效率优先,降低延迟放在第一位
  • 大小限制:文档超过 32KB 自动禁用 AI 补全
  • milkdown-docs/:官方文档参考,不可修改,编辑器相关问题需核对此目录