|
1 week ago | |
---|---|---|
agents | 1 week ago | |
database | 1 week ago | |
prompt | 1 week ago | |
tools | 1 week ago | |
utils | 1 week ago | |
.DS_Store | 1 week ago | |
.env | 1 week ago | |
.gitignore | 1 week ago | |
README.md | 1 week ago | |
agent.py | 1 week ago | |
gemini.py | 1 week ago | |
requirements.txt | 1 week ago | |
start_service.sh | 1 week ago |
基于 FastAPI + LangGraph 的智能内容识别和结构化处理服务。支持通过API输入指令执行Agent。
pip install -r requirements.txt
./start_service.sh # 启动主服务
./start_api.sh # 启动API服务
python3 agent.py # 运行Agent
python3 api.py # 运行API服务
uvicorn agent:app --host 0.0.0.0 --port 8080 --reload # 主服务
uvicorn api:app --host 0.0.0.0 --port 8000 --reload # API服务
通过API执行Agent处理用户指令
请求体:
{
"instruction": "你的指令内容"
}
响应:
{
"status": "success",
"result": "Agent执行结果..."
}
API服务健康检查
响应:
{
"message": "Knowledge Agent API 服务已启动,请使用 /execute 端点执行Agent"
}
同步解析内容处理
请求体:
{
"requestId": "your_request_id"
}
响应:
{
"requestId": "your_request_id",
"processed": 5,
"success": 4,
"details": [
{
"index": 1,
"dbInserted": true,
"identifyError": null,
"status": "success"
}
]
}
异步解析内容处理(后台任务)
请求体:
{
"requestId": "your_request_id"
}
响应:
{
"requestId": "your_request_id",
"status": "processing",
"message": "任务已提交到后台处理"
}
健康检查接口
响应:
{
"status": "healthy",
"timestamp": 1703123456.789
}
GEMINI_API_KEY
: Gemini API 密钥(必需)系统支持 LangSmith 追踪功能,可以通过 .env
文件配置:
在 .env
文件中配置:
```bash
LANGCHAIN_TRACING_V2=true
LANGCHAIN_ENDPOINT=https://api.smith.langchain.com
LANGCHAIN_API_KEY=your_langsmith_api_key_here
LANGCHAIN_PROJECT=knowledge-agent
3. 重启服务即可生效
**注意**: 如果没有配置 `.env` 文件或相关环境变量,系统将自动禁用 LangSmith 追踪以避免网络连接错误。
### 数据库配置
在 `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. **状态管理**: 完整的处理状态跟踪和错误处理
8. **Agent API**: 支持通过API直接执行Agent处理指令
## 📝 API使用示例
### Python示例
```python
import requests
# API服务地址
api_url = "http://localhost:8000/execute"
# 发送请求
response = requests.post(
api_url,
json={"instruction": "分析以下内容并提取关键信息:..."},
)
# 处理响应
if response.status_code == 200:
result = response.json()
print(f"状态: {result['status']}")
print(f"结果: {result['result']}")
else:
print(f"请求失败: {response.status_code}")
curl -X POST http://localhost:8000/execute \
-H "Content-Type: application/json" \
-d '{"instruction": "分析以下内容并提取关键信息:..."}'
GEMINI_API_KEY
环境变量服务运行时会输出详细日志,包括: