Timothy Jaeryang Baek 3 months ago
parent
commit
807b208418
1 changed files with 10 additions and 2 deletions
  1. 10 2
      backend/open_webui/utils/middleware.py

+ 10 - 2
backend/open_webui/utils/middleware.py

@@ -221,6 +221,14 @@ async def chat_completion_tools_handler(
                 except Exception as e:
                     tool_result = str(e)
 
+                tool_result_files = []
+                if isinstance(tool_result, list):
+                    for item in tool_result:
+                        # check if string
+                        if isinstance(item, str) and item.startswith("data:"):
+                            tool_result_files.append(item)
+                            tool_result.remove(item)
+
                 if isinstance(tool_result, dict) or isinstance(tool_result, list):
                     tool_result = json.dumps(tool_result, indent=2)
 
@@ -240,7 +248,7 @@ async def chat_completion_tools_handler(
                                         else f"{tool_function_name}"
                                     ),
                                 },
-                                "document": [tool_result],
+                                "document": [tool_result, *tool_result_files],
                                 "metadata": [
                                     {
                                         "source": (
@@ -256,7 +264,7 @@ async def chat_completion_tools_handler(
                         sources.append(
                             {
                                 "source": {},
-                                "document": [tool_result],
+                                "document": [tool_result, *tool_result_files],
                                 "metadata": [
                                     {
                                         "source": (