Skip to content

Commit 13aa491

Browse files
ayushag-nv2ez4bz
andauthored
feat: Xml coder tool parser (#4415) (#4859)
Signed-off-by: ayushag <[email protected]> Co-authored-by: William Zhang <[email protected]>
1 parent 9606c45 commit 13aa491

File tree

7 files changed

+838
-18
lines changed

7 files changed

+838
-18
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/parsers/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ openai-harmony = "0.0.3"
3838
lazy_static = "1.5.0"
3939
rustpython-parser = "0.4.0"
4040
num-traits = "0.2"
41+
42+
[dev-dependencies]
43+
rstest = "0.25"

lib/parsers/src/tool_calling/config.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ impl Default for JsonParserConfig {
5555
}
5656

5757
/// Configuration for parsing tool calls with different formats
58+
// TODO(2ez4bz): refactor to allow other parser configs than `JsonParserConfig`.
5859
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
5960
pub struct ToolCallConfig {
6061
/// The format type for tool calls
@@ -192,4 +193,12 @@ impl ToolCallConfig {
192193
},
193194
}
194195
}
196+
197+
pub fn qwen3_coder() -> Self {
198+
// <tool_call><function=name><parameter=key>value</parameter></function></tool_call>
199+
Self {
200+
format: ToolCallParserType::Xml,
201+
json: JsonParserConfig::default(), // Not used for qwen3_coder but kept for consistency.
202+
}
203+
}
195204
}

lib/parsers/src/tool_calling/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub mod response;
1010
#[cfg(test)]
1111
pub mod tests;
1212
pub mod tools;
13+
pub mod xml;
1314

1415
// Re-export main types and functions for convenience
1516
pub use config::{JsonParserConfig, ToolCallConfig, ToolCallParserType};
@@ -22,3 +23,4 @@ pub use parsers::{
2223
pub use pythonic::try_tool_call_parse_pythonic;
2324
pub use response::{CalledFunction, ToolCallResponse, ToolCallType};
2425
pub use tools::{try_tool_call_parse_aggregate, try_tool_call_parse_stream};
26+
pub use xml::try_tool_call_parse_xml;

0 commit comments

Comments
 (0)