from fastapi import HTTPException def handle_generation_error(error: Exception, user_input: str): error_msg = f"推理失败(输入:{user_input}),错误原因:{str(error)[:100]}" print(error_msg) raise HTTPException( status_code=500, detail={"error": "AI回复生成失败", "msg": error_msg} )