Skip to content

Commit d7702b8

Browse files
authored
chore: jamba based parsers (#4856)
Signed-off-by: ayushag <[email protected]>
1 parent ce602cb commit d7702b8

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

docs/agents/tool-calling.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Parser to Model Mapping
3838
| deepseek_v3 | deepseek-ai/DeepSeek-V3, deepseek-ai/DeepSeek-R1, deepseek-ai/DeepSeek-R1-0528 |
3939
| deepseek_v3_1 | deepseek-ai/DeepSeek-V3.1 |
4040
| pythonic | meta-llama/Llama-4-* |
41+
| jamba | ai21labs/AI21-Jamba-*-1.5, ai21labs/AI21-Jamba-*-1.6, ai21labs/AI21-Jamba-*-1.7, |
4142
4243
4344
## Examples

lib/parsers/src/tool_calling/config.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,14 @@ impl ToolCallConfig {
239239
parser_config: ParserConfig::Xml(XmlParserConfig::default()),
240240
}
241241
}
242+
243+
pub fn jamba() -> Self {
244+
Self {
245+
parser_config: ParserConfig::Json(JsonParserConfig {
246+
tool_call_start_tokens: vec!["<tool_calls>".to_string()],
247+
tool_call_end_tokens: vec!["</tool_calls>".to_string()],
248+
..Default::default()
249+
}),
250+
}
251+
}
242252
}

lib/parsers/src/tool_calling/parsers.rs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub fn get_tool_parser_map() -> &'static HashMap<&'static str, ToolCallConfig> {
3636
map.insert("deepseek_v3", ToolCallConfig::deepseek_v3());
3737
map.insert("deepseek_v3_1", ToolCallConfig::deepseek_v3_1());
3838
map.insert("qwen3_coder", ToolCallConfig::qwen3_coder());
39+
map.insert("jamba", ToolCallConfig::jamba());
3940
map.insert("default", ToolCallConfig::default());
4041
map
4142
})
@@ -191,6 +192,7 @@ mod tests {
191192
"deepseek_v3",
192193
"deepseek_v3_1",
193194
"qwen3_coder",
195+
"jamba",
194196
];
195197
for parser in available_parsers {
196198
assert!(parsers.contains(&parser));
@@ -940,19 +942,11 @@ Remember, San Francisco weather can be quite unpredictable, particularly with it
940942
}
941943

942944
#[tokio::test]
943-
#[ignore]
944945
async fn test_ai21labs_ai21_jamba_15_mini_simple() {
945-
let input = r#" [
946-
{"name": "get_weather", "arguments": {"location": "San Francisco, CA", "unit": "fahrenheit"}}
947-
]"#;
948-
let config = ToolCallConfig {
949-
parser_config: ParserConfig::Json(JsonParserConfig {
950-
tool_call_start_tokens: vec![],
951-
tool_call_end_tokens: vec![],
952-
arguments_keys: vec!["arguments".to_string()],
953-
..Default::default()
954-
}),
955-
};
946+
let input = r#"<tool_calls>[
947+
{"name": "get_weather", "arguments": {"location": "San Francisco, CA", "unit": "fahrenheit"}}
948+
]</tool_calls>"#;
949+
let config = ToolCallConfig::jamba();
956950
let (result, content) = try_tool_call_parse(input, &config).await.unwrap();
957951
assert_eq!(content, Some("".to_string()));
958952
assert!(!result.is_empty());
@@ -963,6 +957,29 @@ Remember, San Francisco weather can be quite unpredictable, particularly with it
963957
assert_eq!(args["unit"], "fahrenheit");
964958
}
965959

960+
#[tokio::test]
961+
async fn test_ai21labs_ai21_jamba_15_mini_multiple() {
962+
let input = r#"<tool_calls>[
963+
{"name": "get_weather", "arguments": {"location": "San Francisco, CA", "unit": "fahrenheit"}},
964+
{"name": "get_weather", "arguments": {"location": "New York, NY", "unit": "celsius"}}
965+
]</tool_calls>"#;
966+
let config = ToolCallConfig::jamba();
967+
let (result, content) = try_tool_call_parse(input, &config).await.unwrap();
968+
assert_eq!(content, Some("".to_string()));
969+
assert!(!result.is_empty());
970+
assert_eq!(result.len(), 2);
971+
972+
let (name, args) = extract_name_and_args(result[0].clone());
973+
assert_eq!(name, "get_weather");
974+
assert_eq!(args["location"], "San Francisco, CA");
975+
assert_eq!(args["unit"], "fahrenheit");
976+
977+
let (name, args) = extract_name_and_args(result[1].clone());
978+
assert_eq!(name, "get_weather");
979+
assert_eq!(args["location"], "New York, NY");
980+
assert_eq!(args["unit"], "celsius");
981+
}
982+
966983
#[tokio::test]
967984
#[ignore]
968985
async fn test_salesforce_llama_xlam_2_8b_fc_r_simple() {

0 commit comments

Comments
 (0)