From d9f17225ef4de48009eed6c010afb0d627afd0cb Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Wed, 5 Feb 2025 14:26:09 -0800 Subject: [PATCH] refac --- backend/open_webui/utils/middleware.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 909a12635..06763483c 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -1172,7 +1172,7 @@ async def process_chat_response( reasoning_duration = block.get("duration", None) - if reasoning_duration: + if reasoning_duration is not None: if raw: content = f'{content}\n<{block["tag"]}>{block["content"]}\n' else: @@ -1315,6 +1315,14 @@ async def process_chat_response( "content": leftover_content, } ) + else: + content_blocks.append( + { + "type": "text", + "content": "", + } + ) + else: # Remove the block if content is empty content_blocks.pop() @@ -1326,6 +1334,13 @@ async def process_chat_response( "content": leftover_content, } ) + else: + content_blocks.append( + { + "type": "text", + "content": "", + } + ) # Clean processed content content = re.sub(