use async way to run ai

This commit is contained in:
2026-03-05 15:39:50 +08:00
parent dd40e754f1
commit bd5883585a
2 changed files with 6 additions and 25 deletions

23
main.py
View File

@@ -1,6 +1,7 @@
"""FastAPI 应用主文件"""
import logging
import asyncio
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
@@ -39,26 +40,6 @@ class FullWorkflowResponse(BaseModel):
@app.post("/workflow/full", response_model=FullWorkflowResponse)
async def full_workflow(request: Request):
"""
完整工作流PM Agent -> QA Agent -> Dev Agent
这个端点接收一个简单的需求描述通过三个Agent的协作
最终生成完整的需求分析、测试用例和Java代码。
Args:
request: RequirementRequest 包含简单的需求描述
Returns:
FullWorkflowResponse 包含:
- requirement_analysis: PM Agent的需求分析结果
- test_cases: QA Agent生成的测试用例
- code_generation: Dev Agent生成的Java代码和单元测试
Example:
{
"requirement": "创建一个用户管理系统,支持用户注册、登录、个人信息管理"
}
"""
try:
body_bytes = await request.body()
message = body_bytes.decode('utf-8')
@@ -66,7 +47,7 @@ async def full_workflow(request: Request):
logger.info(f"开始处理需求: {message}")
# 调用编排函数执行三个Agent的工作流
await orchestrate_agents(message)
asyncio.create_task( orchestrate_agents(message))
# 构建响应
response = FullWorkflowResponse(