mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +01:00
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:
parent
071ed99a32
commit
d46a4f6006
1 changed files with 5 additions and 4 deletions
|
|
@ -123,12 +123,13 @@ class LLMProvider(LLMProviderBase):
|
||||||
except IndexError:
|
except IndexError:
|
||||||
content = ""
|
content = ""
|
||||||
if content:
|
if content:
|
||||||
if "<think>" in content:
|
original_content = content
|
||||||
|
if "<think>" in original_content:
|
||||||
is_active = False
|
is_active = False
|
||||||
content = content.split("<think>")[0]
|
content = original_content.split("<think>")[0]
|
||||||
if "</think>" in content:
|
if "</think>" in original_content:
|
||||||
is_active = True
|
is_active = True
|
||||||
content = content.split("</think>")[-1]
|
content = original_content.split("</think>")[-1]
|
||||||
if is_active:
|
if is_active:
|
||||||
yield content
|
yield content
|
||||||
finally:
|
finally:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue