From a20abe2d33fe03202f7f10b65ab55b129c1f05d3 Mon Sep 17 00:00:00 2001 From: Benjamin Oldenburg Date: Sun, 16 Mar 2025 07:31:21 +0700 Subject: [PATCH] Bugfix: Chat completion requests fail with UnboundLocalError: finish_reason variable not initialized (#307) * fix issue #306 * removed whitespaces for ruff --- endpoints/OAI/utils/chat_completion.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/endpoints/OAI/utils/chat_completion.py b/endpoints/OAI/utils/chat_completion.py index 9393e90..2326bc2 100644 --- a/endpoints/OAI/utils/chat_completion.py +++ b/endpoints/OAI/utils/chat_completion.py @@ -74,7 +74,9 @@ def _create_response( logprob_response = ChatCompletionLogprobs(content=collected_token_probs) - # Finish reason will always be present in a completion + # Initialize finish_reason with a default value or from generation data + finish_reason = generation.get("finish_reason", "stop") + # If a tool call is present, mark the finish reason as such if message.tool_calls: finish_reason = "tool_calls"