One-time parsing: Detects and parses tool calls in the provided text. :param text: The complete text to parse. :param tools: List of available tools. :return: ParseResult indicating success or failure, consumed text, leftover text, and parsed calls.
(self, text: str, tools: List[Function])
| 305 | self.eot_token = "</tool_call>" |
| 306 | |
| 307 | def detect_and_parse(self, text: str, tools: List[Function]) -> List[ToolCallItem]: |
| 308 | """ |
| 309 | One-time parsing: Detects and parses tool calls in the provided text. |
| 310 | |
| 311 | :param text: The complete text to parse. |
| 312 | :param tools: List of available tools. |
| 313 | :return: ParseResult indicating success or failure, consumed text, leftover text, and parsed calls. |
| 314 | """ |
| 315 | if "<tool_call>" not in text: |
| 316 | return [] |
| 317 | pattern = r"<tool_call>(.*?)</tool_call>" |
| 318 | match_result_list = re.findall(pattern, text, re.DOTALL) |
| 319 | calls = [] |
| 320 | for match_result in match_result_list: |
| 321 | match_result = json.loads(match_result) |
| 322 | calls.extend(self.parse_base_json(match_result, tools)) |
| 323 | return calls |
| 324 | |
| 325 | |
| 326 | class MistralDetector(BaseFormatDetector): |
no test coverage detected