clean text to only leave ''[TOOL_CALLS] [{"name": xxx, "arguments": {xxx}}]' for example, text = '[TOOL_CALLS] [{"name": "get_current_weather", "arguments": {"location": "Boston, MA", "unit": "fahrenheit"}}]\n\n Today\'s weather in Boston
(self, text: str)
| 339 | self.tool_call_regex = re.compile(r"\[{.*}\]", re.DOTALL) |
| 340 | |
| 341 | def _clean_text(self, text: str) -> str: |
| 342 | """ |
| 343 | clean text to only leave ''[TOOL_CALLS] [{"name": xxx, "arguments": {xxx}}]' |
| 344 | for example, |
| 345 | text = '[TOOL_CALLS] [{"name": "get_current_weather", |
| 346 | "arguments": {"location": "Boston, MA", "unit": "fahrenheit"}}]\n\n |
| 347 | Today\'s weather in Boston is :{function call result} (in Fahrenheit)\n\n |
| 348 | If you prefer Celsius, please let me know.' |
| 349 | return '[TOOL_CALLS] [{"name": "get_current_weather", |
| 350 | "arguments": {"location": "Boston, MA", "unit": "fahrenheit"}}]' |
| 351 | The key pattern is [TOOL_CALLS] [...] |
| 352 | """ |
| 353 | find_results = re.findall(r"\[TOOL_CALLS\] \[.*?\]", text, re.DOTALL) |
| 354 | if len(find_results) > 0: |
| 355 | return find_results[0] |
| 356 | else: |
| 357 | return "" |
| 358 | |
| 359 | def detect_and_parse(self, text: str, tools: List[Function]) -> List[ToolCallItem]: |
| 360 | """ |