MCPcopy Index your code
hub / github.com/mudler/LocalAI / split_reasoning

Function split_reasoning

backend/python/common/mlx_utils.py:17–33  ·  view source on GitHub ↗

Split `` ... `` blocks out of ``text``. Returns ``(reasoning_content, remaining_text)``. When ``think_start`` is empty or not found, returns ``("", text)`` unchanged.

(text, think_start, think_end)

Source from the content-addressed store, hash-verified

15
16
17def split_reasoning(text, think_start, think_end):
18 """Split ``<think>...</think>`` blocks out of ``text``.
19
20 Returns ``(reasoning_content, remaining_text)``. When ``think_start`` is
21 empty or not found, returns ``("", text)`` unchanged.
22 """
23 if not think_start or not text or think_start not in text:
24 return "", text
25 pattern = re.compile(
26 re.escape(think_start) + r"(.*?)" + re.escape(think_end or ""),
27 re.DOTALL,
28 )
29 reasoning_parts = pattern.findall(text)
30 if not reasoning_parts:
31 return "", text
32 remaining = pattern.sub("", text).strip()
33 return "\n".join(p.strip() for p in reasoning_parts), remaining
34
35
36def parse_tool_calls(text, tool_module, tools):

Callers 7

test_split_reasoningMethod · 0.90
_finalize_outputMethod · 0.90
test_split_reasoningMethod · 0.90
_finalize_outputMethod · 0.90
test_split_reasoningMethod · 0.90
_finalize_outputMethod · 0.90

Calls 3

escapeMethod · 0.80
subMethod · 0.80
compileMethod · 0.45

Tested by 4

test_split_reasoningMethod · 0.72
test_split_reasoningMethod · 0.72
test_split_reasoningMethod · 0.72