Skip to content

Commit 0343a26

Browse files
committed
fix: update harmony end logic
Signed-off-by: ayushag <ayushag@nvidia.com>
1 parent abfec30 commit 0343a26

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/parsers/src/tool_calling/harmony/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@
33

44
pub mod harmony_parser;
55

6+
pub use super::config::JsonParserConfig;
67
pub use super::{config, response};
78
pub use harmony_parser::{
89
detect_tool_call_start_harmony, parse_tool_calls_harmony, parse_tool_calls_harmony_complete,
910
};
1011

11-
pub fn find_tool_call_end_position_harmony(chunk: &str) -> usize {
12-
chunk.len()
12+
pub fn find_tool_call_end_position_harmony(chunk: &str, config: &JsonParserConfig) -> usize {
13+
let end_token = config
14+
.tool_call_end_tokens
15+
.first()
16+
.map_or("<|call|>", |v| v);
17+
if let Some(pos) = chunk.rfind(end_token) {
18+
pos + end_token.len()
19+
} else {
20+
chunk.len()
21+
}
1322
}

lib/parsers/src/tool_calling/parsers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub fn find_tool_call_end_position(chunk: &str, parser_str: Option<&str>) -> usi
142142
};
143143
find_tool_call_end_position_json(chunk, effective_parser, &config.json)
144144
}
145-
ToolCallParserType::Harmony => find_tool_call_end_position_harmony(chunk),
145+
ToolCallParserType::Harmony => find_tool_call_end_position_harmony(chunk, &config.json),
146146
ToolCallParserType::Pythonic => find_tool_call_end_position_pythonic(chunk),
147147
ToolCallParserType::Typescript => {
148148
// Typescript parser not implemented

0 commit comments

Comments
 (0)