From cf5201aada8473e367dde77adfc1c9f4b109eb5b Mon Sep 17 00:00:00 2001 From: Alexander Grimm Date: Thu, 8 May 2025 06:27:07 +0000 Subject: [PATCH 1/2] remove files from message for tasks --- backend/open_webui/utils/middleware.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 2ab73292c..146e31cad 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -977,6 +977,20 @@ async def process_chat_response( if message: messages = get_message_list(message_map, message.get("id")) + # Remove reasoning details and files from the messages. + # 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, + ).strip() + + if message.get('files'): + message['files'] = [] + if tasks and messages: if TASKS.TITLE_GENERATION in tasks: if tasks[TASKS.TITLE_GENERATION]: From a655bb5a63e9e9d7a05a84c48e083a41506400cd Mon Sep 17 00:00:00 2001 From: Alexander Grimm Date: Thu, 8 May 2025 06:51:50 +0000 Subject: [PATCH 2/2] skip checks in title gen --- backend/open_webui/routers/tasks.py | 13 +------------ backend/open_webui/utils/middleware.py | 6 +++--- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/backend/open_webui/routers/tasks.py b/backend/open_webui/routers/tasks.py index 39fca43d3..14a6c4286 100644 --- a/backend/open_webui/routers/tasks.py +++ b/backend/open_webui/routers/tasks.py @@ -186,20 +186,9 @@ async def generate_title( else: template = DEFAULT_TITLE_GENERATION_PROMPT_TEMPLATE - messages = form_data["messages"] - - # Remove reasoning details from the messages - for message in messages: - message["content"] = re.sub( - r"]*>.*?<\/details>", - "", - message["content"], - flags=re.S, - ).strip() - content = title_generation_template( template, - messages, + form_data["messages"], { "name": user.name, "location": user.info.get("location") if user.info else None, diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 146e31cad..55e3a0d92 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -978,7 +978,7 @@ async def process_chat_response( messages = get_message_list(message_map, message.get("id")) # Remove reasoning details and files from the messages. - # as get_message_list creates a new list, it does not affect + # 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( @@ -988,8 +988,8 @@ async def process_chat_response( flags=re.S, ).strip() - if message.get('files'): - message['files'] = [] + if message.get("files"): + message["files"] = [] if tasks and messages: if TASKS.TITLE_GENERATION in tasks: