MCPcopy
hub / github.com/ModelTC/LightLLM / detect_and_parse

Method detect_and_parse

lightllm/server/function_call_parser.py:359–376  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

357 return ""
358
359 def detect_and_parse(self, text: str, tools: List[Function]) -> List[ToolCallItem]:
360 """
361 One-time parsing: Detects and parses tool calls in the provided text.
362
363 :param text: The complete text to parse.
364 :param tools: List of available tools.
365 :return: ParseResult indicating success or failure, consumed text, leftover text, and parsed calls.
366 """
367 text = self._clean_text(text)
368 tool_content = text.replace("[TOOL_CALLS]", "").strip()
369 raw_tool_calls = self.tool_call_regex.findall(tool_content)
370 calls = []
371 if len(raw_tool_calls) > 0:
372 raw_tool_call = raw_tool_calls[0]
373 function_call_arr = json.loads(raw_tool_call)
374 for match_result in function_call_arr:
375 calls.extend(self.parse_base_json(match_result, tools))
376 return calls
377
378
379class Llama32Detector(BaseFormatDetector):

Callers

nothing calls this directly

Calls 3

_clean_textMethod · 0.95
parse_base_jsonMethod · 0.80
extendMethod · 0.45

Tested by

no test coverage detected