openai[patch]: guard against None text completions in BaseOpenAI (#31514)

Some chat completions APIs will return null `text` output (even though
this is typed as string).
This commit is contained in:
ccurme
2025-06-06 09:14:37 -04:00
committed by GitHub
parent abc8bf9f1c
commit 4cc2f6b807
2 changed files with 38 additions and 1 deletions

View File

@@ -40,7 +40,7 @@ def _stream_response_to_generation_chunk(
if not stream_response["choices"]:
return GenerationChunk(text="")
return GenerationChunk(
text=stream_response["choices"][0]["text"],
text=stream_response["choices"][0]["text"] or "",
generation_info=dict(
finish_reason=stream_response["choices"][0].get("finish_reason", None),
logprobs=stream_response["choices"][0].get("logprobs", None),