瀏覽代碼

enh: check for reasoning tags

Timothy Jaeryang Baek 3 月之前
父節點
當前提交
08ad4ee018
共有 1 個文件被更改,包括 15 次插入1 次删除
  1. 15 1
      backend/open_webui/routers/tasks.py

+ 15 - 1
backend/open_webui/routers/tasks.py

@@ -4,6 +4,7 @@ from fastapi.responses import JSONResponse, RedirectResponse
 from pydantic import BaseModel
 from pydantic import BaseModel
 from typing import Optional
 from typing import Optional
 import logging
 import logging
+import re
 
 
 from open_webui.utils.chat import generate_chat_completion
 from open_webui.utils.chat import generate_chat_completion
 from open_webui.utils.task import (
 from open_webui.utils.task import (
@@ -161,9 +162,22 @@ async def generate_title(
     else:
     else:
         template = DEFAULT_TITLE_GENERATION_PROMPT_TEMPLATE
         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\s+type=\"reasoning\"[^>]*>.*?<\/details>",
+            "",
+            message["content"],
+            flags=re.S,
+        ).strip()
+
+    print(messages)
+
     content = title_generation_template(
     content = title_generation_template(
         template,
         template,
-        form_data["messages"],
+        messages,
         {
         {
             "name": user.name,
             "name": user.name,
             "location": user.info.get("location") if user.info else None,
             "location": user.info.get("location") if user.info else None,