Skip to content

Commit 951989d

Browse files
vladnosivayushag-nv
authored andcommitted
feat: DeepSeek V3.2 tool calling support (ai-dynamo#4822)
Signed-off-by: Vladislav Nosivskoy <[email protected]> Co-authored-by: Ayush Agarwal <[email protected]>
1 parent 6632f0c commit 951989d

File tree

5 files changed

+636
-0
lines changed

5 files changed

+636
-0
lines changed

lib/parsers/src/tool_calling/config.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,36 @@ impl Default for XmlParserConfig {
6969
}
7070
}
7171

72+
/// Configuration for DSML-style tool call parser (DeepSeek V3.2+)
73+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
74+
pub struct DsmlParserConfig {
75+
/// Start token for function_calls block (e.g., "<|DSML|function_calls>")
76+
pub function_calls_start: String,
77+
/// End token for function_calls block (e.g., "</|DSML|function_calls>")
78+
pub function_calls_end: String,
79+
/// Start prefix for invoke (e.g., "<|DSML|invoke name=")
80+
pub invoke_start_prefix: String,
81+
/// End token for invoke (e.g., "</|DSML|invoke>")
82+
pub invoke_end: String,
83+
/// Start prefix for parameter (e.g., "<|DSML|parameter name=")
84+
pub parameter_prefix: String,
85+
/// End token for parameter (e.g., "</|DSML|parameter>")
86+
pub parameter_end: String,
87+
}
88+
89+
impl Default for DsmlParserConfig {
90+
fn default() -> Self {
91+
Self {
92+
function_calls_start: "<|DSML|function_calls>".to_string(),
93+
function_calls_end: "</|DSML|function_calls>".to_string(),
94+
invoke_start_prefix: "<|DSML|invoke name=".to_string(),
95+
invoke_end: "</|DSML|invoke>".to_string(),
96+
parameter_prefix: "<|DSML|parameter name=".to_string(),
97+
parameter_end: "</|DSML|parameter>".to_string(),
98+
}
99+
}
100+
}
101+
72102
/// Parser-specific configuration
73103
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
74104
#[serde(tag = "type", rename_all = "snake_case")]
@@ -78,6 +108,7 @@ pub enum ParserConfig {
78108
Pythonic,
79109
Harmony(JsonParserConfig),
80110
Typescript,
111+
Dsml(DsmlParserConfig),
81112
}
82113

83114
impl ParserConfig {
@@ -90,6 +121,7 @@ impl ParserConfig {
90121
ParserConfig::Xml(config) => vec![config.tool_call_start_token.clone()],
91122
ParserConfig::Pythonic => vec![],
92123
ParserConfig::Typescript => vec![],
124+
ParserConfig::Dsml(config) => vec![config.function_calls_start.clone()],
93125
}
94126
}
95127

@@ -102,6 +134,7 @@ impl ParserConfig {
102134
ParserConfig::Xml(config) => vec![config.tool_call_end_token.clone()],
103135
ParserConfig::Pythonic => vec![],
104136
ParserConfig::Typescript => vec![],
137+
ParserConfig::Dsml(config) => vec![config.function_calls_end.clone()],
105138
}
106139
}
107140
}
@@ -249,4 +282,16 @@ impl ToolCallConfig {
249282
}),
250283
}
251284
}
285+
286+
pub fn deepseek_v3_2() -> Self {
287+
// DeepSeek V3.2 format (DSML):
288+
// <|DSML|function_calls>
289+
// <|DSML|invoke name="function_name">
290+
// <|DSML|parameter name="param_name" string="true|false">value</|DSML|parameter>
291+
// </|DSML|invoke>
292+
// </|DSML|function_calls>
293+
Self {
294+
parser_config: ParserConfig::Dsml(DsmlParserConfig::default()),
295+
}
296+
}
252297
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
mod parser;
5+
6+
pub use super::response;
7+
pub use parser::{
8+
detect_tool_call_start_dsml, find_tool_call_end_position_dsml, try_tool_call_parse_dsml,
9+
};

0 commit comments

Comments
 (0)