From 528a2cf96a8bef32fd9f8fdc8467908b52895a3a Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Fri, 16 May 2025 18:19:28 +0400 Subject: [PATCH] refac --- backend/open_webui/utils/middleware.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 21495f04a..323fd200a 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -953,15 +953,25 @@ async def process_chat_response( # as get_message_list creates a new list, it does not affect # the original messages outside of this handler for message in messages: - message["content"] = re.sub( - r"]*>.*?<\/details>", - "", - message["content"], - flags=re.S | re.I, - ).strip() + content = message.get("content", "") + if isinstance(content, list): + for item in content: + if item.get("type") == "text": + content = item["text"] + break - if message.get("files"): - message["files"] = [] + if isinstance(content, str): + content = re.sub( + r"]*>.*?<\/details>", + "", + content, + flags=re.S | re.I, + ).strip() + + message = { + "role": message["role"], + "content": content, + } if tasks and messages: if TASKS.TITLE_GENERATION in tasks: