基本完成,舒适性修补
This commit is contained in:
@@ -134,3 +134,45 @@ async def update_table_data(role_name: str, chat_name: str, table_update: dict):
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.post("/{role_name}/{chat_name}/branch", status_code=status.HTTP_201_CREATED)
|
||||
async def branch_chat(role_name: str, chat_name: str, branch_data: dict):
|
||||
"""
|
||||
创建聊天分支
|
||||
|
||||
复制当前楼层及之前的所有内容到一个新的聊天记录
|
||||
|
||||
Args:
|
||||
role_name: 角色名称
|
||||
chat_name: 原聊天名称
|
||||
branch_data: {
|
||||
"target_floor": int, # 目标楼层(包含该楼层及之前的内容)
|
||||
"new_chat_name": str # 新聊天名称(可选,默认自动生成)
|
||||
}
|
||||
|
||||
Returns:
|
||||
{
|
||||
"success": bool,
|
||||
"new_chat_name": str,
|
||||
"message_count": int
|
||||
}
|
||||
"""
|
||||
try:
|
||||
target_floor = branch_data.get("target_floor")
|
||||
new_chat_name = branch_data.get("new_chat_name")
|
||||
|
||||
if target_floor is None:
|
||||
raise HTTPException(status_code=400, detail="缺少 target_floor 参数")
|
||||
|
||||
# 调用服务层创建分支
|
||||
result = chat_service.create_branch(role_name, chat_name, target_floor, new_chat_name)
|
||||
|
||||
return result
|
||||
|
||||
except FileNotFoundError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"创建分支失败: {str(e)}")
|
||||
|
||||
Reference in New Issue
Block a user