mirror of
https://github.com/hwchase17/langchain
synced 2024-11-06 03:20:49 +00:00
handle missing finish_reason (#7296)
In some cases, the OpenAI response is missing the `finish_reason` attribute. It seems to happen when using Ada or Babbage and `stream=true`, but I can't always reproduce it. This change just gracefully handles the missing key.
This commit is contained in:
parent
6ff9e9b34a
commit
1a4ca3eff9
@ -48,9 +48,9 @@ def update_token_usage(
|
||||
def _update_response(response: Dict[str, Any], stream_response: Dict[str, Any]) -> None:
|
||||
"""Update response from the stream response."""
|
||||
response["choices"][0]["text"] += stream_response["choices"][0]["text"]
|
||||
response["choices"][0]["finish_reason"] = stream_response["choices"][0][
|
||||
"finish_reason"
|
||||
]
|
||||
response["choices"][0]["finish_reason"] = stream_response["choices"][0].get(
|
||||
"finish_reason", None
|
||||
)
|
||||
response["choices"][0]["logprobs"] = stream_response["choices"][0]["logprobs"]
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user