|  wangxq
				
				44fca2b272
				把react_agent从/test/目录下复制出来,创建统一的unified_api.py,把chat api 改为ask_react_api. | há 3 meses atrás | |
|---|---|---|
| .. | ||
| ASGI_启动说明.md | há 3 meses atrás | |
| FLASK_MIGRATION.md | há 3 meses atrás | |
| MIGRATION_COMPLETE.md | há 3 meses atrás | |
| QUICKSTART.md | há 3 meses atrás | |
| README_API.md | há 3 meses atrás | |
| README_valid_sql_test.md | há 3 meses atrás | |
| agent.py.backup | há 3 meses atrás | |
| api_design.md | há 3 meses atrás | |
| community_help_request.md | há 3 meses atrás | |
| network_troubleshooting.md | há 3 meses atrás | |
| redesign_summary.md | há 3 meses atrás | |
| result 输出结果.md | há 3 meses atrás | |
| 两个关键问题.md | há 3 meses atrás | |
| 修改默认用户.md | há 3 meses atrás | |
| 参考方案.md | há 3 meses atrás | |
| 增强valid()验证.md | há 3 meses atrás | |
| 异步改造建议参考.md | há 3 meses atrás | |
| 异步改造方案.md | há 3 meses atrás | |
| 独立测试说明.md | há 3 meses atrás | |
Flask API服务,提供与Custom React Agent进行交互的RESTful接口。
cd test/custom_react_agent
python api.py
服务将在 http://localhost:8000 启动
GET /health
检查API服务状态
响应示例:
{
  "status": "healthy",
  "agent_initialized": true,
  "timestamp": "2025-01-15T10:30:00"
}
POST /api/chat
与Agent进行对话
请求参数:
{
  "question": "请问哪个高速服务区的档口数量最多?",
  "user_id": "doudou",
  "thread_id": "doudou:20250115103000001"  // 可选,不提供则自动生成
}
响应示例:
{
  "success": true,
  "data": {
    "records": {...},      // SQL查询结果
    "response": "...",     // Agent回答
    "sql": "...",         // 执行的SQL
    "react_agent_meta": {...}
  },
  "thread_id": "doudou:20250115103000001",
  "timestamp": "2025-01-15T10:30:00"
}
GET /api/v0/react/users/{user_id}/conversations
获取指定用户的最近聊天记录列表
路径参数:
user_id: 用户ID查询参数:
limit: 返回数量限制 (默认10,最大50)请求示例:
curl "http://localhost:8000/api/v0/react/users/doudou/conversations?limit=5"
响应示例:
{
  "success": true,
  "data": {
    "user_id": "doudou",
    "conversations": [
      {
        "thread_id": "doudou:20250115103000001",
        "user_id": "doudou",
        "timestamp": "20250115103000001",
        "message_count": 4,
        "last_message": "南城服务区的档口数量最多,共有39个档口。",
        "last_updated": "2025-01-15T10:30:00",
        "conversation_preview": "请问哪个高速服务区的档口数量最多?",
        "formatted_time": "2025-01-15 10:30:00"
      },
      {
        "thread_id": "doudou:20250115102500002", 
        "user_id": "doudou",
        "timestamp": "20250115102500002",
        "message_count": 6,
        "last_message": "共有6个餐饮档口。",
        "last_updated": "2025-01-15T10:25:00",
        "conversation_preview": "南城服务区有多少个餐饮档口?",
        "formatted_time": "2025-01-15 10:25:00"
      }
    ],
    "total_count": 2,
    "limit": 5
  },
  "timestamp": "2025-01-15T10:35:00"
}
GET /api/v0/react/users/{user_id}/conversations/{thread_id}
获取特定对话的详细历史记录
路径参数:
user_id: 用户IDthread_id: 对话线程ID (必须以 user_id: 开头)请求示例:
curl "http://localhost:8000/api/v0/react/users/doudou/conversations/doudou:20250115103000001"
响应示例:
{
  "success": true,
  "data": {
    "user_id": "doudou",
    "thread_id": "doudou:20250115103000001",
    "message_count": 4,
    "messages": [
      {
        "type": "human",
        "content": "请问哪个高速服务区的档口数量最多?",
        "tool_calls": null
      },
      {
        "type": "ai", 
        "content": "我来帮您查询一下高速服务区的档口数量信息。",
        "tool_calls": [...]
      },
      {
        "type": "tool",
        "content": "[{\"service_area\": \"南城服务区\", \"booth_count\": 39}, ...]",
        "tool_calls": null
      },
      {
        "type": "ai",
        "content": "南城服务区的档口数量最多,共有39个档口。",
        "tool_calls": null
      }
    ]
  },
  "timestamp": "2025-01-15T10:35:00"
}
{user_id}:{timestamp}doudou:20250115103000001# 1. 发起对话
curl -X POST http://localhost:8000/api/chat \
  -H "Content-Type: application/json" \
  -d '{"question": "请问哪个高速服务区的档口数量最多?", "user_id": "doudou"}'
# 2. 查看对话列表  
curl "http://localhost:8000/api/v0/react/users/doudou/conversations?limit=5"
# 3. 查看特定对话详情
curl "http://localhost:8000/api/v0/react/users/doudou/conversations/doudou:20250115103000001"