No Description

jihuaqiang 04e9c185b7 1 1 week ago
indentify 977592a99f fix 1 week ago
prompt aca6c2c5d0 init 1 week ago
structure aca6c2c5d0 init 1 week ago
utils cf72f98115 1 1 week ago
.DS_Store aca6c2c5d0 init 1 week ago
.env 977592a99f fix 1 week ago
.gitignore 1a6d929ced init 1 week ago
README.md 04e9c185b7 1 1 week ago
agent.py 04e9c185b7 1 1 week ago
agent_tools.py 04e9c185b7 1 1 week ago
gemini.py 977592a99f fix 1 week ago
requirements.txt 04e9c185b7 1 1 week ago
start_service.sh 04e9c185b7 1 1 week ago

README.md

Knowledge Agent API

基于 FastAPI + LangGraph 的智能内容识别和结构化处理服务。

🚀 快速开始

1. 安装依赖

pip install -r requirements.txt

2. 启动服务

方式一:使用启动脚本(推荐)

./start_service.sh

方式二:直接运行

python3 agent.py

方式三:使用 uvicorn

uvicorn agent:app --host 0.0.0.0 --port 8080 --reload

3. 访问服务

📚 API 接口

POST /parse

同步解析内容处理

请求体:

{
  "requestId": "your_request_id"
}

响应:

{
  "requestId": "your_request_id",
  "processed": 5,
  "success": 4,
  "details": [
    {
      "index": 1,
      "dbInserted": true,
      "identifyError": null,
      "status": "success"
    }
  ]
}

POST /parse/async

异步解析内容处理(后台任务)

请求体:

{
  "requestId": "your_request_id"
}

响应:

{
  "requestId": "your_request_id",
  "status": "processing",
  "message": "任务已提交到后台处理"
}

GET /health

健康检查接口

响应:

{
  "status": "healthy",
  "timestamp": 1703123456.789
}

🔧 配置

环境变量

  • GEMINI_API_KEY: Gemini API 密钥(必需)

数据库配置

utils/mysql_db.py 中配置数据库连接信息。

📁 项目结构

knowledge-agent/
├── agent.py                 # FastAPI + LangGraph 主服务文件
├── agent_tools.py          # 核心工具类
├── gemini.py               # Gemini API 处理器
├── indentify/              # 内容识别模块
│   ├── image_identifier.py # 图像识别
│   ├── video_identifier.py # 视频识别
│   └── indentify.py        # 识别主逻辑
├── structure/              # 结构化处理模块
│   └── structure_processor.py
├── utils/                  # 工具模块
│   ├── mysql_db.py        # 数据库操作
│   ├── logging_config.py  # 日志配置
│   └── file.py            # 文件操作
├── prompt/                 # 提示词模板
├── requirements.txt        # 依赖包列表
└── start_service.sh       # 启动脚本

🎯 核心功能

  1. 内容识别: 支持图像和视频的智能识别
  2. 结构化处理: 使用 Gemini API 进行内容结构化
  3. 数据存储: 自动存储处理结果到数据库
  4. 异步处理: 支持后台异步任务处理
  5. RESTful API: 现代化的 HTTP API 接口
  6. 工作流管理: 基于 LangGraph 的强大流程控制
  7. 状态管理: 完整的处理状态跟踪和错误处理

🚨 注意事项

  1. 确保设置了正确的 GEMINI_API_KEY 环境变量
  2. 确保数据库连接配置正确
  3. 服务默认监听 8080 端口,可通过参数修改

🔍 故障排除

常见问题

  1. 导入错误: 确保所有依赖已正确安装
  2. 数据库连接失败: 检查数据库配置和网络连接
  3. Gemini API 错误: 验证 API 密钥是否正确

日志查看

服务运行时会输出详细日志,包括:

  • 请求处理状态
  • 错误信息
  • 处理进度
  • 性能指标