mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 04:15:25 +00:00
refac
This commit is contained in:
parent
6920fed97e
commit
2fa222d00a
2 changed files with 32 additions and 13 deletions
|
|
@ -2545,21 +2545,33 @@ async def process_chat_response(
|
|||
else:
|
||||
tool_result = tool_result.body.decode("utf-8")
|
||||
|
||||
elif tool.get("type") == "external" and isinstance(
|
||||
tool_result, tuple
|
||||
elif (
|
||||
tool.get("type") == "external"
|
||||
and isinstance(tool_result, tuple)
|
||||
) or (
|
||||
tool.get("direct", True)
|
||||
and isinstance(tool_result, list)
|
||||
and len(tool_result) == 2
|
||||
):
|
||||
tool_result, tool_response_headers = tool_result
|
||||
|
||||
if tool_response_headers:
|
||||
content_disposition = tool_response_headers.get(
|
||||
"Content-Disposition", ""
|
||||
"Content-Disposition",
|
||||
tool_response_headers.get(
|
||||
"content-disposition", ""
|
||||
),
|
||||
)
|
||||
|
||||
if "inline" in content_disposition:
|
||||
content_type = tool_response_headers.get(
|
||||
"Content-Type", ""
|
||||
"Content-Type",
|
||||
tool_response_headers.get("content-type", ""),
|
||||
)
|
||||
location = tool_response_headers.get(
|
||||
"Location",
|
||||
tool_response_headers.get("location", ""),
|
||||
)
|
||||
location = tool_response_headers.get("Location", "")
|
||||
|
||||
if "text/html" in content_type:
|
||||
# Display as iframe embed
|
||||
|
|
|
|||
|
|
@ -493,18 +493,25 @@ export const executeToolServer = async (
|
|||
throw new Error(`HTTP error! Status: ${res.status}. Message: ${resText}`);
|
||||
}
|
||||
|
||||
let responseData;
|
||||
try {
|
||||
responseData = await res.json();
|
||||
} catch (err) {
|
||||
responseData = await res.text();
|
||||
}
|
||||
// make a clone of res and extract headers
|
||||
const responseHeaders = {};
|
||||
res.headers.forEach((value, key) => {
|
||||
responseHeaders[key] = value;
|
||||
});
|
||||
|
||||
return responseData;
|
||||
const text = await res.text();
|
||||
let responseData;
|
||||
|
||||
try {
|
||||
responseData = JSON.parse(text);
|
||||
} catch {
|
||||
responseData = text;
|
||||
}
|
||||
return [responseData, responseHeaders];
|
||||
} catch (err: any) {
|
||||
error = err.message;
|
||||
console.error('API Request Error:', error);
|
||||
return { error };
|
||||
return [{ error }, null];
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue