test_tool.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. from core.app.entities.app_invoke_entities import InvokeFrom
  2. from core.workflow.entities.variable_pool import VariablePool
  3. from core.workflow.nodes.base_node import UserFrom
  4. from core.workflow.nodes.tool.tool_node import ToolNode
  5. from models.workflow import WorkflowNodeExecutionStatus
  6. def test_tool_variable_invoke():
  7. pool = VariablePool(system_variables={}, user_inputs={}, environment_variables=[])
  8. pool.add(["1", "123", "args1"], "1+1")
  9. node = ToolNode(
  10. tenant_id="1",
  11. app_id="1",
  12. workflow_id="1",
  13. user_id="1",
  14. invoke_from=InvokeFrom.WEB_APP,
  15. user_from=UserFrom.ACCOUNT,
  16. config={
  17. "id": "1",
  18. "data": {
  19. "title": "a",
  20. "desc": "a",
  21. "provider_id": "maths",
  22. "provider_type": "builtin",
  23. "provider_name": "maths",
  24. "tool_name": "eval_expression",
  25. "tool_label": "eval_expression",
  26. "tool_configurations": {},
  27. "tool_parameters": {
  28. "expression": {
  29. "type": "variable",
  30. "value": ["1", "123", "args1"],
  31. }
  32. },
  33. },
  34. },
  35. )
  36. # execute node
  37. result = node.run(pool)
  38. assert result.status == WorkflowNodeExecutionStatus.SUCCEEDED
  39. assert "2" in result.outputs["text"]
  40. assert result.outputs["files"] == []
  41. def test_tool_mixed_invoke():
  42. pool = VariablePool(system_variables={}, user_inputs={}, environment_variables=[])
  43. pool.add(["1", "args1"], "1+1")
  44. node = ToolNode(
  45. tenant_id="1",
  46. app_id="1",
  47. workflow_id="1",
  48. user_id="1",
  49. invoke_from=InvokeFrom.WEB_APP,
  50. user_from=UserFrom.ACCOUNT,
  51. config={
  52. "id": "1",
  53. "data": {
  54. "title": "a",
  55. "desc": "a",
  56. "provider_id": "maths",
  57. "provider_type": "builtin",
  58. "provider_name": "maths",
  59. "tool_name": "eval_expression",
  60. "tool_label": "eval_expression",
  61. "tool_configurations": {},
  62. "tool_parameters": {
  63. "expression": {
  64. "type": "mixed",
  65. "value": "{{#1.args1#}}",
  66. }
  67. },
  68. },
  69. },
  70. )
  71. # execute node
  72. result = node.run(pool)
  73. assert result.status == WorkflowNodeExecutionStatus.SUCCEEDED
  74. assert "2" in result.outputs["text"]
  75. assert result.outputs["files"] == []