fix(llm/openai): strip <think> tags against the original chunk

Reasoning models often emit both <think> and </think> in a single streamed
chunk. The previous code truncated `content` at <think> first, then tested
the already-truncated string for </think>. The closing tag was gone, so
`is_active` was never restored to True and the entire post-</think> answer
was dropped — the user received silence.

Snapshot the chunk as `original_content` and test both tags against the
snapshot so the closing tag is still detectable after truncation.
This commit is contained in:
Brad Shannon 2026-06-17 17:56:12 -04:00
parent 071ed99a32
commit d46a4f6006

View file

@ -123,12 +123,13 @@ class LLMProvider(LLMProviderBase):
except IndexError:
content = ""
if content:
if "<think>" in content:
original_content = content
if "<think>" in original_content:
is_active = False
content = content.split("<think>")[0]
if "</think>" in content:
content = original_content.split("<think>")[0]
if "</think>" in original_content:
is_active = True
content = content.split("</think>")[-1]
content = original_content.split("</think>")[-1]
if is_active:
yield content
finally: