Unverified Commit 466992b2 authored by Chang Su's avatar Chang Su Committed by GitHub
Browse files

[router][tool call] Clean up redundant `detect_format` and `has_tool_markers` (#11270)

parent 155cbb51
......@@ -116,10 +116,10 @@ async fn test_llama_empty_arguments() {
async fn test_llama_format_detection() {
let parser = LlamaParser::new();
assert!(parser.detect_format(r#"<|python_tag|>{"name": "test"}"#));
assert!(parser.detect_format(r#"{"name": "test", "parameters": {}}"#));
assert!(!parser.detect_format("plain text"));
assert!(!parser.detect_format(r#"{"key": "value"}"#)); // No name field
assert!(parser.has_tool_markers(r#"<|python_tag|>{"name": "test"}"#));
assert!(parser.has_tool_markers(r#"{"name": "test", "parameters": {}}"#));
assert!(!parser.has_tool_markers("plain text"));
assert!(!parser.has_tool_markers(r#"{"key": "value"}"#)); // No name field
}
#[tokio::test]
......
......@@ -96,10 +96,10 @@ async fn test_mistral_with_brackets_in_strings() {
async fn test_mistral_format_detection() {
let parser = MistralParser::new();
assert!(parser.detect_format("[TOOL_CALLS] ["));
assert!(parser.detect_format("Some text [TOOL_CALLS] ["));
assert!(!parser.detect_format("Just plain text"));
assert!(!parser.detect_format("[{\"name\": \"test\"}]")); // JSON array without TOOL_CALLS
assert!(parser.has_tool_markers("[TOOL_CALLS] ["));
assert!(parser.has_tool_markers("Some text [TOOL_CALLS] ["));
assert!(!parser.has_tool_markers("Just plain text"));
assert!(!parser.has_tool_markers("[{\"name\": \"test\"}]")); // JSON array without TOOL_CALLS
}
#[tokio::test]
......
......@@ -125,10 +125,10 @@ async fn test_pythonic_empty_arguments() {
async fn test_pythonic_format_detection() {
let parser = PythonicParser::new();
assert!(!parser.detect_format("[function_name(")); // Incomplete
assert!(parser.detect_format("[get_weather(city=\"NYC\")]"));
assert!(!parser.detect_format("Just plain text"));
assert!(!parser.detect_format("{\"name\": \"test\"}")); // JSON
assert!(!parser.has_tool_markers("[function_name(")); // Incomplete
assert!(parser.has_tool_markers("[get_weather(city=\"NYC\")]"));
assert!(!parser.has_tool_markers("Just plain text"));
assert!(!parser.has_tool_markers("{\"name\": \"test\"}")); // JSON
}
#[tokio::test]
......
......@@ -120,10 +120,10 @@ async fn test_qwen_with_newlines_in_strings() {
async fn test_qwen_format_detection() {
let parser = QwenParser::new();
assert!(parser.detect_format("<tool_call>"));
assert!(parser.detect_format("Some text <tool_call>\n{"));
assert!(!parser.detect_format("Just plain text"));
assert!(!parser.detect_format("{\"name\": \"test\"}")); // Plain JSON
assert!(parser.has_tool_markers("<tool_call>"));
assert!(parser.has_tool_markers("Some text <tool_call>\n{"));
assert!(!parser.has_tool_markers("Just plain text"));
assert!(!parser.has_tool_markers("{\"name\": \"test\"}")); // Plain JSON
}
#[tokio::test]
......
......@@ -111,13 +111,13 @@ fn test_step3_format_detection() {
let parser = Step3Parser::new();
// Should detect Step3 format
assert!(parser.detect_format("<|tool_calls_begin|>"));
assert!(parser.detect_format("text with <|tool_calls_begin|> marker"));
assert!(parser.has_tool_markers("<|tool_calls_begin|>"));
assert!(parser.has_tool_markers("text with <|tool_calls_begin|> marker"));
// Should not detect other formats
assert!(!parser.detect_format("[TOOL_CALLS]"));
assert!(!parser.detect_format("<tool_call>"));
assert!(!parser.detect_format("plain text"));
assert!(!parser.has_tool_markers("[TOOL_CALLS]"));
assert!(!parser.has_tool_markers("<tool_call>"));
assert!(!parser.has_tool_markers("plain text"));
}
#[tokio::test]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment