feat(ai): add comprehensive AI streaming and non-streaming processing services
This commit is contained in:
parent
96b92fe487
commit
fdca1fbf86
@ -188,8 +188,8 @@ pub async fn run_mode_streaming(
|
|||||||
let (final_content, err_msg) = match result {
|
let (final_content, err_msg) = match result {
|
||||||
Ok((content, _input, _output)) => (content, None),
|
Ok((content, _input, _output)) => (content, None),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let msg = "[AI 处理发生错误,请稍后再试]".to_string();
|
let msg = format!("AI 处理失败: {}", e);
|
||||||
tracing::error!(error = %e, "{} streaming failed", mode_name);
|
tracing::error!(error = ?e, "{} streaming failed", mode_name);
|
||||||
(String::new(), Some(msg))
|
(String::new(), Some(msg))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -66,7 +66,7 @@ pub async fn process_message_ai_nonstreaming(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!(error = %e, "AI processing failed");
|
tracing::error!(error = ?e, "AI processing failed");
|
||||||
let _ = create_and_publish_ai_message(
|
let _ = create_and_publish_ai_message(
|
||||||
&db,
|
&db,
|
||||||
&cache,
|
&cache,
|
||||||
@ -75,7 +75,7 @@ pub async fn process_message_ai_nonstreaming(
|
|||||||
room_id,
|
room_id,
|
||||||
project_id,
|
project_id,
|
||||||
Uuid::now_v7(),
|
Uuid::now_v7(),
|
||||||
"[AI 处理发生错误,请稍后再试]".to_string(),
|
format!("AI 处理失败: {}", e),
|
||||||
model_id,
|
model_id,
|
||||||
Some(model_display_name),
|
Some(model_display_name),
|
||||||
)
|
)
|
||||||
|
|||||||
@ -68,7 +68,7 @@ pub async fn process_message_ai_react_nonstreaming(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!(error = %e, "ReAct agent failed");
|
tracing::error!(error = ?e, "ReAct agent failed");
|
||||||
let _ = create_and_publish_ai_message(
|
let _ = create_and_publish_ai_message(
|
||||||
&db,
|
&db,
|
||||||
&cache,
|
&cache,
|
||||||
@ -77,7 +77,7 @@ pub async fn process_message_ai_react_nonstreaming(
|
|||||||
room_id,
|
room_id,
|
||||||
project_id,
|
project_id,
|
||||||
Uuid::now_v7(),
|
Uuid::now_v7(),
|
||||||
"[AI 处理发生错误,请稍后再试]".to_string(),
|
format!("AI 处理失败: {}", e),
|
||||||
model_id,
|
model_id,
|
||||||
Some(model_display_name),
|
Some(model_display_name),
|
||||||
)
|
)
|
||||||
|
|||||||
@ -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 {
|
let (final_content, _input_tokens, _output_tokens, err_msg, _should_log) = match result {
|
||||||
Ok((content, input, output)) => (content, input, output, None, false),
|
Ok((content, input, output)) => (content, input, output, None, false),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let msg = "[AI 处理发生错误,请稍后再试]".to_string();
|
let msg = format!("AI 处理失败: {}", e);
|
||||||
tracing::error!(error = %e, "ReAct streaming failed");
|
tracing::error!(error = ?e, "ReAct streaming failed");
|
||||||
(String::new(), 0, 0, Some(msg), true)
|
(String::new(), 0, 0, Some(msg), true)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -247,7 +247,7 @@ pub async fn process_message_ai_streaming(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!(error = %e, "AI streaming failed");
|
tracing::error!(error = ?e, "AI streaming failed");
|
||||||
let _ = typing_cancel_tx.send(());
|
let _ = typing_cancel_tx.send(());
|
||||||
typing_renew_handle.abort();
|
typing_renew_handle.abort();
|
||||||
let typing_stop = queue::TypingEvent {
|
let typing_stop = queue::TypingEvent {
|
||||||
@ -266,7 +266,7 @@ pub async fn process_message_ai_streaming(
|
|||||||
seq: 0,
|
seq: 0,
|
||||||
content: String::new(),
|
content: String::new(),
|
||||||
done: true,
|
done: true,
|
||||||
error: Some("AI 处理发生错误,请稍后再试".to_string()),
|
error: Some(format!("AI 处理失败: {}", e)),
|
||||||
display_name: Some(ai_display_name.clone()),
|
display_name: Some(ai_display_name.clone()),
|
||||||
chunk_type: None,
|
chunk_type: None,
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user