Timothy Jaeryang Baek 2 月之前
父节点
当前提交
31c176a485
共有 1 个文件被更改,包括 12 次插入3 次删除
  1. 12 3
      backend/open_webui/utils/middleware.py

+ 12 - 3
backend/open_webui/utils/middleware.py

@@ -1107,9 +1107,15 @@ async def process_chat_response(
                         reasoning_duration = block.get("duration", None)
 
                         if reasoning_duration:
-                            content = f'{content}<details type="reasoning" done="true" duration="{reasoning_duration}">\n<summary>Thought for {reasoning_duration} seconds</summary>\n{reasoning_display_content}\n</details>\n'
+                            if raw:
+                                content = f'{content}<{block["tag"]}>{block["content"]}</{block["tag"]}>\n'
+                            else:
+                                content = f'{content}<details type="reasoning" done="true" duration="{reasoning_duration}">\n<summary>Thought for {reasoning_duration} seconds</summary>\n{reasoning_display_content}\n</details>\n'
                         else:
-                            content = f'{content}<details type="reasoning" done="false">\n<summary>Thinking…</summary>\n{reasoning_display_content}\n</details>\n'
+                            if raw:
+                                content = f'{content}<{block["tag"]}>{block["content"]}</{block["tag"]}>\n'
+                            else:
+                                content = f'{content}<details type="reasoning" done="false">\n<summary>Thinking…</summary>\n{reasoning_display_content}\n</details>\n'
 
                     elif block["type"] == "code_interpreter":
                         attributes = block.get("attributes", {})
@@ -1124,7 +1130,10 @@ async def process_chat_response(
                             else:
                                 content = f'{content}<details type="code_interpreter" done="true" output="{output}">\n<summary>Analyzed</summary>\n```{lang}\n{block["content"]}\n```\n</details>\n'
                         else:
-                            content = f'{content}<details type="code_interpreter" done="false">\n<summary>Analyzing...</summary>\n```{lang}\n{block["content"]}\n```\n</details>\n'
+                            if raw:
+                                content = f'{content}<code_interpreter type="code" lang="{lang}">\n{block["content"]}\n</code_interpreter>\n'
+                            else:
+                                content = f'{content}<details type="code_interpreter" done="false">\n<summary>Analyzing...</summary>\n```{lang}\n{block["content"]}\n```\n</details>\n'
 
                     else:
                         block_content = str(block["content"]).strip()