MCPcopy Index your code
hub / github.com/ModelTC/LightLLM / _clean_text

Method _clean_text

lightllm/server/function_call_parser.py:341–357  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 """

Callers 1

detect_and_parseMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected