node_entities.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. from enum import Enum
  2. from typing import Any, Optional
  3. from pydantic import BaseModel
  4. from models.workflow import WorkflowNodeExecutionStatus
  5. class NodeType(Enum):
  6. """
  7. Node Types.
  8. """
  9. START = 'start'
  10. END = 'end'
  11. ANSWER = 'answer'
  12. LLM = 'llm'
  13. KNOWLEDGE_RETRIEVAL = 'knowledge-retrieval'
  14. IF_ELSE = 'if-else'
  15. CODE = 'code'
  16. TEMPLATE_TRANSFORM = 'template-transform'
  17. QUESTION_CLASSIFIER = 'question-classifier'
  18. HTTP_REQUEST = 'http-request'
  19. TOOL = 'tool'
  20. VARIABLE_ASSIGNER = 'variable-assigner'
  21. @classmethod
  22. def value_of(cls, value: str) -> 'NodeType':
  23. """
  24. Get value of given node type.
  25. :param value: node type value
  26. :return: node type
  27. """
  28. for node_type in cls:
  29. if node_type.value == value:
  30. return node_type
  31. raise ValueError(f'invalid node type value {value}')
  32. class SystemVariable(Enum):
  33. """
  34. System Variables.
  35. """
  36. QUERY = 'query'
  37. FILES = 'files'
  38. CONVERSATION = 'conversation'
  39. @classmethod
  40. def value_of(cls, value: str) -> 'SystemVariable':
  41. """
  42. Get value of given system variable.
  43. :param value: system variable value
  44. :return: system variable
  45. """
  46. for system_variable in cls:
  47. if system_variable.value == value:
  48. return system_variable
  49. raise ValueError(f'invalid system variable value {value}')
  50. class NodeRunMetadataKey(Enum):
  51. """
  52. Node Run Metadata Key.
  53. """
  54. TOTAL_TOKENS = 'total_tokens'
  55. TOTAL_PRICE = 'total_price'
  56. CURRENCY = 'currency'
  57. TOOL_INFO = 'tool_info'
  58. class NodeRunResult(BaseModel):
  59. """
  60. Node Run Result.
  61. """
  62. status: WorkflowNodeExecutionStatus = WorkflowNodeExecutionStatus.RUNNING
  63. inputs: Optional[dict] = None # node inputs
  64. process_data: Optional[dict] = None # process data
  65. outputs: Optional[dict] = None # node outputs
  66. metadata: Optional[dict[NodeRunMetadataKey, Any]] = None # node metadata
  67. edge_source_handle: Optional[str] = None # source handle id of node with multiple branches
  68. error: Optional[str] = None # error message if status is failed