56 lines
1.2 KiB
Python
56 lines
1.2 KiB
Python
|
|
"""
|
||
|
|
角色分配 API 路由
|
||
|
|
"""
|
||
|
|
from fastapi import APIRouter
|
||
|
|
from pydantic import BaseModel
|
||
|
|
from typing import List, Dict
|
||
|
|
|
||
|
|
router = APIRouter()
|
||
|
|
|
||
|
|
|
||
|
|
class RoleRequest(BaseModel):
|
||
|
|
task: str
|
||
|
|
|
||
|
|
|
||
|
|
class RoleAllocateRequest(BaseModel):
|
||
|
|
task: str
|
||
|
|
agents: List[str]
|
||
|
|
|
||
|
|
|
||
|
|
@router.post("/primary")
|
||
|
|
async def get_primary_role(request: RoleRequest):
|
||
|
|
"""获取任务主要角色"""
|
||
|
|
return {
|
||
|
|
"task": request.task,
|
||
|
|
"primary_role": "developer",
|
||
|
|
"role_scores": {
|
||
|
|
"developer": 0.8,
|
||
|
|
"architect": 0.6,
|
||
|
|
"qa": 0.4,
|
||
|
|
"pm": 0.2
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
@router.post("/allocate")
|
||
|
|
async def allocate_roles(request: RoleAllocateRequest):
|
||
|
|
"""分配角色"""
|
||
|
|
allocation = {}
|
||
|
|
for i, agent in enumerate(request.agents):
|
||
|
|
roles = ["developer", "architect", "qa"]
|
||
|
|
allocation[agent] = roles[i % len(roles)]
|
||
|
|
|
||
|
|
return {
|
||
|
|
"task": request.task,
|
||
|
|
"primary_role": "developer",
|
||
|
|
"allocation": allocation
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
@router.post("/explain")
|
||
|
|
async def explain_roles(request: RoleAllocateRequest):
|
||
|
|
"""解释角色分配"""
|
||
|
|
return {
|
||
|
|
"explanation": f"基于任务 '{request.task}' 的分析,推荐了最适合的角色分配方案。"
|
||
|
|
}
|