Skip to content

Commit 807b208

Browse files
committed
refac
1 parent ae484e8 commit 807b208

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

backend/open_webui/utils/middleware.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ async def tool_call_handler(tool_call):
221221
except Exception as e:
222222
tool_result = str(e)
223223

224+
tool_result_files = []
225+
if isinstance(tool_result, list):
226+
for item in tool_result:
227+
# check if string
228+
if isinstance(item, str) and item.startswith("data:"):
229+
tool_result_files.append(item)
230+
tool_result.remove(item)
231+
224232
if isinstance(tool_result, dict) or isinstance(tool_result, list):
225233
tool_result = json.dumps(tool_result, indent=2)
226234

@@ -240,7 +248,7 @@ async def tool_call_handler(tool_call):
240248
else f"{tool_function_name}"
241249
),
242250
},
243-
"document": [tool_result],
251+
"document": [tool_result, *tool_result_files],
244252
"metadata": [
245253
{
246254
"source": (
@@ -256,7 +264,7 @@ async def tool_call_handler(tool_call):
256264
sources.append(
257265
{
258266
"source": {},
259-
"document": [tool_result],
267+
"document": [tool_result, *tool_result_files],
260268
"metadata": [
261269
{
262270
"source": (

0 commit comments

Comments
 (0)