Fix the GPT function calling regex to allow dash in the name (#10577)

This commit is contained in:
Antoine Roux
2025-10-12 14:34:58 +02:00
committed by GitHub
parent 1103dc6204
commit ec1cd90ac9
2 changed files with 3 additions and 3 deletions

View File

@@ -40,12 +40,12 @@ impl GptOssParser {
pub fn new() -> Self {
// Pattern for complete function calls with to= parameter
// Handles optional <|start|>assistant prefix and whitespace after function name
let function_call_pattern = r"(?s)(?:<\|start\|>assistant)?<\|channel\|>commentary to=([a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*)\s*<\|constrain\|>json<\|message\|>(.*?)<\|call\|>(?:commentary)?";
let function_call_pattern = r"(?s)(?:<\|start\|>assistant)?<\|channel\|>commentary to=([a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_-]*)*)\s*<\|constrain\|>json<\|message\|>(.*?)<\|call\|>(?:commentary)?";
let function_call_extractor =
Regex::new(function_call_pattern).expect("Valid regex pattern");
// Pattern for streaming function calls (incomplete)
let streaming_pattern = r"(?s)(?:<\|start\|>assistant)?<\|channel\|>commentary to=([a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*)\s*<\|constrain\|>json<\|message\|>(.*)";
let streaming_pattern = r"(?s)(?:<\|start\|>assistant)?<\|channel\|>commentary to=([a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_-]*)*)\s*<\|constrain\|>json<\|message\|>(.*)";
let streaming_extractor = Regex::new(streaming_pattern).expect("Valid regex pattern");
Self {