fix: properly extract content before tool_calls block
- Search for the pattern in cleaned_text but extract position from original - Strip trailing markdown block markers from content - Ensure content is empty when tool_calls are present
This commit is contained in:
+10
-3
@@ -148,11 +148,18 @@ def parse_tool_calls(text: str) -> tuple:
|
||||
return text, None
|
||||
|
||||
# Find and remove the tool_calls section from text
|
||||
full_match = re.search(pattern, text, re.DOTALL)
|
||||
full_match = re.search(pattern, cleaned_text, re.DOTALL)
|
||||
if full_match:
|
||||
content = text[:full_match.start()].strip()
|
||||
# Extract content before the tool_calls block from original text
|
||||
content_end = text.find(full_match.group(0))
|
||||
if content_end > 0:
|
||||
content = text[:content_end].strip()
|
||||
# Also strip any markdown block start that might be there
|
||||
content = re.sub(r'```\w*\s*$', '', content).strip()
|
||||
else:
|
||||
content = ""
|
||||
else:
|
||||
content = text[:match.start()].strip()
|
||||
content = ""
|
||||
return content, tool_calls
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user