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( ai_response_text, view_message = await self._handle_final_output(
final_output, incremental=incremental final_output, incremental=incremental
) )
if text_output:
full_text = view_message full_text = view_message
# Return the incremental text # Return the incremental text
delta_text = full_text[len(previous_text) :] delta_text = full_text[len(previous_text) :]
yield delta_text if incremental else full_text result_text = delta_text if incremental else full_text
if text_output:
yield result_text
else: else:
yield ModelOutput.build( yield ModelOutput.build(
view_message, result_text,
"", "",
error_code=final_output.error_code, error_code=final_output.error_code,
usage=final_output.usage, usage=final_output.usage,