fix: 优化错误提示
This commit is contained in:
1 parent
d57ecc62f9
commit
239d373503
14 files changed
+333
-38
No files matched your search
@@ -141,7 +141,21 @@ def emit_run_failed(
|
||||
conversation_id: str,
|
||||
message: str,
|
||||
code: str | None = None,
|
||||
user_facing: bool = False,
|
||||
) -> str:
|
||||
"""
|
||||
发出本轮失败事件,并附带兼容用的 error 帧。
|
||||
|
||||
核心逻辑:user_facing 为 True 时两帧都带标记,前端原样展示 message。
|
||||
|
||||
Args:
|
||||
message: 失败说明。user_facing 为 True 时必须已是给用户看的句子。
|
||||
code: 业务错误码,可选。
|
||||
user_facing: 为 True 时前端不再把 message 收成通用失败提示。
|
||||
|
||||
Returns:
|
||||
连续两段 SSE 帧:run.failed 与 error。
|
||||
"""
|
||||
error_payload: dict[str, Any] = {
|
||||
"event": "run.failed",
|
||||
"run_id": run_id,
|
||||
@@ -150,10 +164,18 @@ def emit_run_failed(
|
||||
"message": message,
|
||||
"session_status": "error",
|
||||
}
|
||||
legacy_payload: dict[str, Any] = {
|
||||
"event": "error",
|
||||
"message": message,
|
||||
"conversation_id": conversation_id,
|
||||
"session_status": "error",
|
||||
}
|
||||
if code:
|
||||
error_payload["code"] = code
|
||||
legacy = sse_frame({"event": "error", "message": message, "conversation_id": conversation_id, "session_status": "error"})
|
||||
return sse_frame(error_payload) + legacy
|
||||
if user_facing:
|
||||
error_payload["user_facing"] = True
|
||||
legacy_payload["user_facing"] = True
|
||||
return sse_frame(error_payload) + sse_frame(legacy_payload)
|
||||
|
||||
|
||||
def emit_turn_event(event: TurnEvent, *, conversation_id: str) -> str:
|
||||
|
||||
@@ -194,6 +194,7 @@ class ChatTurnRuntime:
|
||||
conversation_id=session.session_id,
|
||||
message=exc.message,
|
||||
code=str(getattr(exc, "code", "") or "") or None,
|
||||
user_facing=True,
|
||||
)
|
||||
except Exception as exc:
|
||||
current_app.logger.exception("[chat-turn] unexpected failure request_id=%s turn_id=%s", req_id, turn_id)
|
||||
|
||||
Reference in new issue
Block a user