From fdca1fbf868431b654fa5c28925e90a8578270ff Mon Sep 17 00:00:00 2001 From: ZhenYi <434836402@qq.com> Date: Fri, 1 May 2026 00:54:24 +0800 Subject: [PATCH] feat(ai): add comprehensive AI streaming and non-streaming processing services --- libs/room/src/service/ai_mode_streaming.rs | 4 ++-- libs/room/src/service/ai_nonstreaming.rs | 4 ++-- libs/room/src/service/ai_react_nonstreaming.rs | 4 ++-- libs/room/src/service/ai_react_streaming.rs | 4 ++-- libs/room/src/service/ai_streaming.rs | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libs/room/src/service/ai_mode_streaming.rs b/libs/room/src/service/ai_mode_streaming.rs index aeca3f2..0d42fa2 100644 --- a/libs/room/src/service/ai_mode_streaming.rs +++ b/libs/room/src/service/ai_mode_streaming.rs @@ -188,8 +188,8 @@ pub async fn run_mode_streaming( let (final_content, err_msg) = match result { Ok((content, _input, _output)) => (content, None), Err(e) => { - let msg = "[AI 处理发生错误,请稍后再试]".to_string(); - tracing::error!(error = %e, "{} streaming failed", mode_name); + let msg = format!("AI 处理失败: {}", e); + tracing::error!(error = ?e, "{} streaming failed", mode_name); (String::new(), Some(msg)) } }; diff --git a/libs/room/src/service/ai_nonstreaming.rs b/libs/room/src/service/ai_nonstreaming.rs index e8a12b3..ca3fc1b 100644 --- a/libs/room/src/service/ai_nonstreaming.rs +++ b/libs/room/src/service/ai_nonstreaming.rs @@ -66,7 +66,7 @@ pub async fn process_message_ai_nonstreaming( } } Err(e) => { - tracing::error!(error = %e, "AI processing failed"); + tracing::error!(error = ?e, "AI processing failed"); let _ = create_and_publish_ai_message( &db, &cache, @@ -75,7 +75,7 @@ pub async fn process_message_ai_nonstreaming( room_id, project_id, Uuid::now_v7(), - "[AI 处理发生错误,请稍后再试]".to_string(), + format!("AI 处理失败: {}", e), model_id, Some(model_display_name), ) diff --git a/libs/room/src/service/ai_react_nonstreaming.rs b/libs/room/src/service/ai_react_nonstreaming.rs index d558d47..ad6bc26 100644 --- a/libs/room/src/service/ai_react_nonstreaming.rs +++ b/libs/room/src/service/ai_react_nonstreaming.rs @@ -68,7 +68,7 @@ pub async fn process_message_ai_react_nonstreaming( } } Err(e) => { - tracing::error!(error = %e, "ReAct agent failed"); + tracing::error!(error = ?e, "ReAct agent failed"); let _ = create_and_publish_ai_message( &db, &cache, @@ -77,7 +77,7 @@ pub async fn process_message_ai_react_nonstreaming( room_id, project_id, Uuid::now_v7(), - "[AI 处理发生错误,请稍后再试]".to_string(), + format!("AI 处理失败: {}", e), model_id, Some(model_display_name), ) diff --git a/libs/room/src/service/ai_react_streaming.rs b/libs/room/src/service/ai_react_streaming.rs index fcb5d15..3d25ba7 100644 --- a/libs/room/src/service/ai_react_streaming.rs +++ b/libs/room/src/service/ai_react_streaming.rs @@ -196,8 +196,8 @@ pub async fn process_message_ai_react_streaming( let (final_content, _input_tokens, _output_tokens, err_msg, _should_log) = match result { Ok((content, input, output)) => (content, input, output, None, false), Err(e) => { - let msg = "[AI 处理发生错误,请稍后再试]".to_string(); - tracing::error!(error = %e, "ReAct streaming failed"); + let msg = format!("AI 处理失败: {}", e); + tracing::error!(error = ?e, "ReAct streaming failed"); (String::new(), 0, 0, Some(msg), true) } }; diff --git a/libs/room/src/service/ai_streaming.rs b/libs/room/src/service/ai_streaming.rs index 822b00f..c4412ee 100644 --- a/libs/room/src/service/ai_streaming.rs +++ b/libs/room/src/service/ai_streaming.rs @@ -247,7 +247,7 @@ pub async fn process_message_ai_streaming( } } Err(e) => { - tracing::error!(error = %e, "AI streaming failed"); + tracing::error!(error = ?e, "AI streaming failed"); let _ = typing_cancel_tx.send(()); typing_renew_handle.abort(); let typing_stop = queue::TypingEvent { @@ -266,7 +266,7 @@ pub async fn process_message_ai_streaming( seq: 0, content: String::new(), done: true, - error: Some("AI 处理发生错误,请稍后再试".to_string()), + error: Some(format!("AI 处理失败: {}", e)), display_name: Some(ai_display_name.clone()), chunk_type: None, };