From e1435501aa6237675c8b9d88c7eb98c440978841 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Thu, 13 Feb 2025 15:17:41 -0800 Subject: [PATCH] fix --- backend/open_webui/utils/chat.py | 1 + backend/open_webui/utils/middleware.py | 15 ++++++++------- backend/open_webui/utils/misc.py | 9 +++++---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/backend/open_webui/utils/chat.py b/backend/open_webui/utils/chat.py index 58cd2baba..697626dc5 100644 --- a/backend/open_webui/utils/chat.py +++ b/backend/open_webui/utils/chat.py @@ -161,6 +161,7 @@ async def generate_chat_completion( user: Any, bypass_filter: bool = False, ): + log.debug(f"generate_chat_completion: {form_data}") if BYPASS_MODEL_ACCESS_CONTROL: bypass_filter = True diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index b15a71b92..4e4ba8d30 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -1180,12 +1180,14 @@ async def process_chat_response( temp_blocks.append(block) if temp_blocks: - messages.append( - { - "role": "assistant", - "content": serialize_content_blocks(temp_blocks), - } - ) + content = serialize_content_blocks(temp_blocks) + if content: + messages.append( + { + "role": "assistant", + "content": content, + } + ) return messages @@ -1580,7 +1582,6 @@ async def process_chat_response( results = [] for tool_call in response_tool_calls: - print("\n\n" + str(tool_call) + "\n\n") tool_call_id = tool_call.get("id", "") tool_name = tool_call.get("function", {}).get("name", "") diff --git a/backend/open_webui/utils/misc.py b/backend/open_webui/utils/misc.py index 4eace24dc..f79b62684 100644 --- a/backend/open_webui/utils/misc.py +++ b/backend/open_webui/utils/misc.py @@ -225,10 +225,11 @@ def openai_chat_completion_message_template( template = openai_chat_message_template(model) template["object"] = "chat.completion" if message is not None: - template["choices"][0]["message"] = {"content": message, "role": "assistant"} - - if tool_calls: - template["choices"][0]["tool_calls"] = tool_calls + template["choices"][0]["message"] = { + "content": message, + "role": "assistant", + **({"tool_calls": tool_calls} if tool_calls else {}), + } template["choices"][0]["finish_reason"] = "stop"