diff --git a/strix/llm/llm.py b/strix/llm/llm.py index c27ac042..d166dfd4 100644 --- a/strix/llm/llm.py +++ b/strix/llm/llm.py @@ -1,4 +1,5 @@ import asyncio +import re from collections.abc import AsyncIterator from dataclasses import dataclass from typing import Any @@ -188,7 +189,10 @@ class LLM: delta = self._get_chunk_content(chunk) if delta: accumulated += delta - if "" in accumulated or "" in accumulated: + check_content = re.sub( + r"]*>.*?", "", accumulated, flags=re.DOTALL + ) + if "" in check_content or "" in check_content: end_tag = "" if "" in accumulated else "" pos = accumulated.find(end_tag) accumulated = accumulated[: pos + len(end_tag)] @@ -203,11 +207,7 @@ class LLM: accumulated = normalize_tool_format(accumulated) accumulated = fix_incomplete_tool_call(_truncate_to_first_function(accumulated)) - thinking_content = "" - for match in re.finditer(r"]*>(.*?)", accumulated, re.DOTALL): - thinking_content += match.group(1) + "\n" - if thinking_content: - accumulated = accumulated.replace(thinking_content, "") + accumulated = re.sub(r"]*>.*?", "", accumulated, flags=re.DOTALL) yield LLMResponse( content=accumulated, diff --git a/strix/llm/utils.py b/strix/llm/utils.py index 314eee22..0f56bedf 100644 --- a/strix/llm/utils.py +++ b/strix/llm/utils.py @@ -20,7 +20,12 @@ def normalize_tool_format(content: str) -> str: """ - if "