feat(ws): 移除工具结果的处理逻辑,优化消息输出
This commit is contained in:
parent
d35e89a44c
commit
2f47a8a273
@ -319,15 +319,7 @@ impl OutboundMessage {
|
|||||||
)]
|
)]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"tool" => vec![Self::tool_result(
|
"tool" => Vec::new(),
|
||||||
channel.to_string(),
|
|
||||||
chat_id.to_string(),
|
|
||||||
message.tool_call_id.clone().unwrap_or_else(|| message.id.clone()),
|
|
||||||
message.tool_name.clone().unwrap_or_else(|| "tool".to_string()),
|
|
||||||
message.content.clone(),
|
|
||||||
reply_to,
|
|
||||||
metadata.clone(),
|
|
||||||
)],
|
|
||||||
_ => Vec::new(),
|
_ => Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -404,7 +396,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_from_chat_message_maps_tool_result() {
|
fn test_from_chat_message_omits_tool_result() {
|
||||||
let message = ChatMessage::tool("call-9", "calculator", "2");
|
let message = ChatMessage::tool("call-9", "calculator", "2");
|
||||||
|
|
||||||
let outbound = OutboundMessage::from_chat_message(
|
let outbound = OutboundMessage::from_chat_message(
|
||||||
@ -415,10 +407,6 @@ mod tests {
|
|||||||
&message,
|
&message,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(outbound.len(), 1);
|
assert!(outbound.is_empty());
|
||||||
assert_eq!(outbound[0].event_kind, OutboundEventKind::ToolResult);
|
|
||||||
assert_eq!(outbound[0].tool_call_id.as_deref(), Some("call-9"));
|
|
||||||
assert_eq!(outbound[0].tool_name.as_deref(), Some("calculator"));
|
|
||||||
assert!(outbound[0].content.contains("工具结果: calculator"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -172,17 +172,7 @@ fn ws_outbound_from_chat_message(message: &ChatMessage) -> Vec<WsOutbound> {
|
|||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"tool" => vec![WsOutbound::ToolResult {
|
"tool" => Vec::new(),
|
||||||
id: message.id.clone(),
|
|
||||||
tool_call_id: message.tool_call_id.clone().unwrap_or_else(|| message.id.clone()),
|
|
||||||
tool_name: message.tool_name.clone().unwrap_or_else(|| "tool".to_string()),
|
|
||||||
content: format!(
|
|
||||||
"工具结果: {}\n\n{}",
|
|
||||||
message.tool_name.clone().unwrap_or_else(|| "tool".to_string()),
|
|
||||||
message.content,
|
|
||||||
),
|
|
||||||
role: message.role.clone(),
|
|
||||||
}],
|
|
||||||
_ => Vec::new(),
|
_ => Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -379,3 +369,45 @@ async fn handle_inbound(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::ws_outbound_from_chat_message;
|
||||||
|
use crate::bus::ChatMessage;
|
||||||
|
use crate::providers::ToolCall;
|
||||||
|
use crate::protocol::WsOutbound;
|
||||||
|
use serde_json::json;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_ws_outbound_from_chat_message_expands_tool_calls() {
|
||||||
|
let message = ChatMessage::assistant_with_tool_calls(
|
||||||
|
"",
|
||||||
|
vec![ToolCall {
|
||||||
|
id: "call-1".to_string(),
|
||||||
|
name: "calculator".to_string(),
|
||||||
|
arguments: json!({"expression": "1 + 1"}),
|
||||||
|
}],
|
||||||
|
);
|
||||||
|
|
||||||
|
let outbound = ws_outbound_from_chat_message(&message);
|
||||||
|
|
||||||
|
assert_eq!(outbound.len(), 1);
|
||||||
|
match &outbound[0] {
|
||||||
|
WsOutbound::ToolCall { tool_call_id, tool_name, arguments, .. } => {
|
||||||
|
assert_eq!(tool_call_id, "call-1");
|
||||||
|
assert_eq!(tool_name, "calculator");
|
||||||
|
assert_eq!(arguments["expression"], "1 + 1");
|
||||||
|
}
|
||||||
|
other => panic!("unexpected outbound variant: {:?}", other),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_ws_outbound_from_chat_message_omits_tool_results() {
|
||||||
|
let message = ChatMessage::tool("call-1", "calculator", "2");
|
||||||
|
|
||||||
|
let outbound = ws_outbound_from_chat_message(&message);
|
||||||
|
|
||||||
|
assert!(outbound.is_empty());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user