Files
X-Agents/algorithm
DESKTOP-72TV0V4\caoxiaozhu 3a1d9ed676 feat: 添加算法目录和知识库 API 文档
- 新增 algorithm/ 目录
- 添加知识库 API 需求文档
- 添加相关截图

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 20:34:41 +08:00
..

Algorithm Service

Python 算法服务提供文档解析、Embedding、LLM 调用等功能。

环境要求

  • Python 3.9+
  • FastAPI
  • Uvicorn

安装依赖

pip install -r requirements.txt

运行服务

# 开发模式
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

响应

{
  "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 模型名称

响应

{
  "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 温度参数

响应

{
  "success": true,
  "message": {
    "role": "assistant",
    "content": "回复内容..."
  },
  "usage": {
    "prompt_tokens": 100,
    "completion_tokens": 50
  }
}