mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-07 05:52:15 +00:00
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:
@@ -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),
|
||||
|
Reference in New Issue
Block a user