refactor: Simplify reasoning content handling in stream processing

This commit is contained in:
Paul Gauthier 2025-03-09 08:30:56 -07:00 committed by Paul Gauthier (aider)
parent a37d6e86df
commit a15d10ea1e
2 changed files with 11 additions and 14 deletions

View file

@ -1778,31 +1778,27 @@ class Coder:
pass pass
text = "" text = ""
dump(chunk)
try: try:
reasoning_content = chunk.choices[0].delta.reasoning_content reasoning_content = chunk.choices[0].delta.reasoning_content
if reasoning_content:
if not self.got_reasoning_content:
text += f"<{self.reasoning_tag_name}>\n\n"
text += reasoning_content
self.got_reasoning_content = True
received_content = True
except AttributeError: except AttributeError:
try: try:
reasoning_content = chunk.choices[0].delta.reasoning reasoning_content = chunk.choices[0].delta.reasoning
if reasoning_content:
if not self.got_reasoning_content:
text += f"<{self.reasoning_tag_name}>\n\n"
text += reasoning_content
self.got_reasoning_content = True
received_content = True
except AttributeError: except AttributeError:
pass reasoning_content = None
if reasoning_content:
if not self.got_reasoning_content:
text += f"<{REASONING_TAG}>\n\n"
text += reasoning_content
self.got_reasoning_content = True
received_content = True
try: try:
content = chunk.choices[0].delta.content content = chunk.choices[0].delta.content
if content: if content:
if self.got_reasoning_content and not self.ended_reasoning_content: if self.got_reasoning_content and not self.ended_reasoning_content:
text += f"\n\n</{REASONING_TAG}>\n\n" text += f"\n\n</{self.reasoning_tag_name}>\n\n"
self.ended_reasoning_content = True self.ended_reasoning_content = True
text += content text += content

View file

@ -547,6 +547,7 @@
examples_as_sys_msg: true examples_as_sys_msg: true
extra_params: extra_params:
max_tokens: 8192 max_tokens: 8192
include_reasoning: true
caches_by_default: true caches_by_default: true
use_temperature: false use_temperature: false
editor_model_name: openrouter/deepseek/deepseek-chat editor_model_name: openrouter/deepseek/deepseek-chat