Unverified Commit ec1cd90a authored by Antoine Roux's avatar Antoine Roux Committed by GitHub
Browse files

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

parent 1103dc62
...@@ -31,7 +31,7 @@ class GptOssDetector(BaseFormatDetector): ...@@ -31,7 +31,7 @@ class GptOssDetector(BaseFormatDetector):
# Pattern to extract function name and JSON from tool_call event content # Pattern to extract function name and JSON from tool_call event content
self.tool_extract_pattern = re.compile( self.tool_extract_pattern = re.compile(
r"to=([a-zA-Z_][a-zA-Z0-9_.]*)\s*<\|constrain\|>json<\|message\|>(.*?)(?:<\|call\|>|$)", r"to=([a-zA-Z_][a-zA-Z0-9_.-]*)\s*<\|constrain\|>json<\|message\|>(.*?)(?:<\|call\|>|$)",
re.DOTALL, re.DOTALL,
) )
......
...@@ -40,12 +40,12 @@ impl GptOssParser { ...@@ -40,12 +40,12 @@ impl GptOssParser {
pub fn new() -> Self { pub fn new() -> Self {
// Pattern for complete function calls with to= parameter // Pattern for complete function calls with to= parameter
// Handles optional <|start|>assistant prefix and whitespace after function name // 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 = let function_call_extractor =
Regex::new(function_call_pattern).expect("Valid regex pattern"); Regex::new(function_call_pattern).expect("Valid regex pattern");
// Pattern for streaming function calls (incomplete) // 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"); let streaming_extractor = Regex::new(streaming_pattern).expect("Valid regex pattern");
Self { Self {
......
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