|
|
|
@@ -1,5 +1,4 @@ |
|
|
|
from collections.abc import Mapping, Sequence |
|
|
|
from os import path |
|
|
|
from typing import Any |
|
|
|
|
|
|
|
from sqlalchemy import select |
|
|
|
@@ -180,7 +179,6 @@ class ToolNode(BaseNode[ToolNodeData]): |
|
|
|
for response in tool_response: |
|
|
|
if response.type in {ToolInvokeMessage.MessageType.IMAGE_LINK, ToolInvokeMessage.MessageType.IMAGE}: |
|
|
|
url = str(response.message) if response.message else None |
|
|
|
ext = path.splitext(url)[1] if url else ".bin" |
|
|
|
tool_file_id = str(url).split("/")[-1].split(".")[0] |
|
|
|
transfer_method = response.meta.get("transfer_method", FileTransferMethod.TOOL_FILE) |
|
|
|
|
|
|
|
@@ -202,7 +200,6 @@ class ToolNode(BaseNode[ToolNodeData]): |
|
|
|
) |
|
|
|
result.append(file) |
|
|
|
elif response.type == ToolInvokeMessage.MessageType.BLOB: |
|
|
|
# get tool file id |
|
|
|
tool_file_id = str(response.message).split("/")[-1].split(".")[0] |
|
|
|
with Session(db.engine) as session: |
|
|
|
stmt = select(ToolFile).where(ToolFile.id == tool_file_id) |
|
|
|
@@ -211,7 +208,6 @@ class ToolNode(BaseNode[ToolNodeData]): |
|
|
|
raise ValueError(f"tool file {tool_file_id} not exists") |
|
|
|
mapping = { |
|
|
|
"tool_file_id": tool_file_id, |
|
|
|
"type": FileType.IMAGE, |
|
|
|
"transfer_method": FileTransferMethod.TOOL_FILE, |
|
|
|
} |
|
|
|
file = file_factory.build_from_mapping( |
|
|
|
@@ -228,13 +224,8 @@ class ToolNode(BaseNode[ToolNodeData]): |
|
|
|
tool_file = session.scalar(stmt) |
|
|
|
if tool_file is None: |
|
|
|
raise ToolFileError(f"Tool file {tool_file_id} does not exist") |
|
|
|
if "." in url: |
|
|
|
extension = "." + url.split("/")[-1].split(".")[1] |
|
|
|
else: |
|
|
|
extension = ".bin" |
|
|
|
mapping = { |
|
|
|
"tool_file_id": tool_file_id, |
|
|
|
"type": FileType.IMAGE, |
|
|
|
"transfer_method": transfer_method, |
|
|
|
"url": url, |
|
|
|
} |