fix(chat): Fix chat completions API error (#2443)

This commit is contained in:
Fangyin Cheng 2025-03-12 08:40:40 +08:00 committed by GitHub
parent 528c0c88d5
commit ee1ac0df8e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -374,14 +374,15 @@ class BaseChat(ABC):
ai_response_text, view_message = await self._handle_final_output(
final_output, incremental=incremental
)
full_text = view_message
# Return the incremental text
delta_text = full_text[len(previous_text) :]
result_text = delta_text if incremental else full_text
if text_output:
full_text = view_message
# Return the incremental text
delta_text = full_text[len(previous_text) :]
yield delta_text if incremental else full_text
yield result_text
else:
yield ModelOutput.build(
view_message,
result_text,
"",
error_code=final_output.error_code,
usage=final_output.usage,