From 00d628544ce9ef405c52fd78ef2437d7417afaf6 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Mon, 26 Feb 2024 08:59:55 -0800 Subject: [PATCH] fix(utils.py): fix vertex ai finish reason handling --- litellm/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/litellm/utils.py b/litellm/utils.py index 7de5199b46..0e718d31a3 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -8538,7 +8538,11 @@ class CustomStreamWrapper: if hasattr(chunk, "candidates") == True: try: completion_obj["content"] = chunk.text - if hasattr(chunk.candidates[0], "finish_reason"): + if ( + hasattr(chunk.candidates[0], "finish_reason") + and chunk.candidates[0].finish_reason.name + != "FINISH_REASON_UNSPECIFIED" + ): # every non-final chunk in vertex ai has this model_response.choices[0].finish_reason = ( map_finish_reason( chunk.candidates[0].finish_reason.name