pyspur icon indicating copy to clipboard operation
pyspur copied to clipboard

Error occurred when using custom tools in workflow

Open Panda98 opened this issue 9 months ago • 3 comments

Hi,

I created a custom tool following the example from https://github.com/PySpur-Dev/pyspur/blob/main/backend/pyspur/examples/tool_function_example.py, but encountered an error when using it and running in workflow:

Traceback (most recent call last):
  File "/data/xxxxxx/venv/lib/python3.11/site-packages/pyspur/execution/workflow_executor.py", line 610, in _execute_node
    node_instance = NodeFactory.create_node(
                    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/xxxxxx/venv/lib/python3.11/site-packages/pyspur/nodes/factory.py", line 106, in create_node
    node_class = getattr(module, class_name)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'tools.weather' has no attribute 'weather_tool.node_class'

Python version: 3.11.6 PySpur version: 0.1.16

Here's my workflow:

Image

Panda98 avatar Mar 24 '25 07:03 Panda98

Temporary solution working for me is adding this to the bottom of your_custom_tool.py

setattr(sys.modules[__name__], "string_manipulator.node_class", string_manipulator.node_class)
setattr(sys.modules[__name__], "math_tool.node_class", math_tool.node_class)
setattr(sys.modules[__name__], "template_example.node_class", template_example.node_class)
setattr(sys.modules[__name__], "weather_tool.node_class", weather_tool.node_class)

Kompas avatar Apr 02 '25 22:04 Kompas

Temporary solution working for me is adding this to the bottom of your_custom_tool.py

setattr(sys.modules[__name__], "string_manipulator.node_class", string_manipulator.node_class)
setattr(sys.modules[__name__], "math_tool.node_class", math_tool.node_class)
setattr(sys.modules[__name__], "template_example.node_class", template_example.node_class)
setattr(sys.modules[__name__], "weather_tool.node_class", weather_tool.node_class)

It works! Thx

Panda98 avatar Apr 03 '25 02:04 Panda98