feat:专家智能体评选页面重构
This commit is contained in:
@@ -1489,6 +1489,97 @@ def handle_agent_select_modify_add_aspect_ws(data):
|
||||
})
|
||||
|
||||
|
||||
@socketio.on('agent_select_modify_delete_aspect')
|
||||
def handle_agent_select_modify_delete_aspect_ws(data):
|
||||
"""
|
||||
WebSocket版本:删除评估维度
|
||||
|
||||
请求格式:
|
||||
{
|
||||
"id": "request-id",
|
||||
"data": {
|
||||
"task_id": "task-id",
|
||||
"step_id": "step-id",
|
||||
"aspect_name": "要删除的维度名称"
|
||||
}
|
||||
}
|
||||
"""
|
||||
request_id = data.get('id')
|
||||
incoming_data = data.get('data', {})
|
||||
task_id = incoming_data.get('task_id')
|
||||
step_id = incoming_data.get('step_id')
|
||||
aspect_name = incoming_data.get('aspect_name')
|
||||
|
||||
if not task_id or not aspect_name:
|
||||
emit('response', {
|
||||
'id': request_id,
|
||||
'status': 'error',
|
||||
'error': '缺少必要参数 task_id 或 aspect_name'
|
||||
})
|
||||
return
|
||||
|
||||
try:
|
||||
with get_db_context() as db:
|
||||
# 获取现有的 agent_scores 数据
|
||||
task = MultiAgentTaskCRUD.get_by_id(db, task_id)
|
||||
if not task:
|
||||
emit('response', {
|
||||
'id': request_id,
|
||||
'status': 'error',
|
||||
'error': f'任务不存在: {task_id}'
|
||||
})
|
||||
return
|
||||
|
||||
existing_scores = task.agent_scores or {}
|
||||
|
||||
# 如果指定了 step_id,则只更新该步骤的评分;否则更新所有步骤
|
||||
if step_id and step_id in existing_scores:
|
||||
step_scores = existing_scores[step_id]
|
||||
# 从 aspectList 中移除该维度
|
||||
if 'aspectList' in step_scores and aspect_name in step_scores['aspectList']:
|
||||
step_scores['aspectList'] = [a for a in step_scores['aspectList'] if a != aspect_name]
|
||||
# 从每个 agent 的评分中移除该维度
|
||||
if 'agentScores' in step_scores:
|
||||
for agent_name in step_scores['agentScores']:
|
||||
if aspect_name in step_scores['agentScores'][agent_name]:
|
||||
del step_scores['agentScores'][agent_name][aspect_name]
|
||||
print(f"[agent_select_modify_delete_aspect] 已删除维度 from step_id={step_id}, 维度={aspect_name}")
|
||||
else:
|
||||
# 遍历所有步骤,移除该维度
|
||||
for sid, step_scores in existing_scores.items():
|
||||
if 'aspectList' in step_scores and aspect_name in step_scores['aspectList']:
|
||||
step_scores['aspectList'] = [a for a in step_scores['aspectList'] if a != aspect_name]
|
||||
if 'agentScores' in step_scores:
|
||||
for agent_name in step_scores['agentScores']:
|
||||
if aspect_name in step_scores['agentScores'][agent_name]:
|
||||
del step_scores['agentScores'][agent_name][aspect_name]
|
||||
print(f"[agent_select_modify_delete_aspect] 已删除所有步骤中的维度,维度={aspect_name}")
|
||||
|
||||
# 保存更新后的评分数据到数据库
|
||||
db.execute(
|
||||
text("UPDATE multi_agent_tasks SET agent_scores = :scores WHERE task_id = :id"),
|
||||
{"scores": json.dumps(existing_scores), "id": task_id}
|
||||
)
|
||||
db.commit()
|
||||
|
||||
emit('response', {
|
||||
'id': request_id,
|
||||
'status': 'success',
|
||||
'data': {
|
||||
"message": f"维度 '{aspect_name}' 删除成功",
|
||||
"task_id": task_id,
|
||||
"deleted_aspect": aspect_name
|
||||
}
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
emit('response', {
|
||||
'id': request_id,
|
||||
'status': 'error',
|
||||
'error': str(e)
|
||||
})
|
||||
|
||||
|
||||
@socketio.on('set_agents')
|
||||
def handle_set_agents_ws(data):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user