feat: TODO
This commit is contained in:
parent
9b9265b46a
commit
03ee2525ab
39
README.md
39
README.md
|
@ -2,6 +2,15 @@
|
|||
|
||||
一个高效、简洁的 RAG (Retrieval-Augmented Generation) 服务,基于 FastAPI 构建。
|
||||
|
||||
## TODO
|
||||
|
||||
- [ ] 提高检索准确度
|
||||
- [ ] 知识库隔离
|
||||
- [ ] 支持 doc
|
||||
- [ ] 支持 docx
|
||||
- [ ] 支持 excel
|
||||
- [ ] 支持 csv
|
||||
|
||||
## 功能特性
|
||||
|
||||
- 🚀 **高性能 API 服务** - 基于 FastAPI 构建
|
||||
|
@ -101,11 +110,13 @@ python run_tests.py all
|
|||
## API 接口
|
||||
|
||||
### 健康检查
|
||||
|
||||
```
|
||||
GET /api/health
|
||||
```
|
||||
|
||||
### 上传文档
|
||||
|
||||
```
|
||||
POST /api/upload
|
||||
Content-Type: multipart/form-data
|
||||
|
@ -115,6 +126,7 @@ Content-Type: multipart/form-data
|
|||
```
|
||||
|
||||
### 查询问答
|
||||
|
||||
```
|
||||
POST /api/chat
|
||||
Content-Type: application/json
|
||||
|
@ -127,6 +139,7 @@ Content-Type: application/json
|
|||
```
|
||||
|
||||
### 流式聊天问答 🆕
|
||||
|
||||
```
|
||||
POST /api/chat/stream
|
||||
Content-Type: application/json
|
||||
|
@ -145,6 +158,7 @@ Content-Type: application/json
|
|||
```
|
||||
|
||||
### 获取文档列表
|
||||
|
||||
```
|
||||
GET /api/documents
|
||||
|
||||
|
@ -286,15 +300,15 @@ stream_chat("详细解释文档的主要观点")
|
|||
```javascript
|
||||
// 流式聊天问答 - 前端实现
|
||||
async function streamChat(question) {
|
||||
const response = await fetch('/api/chat/stream', {
|
||||
method: 'POST',
|
||||
const response = await fetch("/api/chat/stream", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
question: question,
|
||||
top_k: 3
|
||||
})
|
||||
top_k: 3,
|
||||
}),
|
||||
});
|
||||
|
||||
const reader = response.body.getReader();
|
||||
|
@ -306,16 +320,16 @@ async function streamChat(question) {
|
|||
if (done) break;
|
||||
|
||||
const chunk = decoder.decode(value);
|
||||
const lines = chunk.split('\n');
|
||||
const lines = chunk.split("\n");
|
||||
|
||||
for (const line of lines) {
|
||||
if (line.startsWith('data: ')) {
|
||||
if (line.startsWith("data: ")) {
|
||||
try {
|
||||
const data = JSON.parse(line.slice(6));
|
||||
|
||||
// 显示文本内容
|
||||
if (data.content) {
|
||||
document.getElementById('chat-output').innerHTML += data.content;
|
||||
document.getElementById("chat-output").innerHTML += data.content;
|
||||
}
|
||||
|
||||
// 处理最终数据块
|
||||
|
@ -324,7 +338,7 @@ async function streamChat(question) {
|
|||
console.log(`参考来源: ${data.sources.length}个文档`);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('解析数据失败:', e);
|
||||
console.error("解析数据失败:", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -332,7 +346,7 @@ async function streamChat(question) {
|
|||
}
|
||||
|
||||
// 使用示例
|
||||
streamChat('请解释文档的主要内容');
|
||||
streamChat("请解释文档的主要内容");
|
||||
```
|
||||
|
||||
## 开发指南
|
||||
|
@ -350,6 +364,7 @@ streamChat('请解释文档的主要内容');
|
|||
### 配置文件
|
||||
|
||||
主要配置在 `config.py` 中:
|
||||
|
||||
- LLM 模型配置
|
||||
- 向量模型设置
|
||||
- 数据库路径
|
||||
|
@ -360,6 +375,7 @@ streamChat('请解释文档的主要内容');
|
|||
### 常见问题
|
||||
|
||||
1. **服务启动失败**
|
||||
|
||||
```bash
|
||||
# 检查端口是否被占用
|
||||
lsof -i :8000
|
||||
|
@ -369,11 +385,13 @@ streamChat('请解释文档的主要内容');
|
|||
```
|
||||
|
||||
2. **文档上传失败**
|
||||
|
||||
- 检查文件格式是否支持 (PDF, TXT)
|
||||
- 确认文件大小不超过限制
|
||||
- 检查磁盘空间是否充足
|
||||
|
||||
3. **查询响应慢**
|
||||
|
||||
- 检查向量数据库索引状态
|
||||
- 考虑调整 `top_k` 参数
|
||||
- 监控系统资源使用情况
|
||||
|
@ -411,6 +429,7 @@ python tests/performance_monitor.py
|
|||
## 支持
|
||||
|
||||
如有问题或建议,请:
|
||||
|
||||
1. 查看 [TESTING_README.md](TESTING_README.md) 测试文档
|
||||
2. 运行 `python run_tests.py quick` 进行快速诊断
|
||||
3. 提交 Issue 或 Pull Request
|
||||
|
|
Loading…
Reference in New Issue