Fix: Correct file variable handling for custom tools in workflow (#18427)
This commit is contained in:
@@ -318,6 +318,33 @@ class ToolNode(BaseNode):
|
|||||||
json.append(message.message.json_object)
|
json.append(message.message.json_object)
|
||||||
elif message.type == ToolInvokeMessage.MessageType.LINK:
|
elif message.type == ToolInvokeMessage.MessageType.LINK:
|
||||||
assert isinstance(message.message, ToolInvokeMessage.TextMessage)
|
assert isinstance(message.message, ToolInvokeMessage.TextMessage)
|
||||||
|
|
||||||
|
if message.meta:
|
||||||
|
transfer_method = message.meta.get("transfer_method", FileTransferMethod.TOOL_FILE)
|
||||||
|
else:
|
||||||
|
transfer_method = FileTransferMethod.TOOL_FILE
|
||||||
|
|
||||||
|
tool_file_id = message.message.text.split("/")[-1].split(".")[0]
|
||||||
|
|
||||||
|
with Session(db.engine) as session:
|
||||||
|
stmt = select(ToolFile).where(ToolFile.id == tool_file_id)
|
||||||
|
tool_file = session.scalar(stmt)
|
||||||
|
if tool_file is None:
|
||||||
|
raise ToolFileError(f"Tool file {tool_file_id} does not exist")
|
||||||
|
|
||||||
|
mapping = {
|
||||||
|
"tool_file_id": tool_file_id,
|
||||||
|
"type": file_factory.get_file_type_by_mime_type(tool_file.mimetype),
|
||||||
|
"transfer_method": transfer_method,
|
||||||
|
"url": message.message.text,
|
||||||
|
}
|
||||||
|
|
||||||
|
file = file_factory.build_from_mapping(
|
||||||
|
mapping=mapping,
|
||||||
|
tenant_id=self.tenant_id,
|
||||||
|
)
|
||||||
|
files.append(file)
|
||||||
|
|
||||||
stream_text = f"Link: {message.message.text}\n"
|
stream_text = f"Link: {message.message.text}\n"
|
||||||
text += stream_text
|
text += stream_text
|
||||||
yield RunStreamChunkEvent(chunk_content=stream_text, from_variable_selector=[node_id, "text"])
|
yield RunStreamChunkEvent(chunk_content=stream_text, from_variable_selector=[node_id, "text"])
|
||||||
|
Reference in New Issue
Block a user