From 21abe43f3b1cbbed15e079e8c71981e107966bbf Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Fri, 10 Jan 2025 16:27:37 -0800 Subject: [PATCH] refac --- backend/open_webui/utils/middleware.py | 34 +++++++++++++++----------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 3c53435a4..77628dee5 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -770,14 +770,17 @@ async def process_chat_response( ) if res and isinstance(res, dict): - title = ( - res.get("choices", [])[0] - .get("message", {}) - .get( - "content", - message.get("content", "New Chat"), - ) - ).strip() + if len(res.get("choices", [])) == 1: + title = ( + res.get("choices", [])[0] + .get("message", {}) + .get( + "content", + message.get("content", "New Chat"), + ) + ).strip() + else: + title = None if not title: title = messages[0].get("content", "New Chat") @@ -814,11 +817,14 @@ async def process_chat_response( ) if res and isinstance(res, dict): - tags_string = ( - res.get("choices", [])[0] - .get("message", {}) - .get("content", "") - ) + if len(res.get("choices", [])) == 1: + tags_string = ( + res.get("choices", [])[0] + .get("message", {}) + .get("content", "") + ) + else: + tags_string = "" tags_string = tags_string[ tags_string.find("{") : tags_string.rfind("}") + 1 @@ -837,7 +843,7 @@ async def process_chat_response( } ) except Exception as e: - print(f"Error: {e}") + pass event_emitter = None if (