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)
| 15 | |
| 16 | |
| 17 | def 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 | |
| 36 | def parse_tool_calls(text, tool_module, tools): |