A high-performance inference engine for AI models
fix(hanashi): preserve hyphens in Qwen tool names (#1062)
xianxian.zhang3fc15487d863
diff --git a/crates/legacy/hanashi/configs/parsing/qwen3.5.json b/crates/legacy/hanashi/configs/parsing/qwen3.5.jsonindex c51b3d700..f0156e657 100644--- a/crates/legacy/hanashi/configs/parsing/qwen3.5.json+++ b/crates/legacy/hanashi/configs/parsing/qwen3.5.json@@ -62,7 +62,7 @@"name": [{"type": "regex_find_all",- "pattern": "<function=(\\w+)>"+ "pattern": "<function=([\\w-]+)>"},{"type": "first"diff --git a/crates/legacy/hanashi/configs/parsing/qwen3.6.json b/crates/legacy/hanashi/configs/parsing/qwen3.6.jsonindex c51b3d700..f0156e657 100644--- a/crates/legacy/hanashi/configs/parsing/qwen3.6.json+++ b/crates/legacy/hanashi/configs/parsing/qwen3.6.json@@ -62,7 +62,7 @@"name": [{"type": "regex_find_all",- "pattern": "<function=(\\w+)>"+ "pattern": "<function=([\\w-]+)>"},{"type": "first"diff --git a/crates/legacy/hanashi/unit/chat/hanashi/messages/streamed/content.rs b/crates/legacy/hanashi/unit/chat/hanashi/messages/streamed/content.rsindex a7555312c..a89d8629f 100644--- a/crates/legacy/hanashi/unit/chat/hanashi/messages/streamed/content.rs+++ b/crates/legacy/hanashi/unit/chat/hanashi/messages/streamed/content.rs@@ -1,5 +1,42 @@use super::*;+#[test]+fn qwen_tool_calls_preserve_hyphenated_function_names() {+ use token_stream_parser::{Parser, token_stream::TokenStreamParser, types::Token};++ use crate::chat::hanashi::{config::HanashiConfig, messages::streamed::Message};++ for config in [HanashiConfig::Qwen35, HanashiConfig::Qwen36, HanashiConfig::Qwen38] {+ for (name, parameters, arguments) in [+ ("ping-pong", "", serde_json::json!({})),+ ("get_weather-v2", "<parameter=city>\nLondon\n</parameter>\n", serde_json::json!({"city": "London"})),+ ] {+ let mut parser = TokenStreamParser::new(config.resolve().unwrap().parsing).unwrap();+ let body = format!("\n<function={name}>\n{parameters}</function>\n");+ let fragments = ["<|im_start|>", "assistant", "\n", "<tool_call>"]+ .into_iter()+ .map(str::to_string)+ .chain(body.chars().map(|value| value.to_string()))+ .chain(["</tool_call>", "<|im_end|>"].into_iter().map(str::to_string));+ for value in fragments {+ parser+ .push(&Token {+ id: 0,+ value,+ is_special: false,+ })+ .unwrap();+ }+ let messages: Vec<Message> = serde_json::from_value(parser.state().value.clone()).unwrap();+ let message: shoji::types::session::chat::ChatMessage = messages.into_iter().last().unwrap().into();+ let calls = message.tool_calls();+ assert_eq!(calls.len(), 1, "{config:?}: {:?}", message.content);+ assert_eq!(calls[0].name, name);+ assert_eq!(serde_json::from_str::<Value>(&calls[0].arguments.json).unwrap(), arguments);+ }+ }+}+#[test]fn qwen38_exposes_tool_candidates_before_the_call_closes() {use token_stream_parser::{Parser, token_stream::TokenStreamParser, types::Token};