feat: 添加算法目录和知识库 API 文档
- 新增 algorithm/ 目录 - 添加知识库 API 需求文档 - 添加相关截图 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
112
algorithm/README.md
Normal file
112
algorithm/README.md
Normal file
@@ -0,0 +1,112 @@
|
||||
# Algorithm Service
|
||||
|
||||
Python 算法服务,提供文档解析、Embedding、LLM 调用等功能。
|
||||
|
||||
## 环境要求
|
||||
|
||||
- Python 3.9+
|
||||
- FastAPI
|
||||
- Uvicorn
|
||||
|
||||
## 安装依赖
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
## 运行服务
|
||||
|
||||
```bash
|
||||
# 开发模式
|
||||
uvicorn main:app --reload --port 8081
|
||||
|
||||
# 生产模式
|
||||
uvicorn main:app --host 0.0.0.0 --port 8081
|
||||
```
|
||||
|
||||
## 接口列表
|
||||
|
||||
### 1. 文档解析
|
||||
|
||||
**请求**
|
||||
|
||||
```
|
||||
POST /parse
|
||||
Content-Type: application/json
|
||||
```
|
||||
|
||||
| 参数 | 类型 | 必填 | 说明 |
|
||||
|------|------|------|------|
|
||||
| file_url | String | 是 | 文件 URL |
|
||||
| engine | String | 是 | 解析引擎:markitdown / docling |
|
||||
| docling_url | String | 否 | Docling 服务 URL |
|
||||
|
||||
**响应**
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"content": "解析后的文本内容...",
|
||||
"chunks": ["chunk1", "chunk2"],
|
||||
"total_pages": 10,
|
||||
"metadata": {
|
||||
"filename": "document.pdf",
|
||||
"file_size": 1234567
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 生成 Embedding
|
||||
|
||||
**请求**
|
||||
|
||||
```
|
||||
POST /embedding
|
||||
Content-Type: application/json
|
||||
```
|
||||
|
||||
| 参数 | 类型 | 必填 | 说明 |
|
||||
|------|------|------|------|
|
||||
| input | String/Array | 是 | 要 embedding 的文本 |
|
||||
| model | String | 是 | 模型名称 |
|
||||
|
||||
**响应**
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"embeddings": [[0.1, 0.2, ...], [0.3, 0.4, ...]],
|
||||
"model": "text-embedding-3-small"
|
||||
}
|
||||
```
|
||||
|
||||
### 3. LLM 对话
|
||||
|
||||
**请求**
|
||||
|
||||
```
|
||||
POST /chat
|
||||
Content-Type: application/json
|
||||
```
|
||||
|
||||
| 参数 | 类型 | 必填 | 说明 |
|
||||
|------|------|------|------|
|
||||
| messages | Array | 是 | 消息列表 |
|
||||
| model | String | 是 | 模型名称 |
|
||||
| temperature | Float | 否 | 温度参数 |
|
||||
|
||||
**响应**
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"message": {
|
||||
"role": "assistant",
|
||||
"content": "回复内容..."
|
||||
},
|
||||
"usage": {
|
||||
"prompt_tokens": 100,
|
||||
"completion_tokens": 50
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user