node_entities.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. from collections.abc import Mapping
  2. from enum import Enum
  3. from typing import Any, Optional
  4. from pydantic import BaseModel
  5. from models import WorkflowNodeExecutionStatus
  6. class NodeType(Enum):
  7. """
  8. Node Types.
  9. """
  10. START = 'start'
  11. END = 'end'
  12. ANSWER = 'answer'
  13. LLM = 'llm'
  14. KNOWLEDGE_RETRIEVAL = 'knowledge-retrieval'
  15. IF_ELSE = 'if-else'
  16. CODE = 'code'
  17. TEMPLATE_TRANSFORM = 'template-transform'
  18. QUESTION_CLASSIFIER = 'question-classifier'
  19. HTTP_REQUEST = 'http-request'
  20. TOOL = 'tool'
  21. VARIABLE_AGGREGATOR = 'variable-aggregator'
  22. # TODO: merge this into VARIABLE_AGGREGATOR
  23. VARIABLE_ASSIGNER = 'variable-assigner'
  24. LOOP = 'loop'
  25. ITERATION = 'iteration'
  26. PARAMETER_EXTRACTOR = 'parameter-extractor'
  27. CONVERSATION_VARIABLE_ASSIGNER = 'assigner'
  28. @classmethod
  29. def value_of(cls, value: str) -> 'NodeType':
  30. """
  31. Get value of given node type.
  32. :param value: node type value
  33. :return: node type
  34. """
  35. for node_type in cls:
  36. if node_type.value == value:
  37. return node_type
  38. raise ValueError(f'invalid node type value {value}')
  39. class NodeRunMetadataKey(Enum):
  40. """
  41. Node Run Metadata Key.
  42. """
  43. TOTAL_TOKENS = 'total_tokens'
  44. TOTAL_PRICE = 'total_price'
  45. CURRENCY = 'currency'
  46. TOOL_INFO = 'tool_info'
  47. ITERATION_ID = 'iteration_id'
  48. ITERATION_INDEX = 'iteration_index'
  49. class NodeRunResult(BaseModel):
  50. """
  51. Node Run Result.
  52. """
  53. status: WorkflowNodeExecutionStatus = WorkflowNodeExecutionStatus.RUNNING
  54. inputs: Optional[Mapping[str, Any]] = None # node inputs
  55. process_data: Optional[dict] = None # process data
  56. outputs: Optional[Mapping[str, Any]] = None # node outputs
  57. metadata: Optional[dict[NodeRunMetadataKey, Any]] = None # node metadata
  58. edge_source_handle: Optional[str] = None # source handle id of node with multiple branches
  59. error: Optional[str] = None # error message if status is failed