vellum-ai 0.9.16rc2__py3-none-any.whl → 0.9.16rc4__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (245) hide show
  1. vellum/plugins/__init__.py +0 -0
  2. vellum/plugins/pydantic.py +74 -0
  3. vellum/plugins/utils.py +19 -0
  4. vellum/plugins/vellum_mypy.py +639 -3
  5. vellum/workflows/README.md +90 -0
  6. vellum/workflows/__init__.py +5 -0
  7. vellum/workflows/constants.py +43 -0
  8. vellum/workflows/descriptors/__init__.py +0 -0
  9. vellum/workflows/descriptors/base.py +339 -0
  10. vellum/workflows/descriptors/tests/test_utils.py +83 -0
  11. vellum/workflows/descriptors/utils.py +90 -0
  12. vellum/workflows/edges/__init__.py +5 -0
  13. vellum/workflows/edges/edge.py +23 -0
  14. vellum/workflows/emitters/__init__.py +5 -0
  15. vellum/workflows/emitters/base.py +14 -0
  16. vellum/workflows/environment/__init__.py +5 -0
  17. vellum/workflows/environment/environment.py +7 -0
  18. vellum/workflows/errors/__init__.py +6 -0
  19. vellum/workflows/errors/types.py +20 -0
  20. vellum/workflows/events/__init__.py +31 -0
  21. vellum/workflows/events/node.py +125 -0
  22. vellum/workflows/events/tests/__init__.py +0 -0
  23. vellum/workflows/events/tests/test_event.py +216 -0
  24. vellum/workflows/events/types.py +52 -0
  25. vellum/workflows/events/utils.py +5 -0
  26. vellum/workflows/events/workflow.py +139 -0
  27. vellum/workflows/exceptions.py +15 -0
  28. vellum/workflows/expressions/__init__.py +0 -0
  29. vellum/workflows/expressions/accessor.py +52 -0
  30. vellum/workflows/expressions/and_.py +32 -0
  31. vellum/workflows/expressions/begins_with.py +31 -0
  32. vellum/workflows/expressions/between.py +38 -0
  33. vellum/workflows/expressions/coalesce_expression.py +41 -0
  34. vellum/workflows/expressions/contains.py +30 -0
  35. vellum/workflows/expressions/does_not_begin_with.py +31 -0
  36. vellum/workflows/expressions/does_not_contain.py +30 -0
  37. vellum/workflows/expressions/does_not_end_with.py +31 -0
  38. vellum/workflows/expressions/does_not_equal.py +25 -0
  39. vellum/workflows/expressions/ends_with.py +31 -0
  40. vellum/workflows/expressions/equals.py +25 -0
  41. vellum/workflows/expressions/greater_than.py +33 -0
  42. vellum/workflows/expressions/greater_than_or_equal_to.py +33 -0
  43. vellum/workflows/expressions/in_.py +31 -0
  44. vellum/workflows/expressions/is_blank.py +24 -0
  45. vellum/workflows/expressions/is_not_blank.py +24 -0
  46. vellum/workflows/expressions/is_not_null.py +21 -0
  47. vellum/workflows/expressions/is_not_undefined.py +22 -0
  48. vellum/workflows/expressions/is_null.py +21 -0
  49. vellum/workflows/expressions/is_undefined.py +22 -0
  50. vellum/workflows/expressions/less_than.py +33 -0
  51. vellum/workflows/expressions/less_than_or_equal_to.py +33 -0
  52. vellum/workflows/expressions/not_between.py +38 -0
  53. vellum/workflows/expressions/not_in.py +31 -0
  54. vellum/workflows/expressions/or_.py +32 -0
  55. vellum/workflows/graph/__init__.py +3 -0
  56. vellum/workflows/graph/graph.py +131 -0
  57. vellum/workflows/graph/tests/__init__.py +0 -0
  58. vellum/workflows/graph/tests/test_graph.py +437 -0
  59. vellum/workflows/inputs/__init__.py +5 -0
  60. vellum/workflows/inputs/base.py +55 -0
  61. vellum/workflows/logging.py +14 -0
  62. vellum/workflows/nodes/__init__.py +46 -0
  63. vellum/workflows/nodes/bases/__init__.py +7 -0
  64. vellum/workflows/nodes/bases/base.py +332 -0
  65. vellum/workflows/nodes/bases/base_subworkflow_node/__init__.py +5 -0
  66. vellum/workflows/nodes/bases/base_subworkflow_node/node.py +10 -0
  67. vellum/workflows/nodes/bases/tests/__init__.py +0 -0
  68. vellum/workflows/nodes/bases/tests/test_base_node.py +125 -0
  69. vellum/workflows/nodes/core/__init__.py +16 -0
  70. vellum/workflows/nodes/core/error_node/__init__.py +5 -0
  71. vellum/workflows/nodes/core/error_node/node.py +26 -0
  72. vellum/workflows/nodes/core/inline_subworkflow_node/__init__.py +5 -0
  73. vellum/workflows/nodes/core/inline_subworkflow_node/node.py +73 -0
  74. vellum/workflows/nodes/core/map_node/__init__.py +5 -0
  75. vellum/workflows/nodes/core/map_node/node.py +147 -0
  76. vellum/workflows/nodes/core/map_node/tests/__init__.py +0 -0
  77. vellum/workflows/nodes/core/map_node/tests/test_node.py +65 -0
  78. vellum/workflows/nodes/core/retry_node/__init__.py +5 -0
  79. vellum/workflows/nodes/core/retry_node/node.py +106 -0
  80. vellum/workflows/nodes/core/retry_node/tests/__init__.py +0 -0
  81. vellum/workflows/nodes/core/retry_node/tests/test_node.py +93 -0
  82. vellum/workflows/nodes/core/templating_node/__init__.py +5 -0
  83. vellum/workflows/nodes/core/templating_node/custom_filters.py +12 -0
  84. vellum/workflows/nodes/core/templating_node/exceptions.py +2 -0
  85. vellum/workflows/nodes/core/templating_node/node.py +123 -0
  86. vellum/workflows/nodes/core/templating_node/render.py +55 -0
  87. vellum/workflows/nodes/core/templating_node/tests/test_templating_node.py +21 -0
  88. vellum/workflows/nodes/core/try_node/__init__.py +5 -0
  89. vellum/workflows/nodes/core/try_node/node.py +110 -0
  90. vellum/workflows/nodes/core/try_node/tests/__init__.py +0 -0
  91. vellum/workflows/nodes/core/try_node/tests/test_node.py +82 -0
  92. vellum/workflows/nodes/displayable/__init__.py +31 -0
  93. vellum/workflows/nodes/displayable/api_node/__init__.py +5 -0
  94. vellum/workflows/nodes/displayable/api_node/node.py +44 -0
  95. vellum/workflows/nodes/displayable/bases/__init__.py +11 -0
  96. vellum/workflows/nodes/displayable/bases/api_node/__init__.py +5 -0
  97. vellum/workflows/nodes/displayable/bases/api_node/node.py +70 -0
  98. vellum/workflows/nodes/displayable/bases/base_prompt_node/__init__.py +5 -0
  99. vellum/workflows/nodes/displayable/bases/base_prompt_node/node.py +60 -0
  100. vellum/workflows/nodes/displayable/bases/inline_prompt_node/__init__.py +5 -0
  101. vellum/workflows/nodes/displayable/bases/inline_prompt_node/constants.py +13 -0
  102. vellum/workflows/nodes/displayable/bases/inline_prompt_node/node.py +118 -0
  103. vellum/workflows/nodes/displayable/bases/prompt_deployment_node.py +98 -0
  104. vellum/workflows/nodes/displayable/bases/search_node.py +90 -0
  105. vellum/workflows/nodes/displayable/code_execution_node/__init__.py +5 -0
  106. vellum/workflows/nodes/displayable/code_execution_node/node.py +197 -0
  107. vellum/workflows/nodes/displayable/code_execution_node/tests/__init__.py +0 -0
  108. vellum/workflows/nodes/displayable/code_execution_node/tests/fixtures/__init__.py +0 -0
  109. vellum/workflows/nodes/displayable/code_execution_node/tests/fixtures/main.py +3 -0
  110. vellum/workflows/nodes/displayable/code_execution_node/tests/test_code_execution_node.py +111 -0
  111. vellum/workflows/nodes/displayable/code_execution_node/utils.py +10 -0
  112. vellum/workflows/nodes/displayable/conditional_node/__init__.py +5 -0
  113. vellum/workflows/nodes/displayable/conditional_node/node.py +25 -0
  114. vellum/workflows/nodes/displayable/final_output_node/__init__.py +5 -0
  115. vellum/workflows/nodes/displayable/final_output_node/node.py +43 -0
  116. vellum/workflows/nodes/displayable/guardrail_node/__init__.py +5 -0
  117. vellum/workflows/nodes/displayable/guardrail_node/node.py +97 -0
  118. vellum/workflows/nodes/displayable/inline_prompt_node/__init__.py +5 -0
  119. vellum/workflows/nodes/displayable/inline_prompt_node/node.py +41 -0
  120. vellum/workflows/nodes/displayable/merge_node/__init__.py +5 -0
  121. vellum/workflows/nodes/displayable/merge_node/node.py +10 -0
  122. vellum/workflows/nodes/displayable/prompt_deployment_node/__init__.py +5 -0
  123. vellum/workflows/nodes/displayable/prompt_deployment_node/node.py +45 -0
  124. vellum/workflows/nodes/displayable/search_node/__init__.py +5 -0
  125. vellum/workflows/nodes/displayable/search_node/node.py +26 -0
  126. vellum/workflows/nodes/displayable/subworkflow_deployment_node/__init__.py +5 -0
  127. vellum/workflows/nodes/displayable/subworkflow_deployment_node/node.py +156 -0
  128. vellum/workflows/nodes/displayable/tests/__init__.py +0 -0
  129. vellum/workflows/nodes/displayable/tests/test_inline_text_prompt_node.py +148 -0
  130. vellum/workflows/nodes/displayable/tests/test_search_node_wth_text_output.py +134 -0
  131. vellum/workflows/nodes/displayable/tests/test_text_prompt_deployment_node.py +80 -0
  132. vellum/workflows/nodes/utils.py +27 -0
  133. vellum/workflows/outputs/__init__.py +6 -0
  134. vellum/workflows/outputs/base.py +196 -0
  135. vellum/workflows/ports/__init__.py +7 -0
  136. vellum/workflows/ports/node_ports.py +75 -0
  137. vellum/workflows/ports/port.py +75 -0
  138. vellum/workflows/ports/utils.py +40 -0
  139. vellum/workflows/references/__init__.py +17 -0
  140. vellum/workflows/references/environment_variable.py +20 -0
  141. vellum/workflows/references/execution_count.py +20 -0
  142. vellum/workflows/references/external_input.py +49 -0
  143. vellum/workflows/references/input.py +7 -0
  144. vellum/workflows/references/lazy.py +55 -0
  145. vellum/workflows/references/node.py +43 -0
  146. vellum/workflows/references/output.py +78 -0
  147. vellum/workflows/references/state_value.py +23 -0
  148. vellum/workflows/references/vellum_secret.py +15 -0
  149. vellum/workflows/references/workflow_input.py +41 -0
  150. vellum/workflows/resolvers/__init__.py +5 -0
  151. vellum/workflows/resolvers/base.py +15 -0
  152. vellum/workflows/runner/__init__.py +5 -0
  153. vellum/workflows/runner/runner.py +588 -0
  154. vellum/workflows/runner/types.py +18 -0
  155. vellum/workflows/state/__init__.py +5 -0
  156. vellum/workflows/state/base.py +327 -0
  157. vellum/workflows/state/context.py +18 -0
  158. vellum/workflows/state/encoder.py +57 -0
  159. vellum/workflows/state/store.py +28 -0
  160. vellum/workflows/state/tests/__init__.py +0 -0
  161. vellum/workflows/state/tests/test_state.py +113 -0
  162. vellum/workflows/types/__init__.py +0 -0
  163. vellum/workflows/types/core.py +91 -0
  164. vellum/workflows/types/generics.py +14 -0
  165. vellum/workflows/types/stack.py +39 -0
  166. vellum/workflows/types/tests/__init__.py +0 -0
  167. vellum/workflows/types/tests/test_utils.py +76 -0
  168. vellum/workflows/types/utils.py +164 -0
  169. vellum/workflows/utils/__init__.py +0 -0
  170. vellum/workflows/utils/names.py +13 -0
  171. vellum/workflows/utils/tests/__init__.py +0 -0
  172. vellum/workflows/utils/tests/test_names.py +15 -0
  173. vellum/workflows/utils/tests/test_vellum_variables.py +25 -0
  174. vellum/workflows/utils/vellum_variables.py +81 -0
  175. vellum/workflows/vellum_client.py +18 -0
  176. vellum/workflows/workflows/__init__.py +5 -0
  177. vellum/workflows/workflows/base.py +365 -0
  178. {vellum_ai-0.9.16rc2.dist-info → vellum_ai-0.9.16rc4.dist-info}/METADATA +2 -1
  179. {vellum_ai-0.9.16rc2.dist-info → vellum_ai-0.9.16rc4.dist-info}/RECORD +245 -7
  180. vellum_cli/__init__.py +72 -0
  181. vellum_cli/aliased_group.py +103 -0
  182. vellum_cli/config.py +96 -0
  183. vellum_cli/image_push.py +112 -0
  184. vellum_cli/logger.py +36 -0
  185. vellum_cli/pull.py +73 -0
  186. vellum_cli/push.py +121 -0
  187. vellum_cli/tests/test_config.py +100 -0
  188. vellum_cli/tests/test_pull.py +152 -0
  189. vellum_ee/workflows/__init__.py +0 -0
  190. vellum_ee/workflows/display/__init__.py +0 -0
  191. vellum_ee/workflows/display/base.py +73 -0
  192. vellum_ee/workflows/display/nodes/__init__.py +4 -0
  193. vellum_ee/workflows/display/nodes/base_node_display.py +116 -0
  194. vellum_ee/workflows/display/nodes/base_node_vellum_display.py +36 -0
  195. vellum_ee/workflows/display/nodes/get_node_display_class.py +25 -0
  196. vellum_ee/workflows/display/nodes/tests/__init__.py +0 -0
  197. vellum_ee/workflows/display/nodes/tests/test_base_node_display.py +47 -0
  198. vellum_ee/workflows/display/nodes/types.py +18 -0
  199. vellum_ee/workflows/display/nodes/utils.py +33 -0
  200. vellum_ee/workflows/display/nodes/vellum/__init__.py +32 -0
  201. vellum_ee/workflows/display/nodes/vellum/api_node.py +205 -0
  202. vellum_ee/workflows/display/nodes/vellum/code_execution_node.py +71 -0
  203. vellum_ee/workflows/display/nodes/vellum/conditional_node.py +217 -0
  204. vellum_ee/workflows/display/nodes/vellum/final_output_node.py +61 -0
  205. vellum_ee/workflows/display/nodes/vellum/guardrail_node.py +49 -0
  206. vellum_ee/workflows/display/nodes/vellum/inline_prompt_node.py +170 -0
  207. vellum_ee/workflows/display/nodes/vellum/inline_subworkflow_node.py +99 -0
  208. vellum_ee/workflows/display/nodes/vellum/map_node.py +100 -0
  209. vellum_ee/workflows/display/nodes/vellum/merge_node.py +48 -0
  210. vellum_ee/workflows/display/nodes/vellum/prompt_deployment_node.py +68 -0
  211. vellum_ee/workflows/display/nodes/vellum/search_node.py +193 -0
  212. vellum_ee/workflows/display/nodes/vellum/subworkflow_deployment_node.py +58 -0
  213. vellum_ee/workflows/display/nodes/vellum/templating_node.py +67 -0
  214. vellum_ee/workflows/display/nodes/vellum/tests/__init__.py +0 -0
  215. vellum_ee/workflows/display/nodes/vellum/tests/test_utils.py +106 -0
  216. vellum_ee/workflows/display/nodes/vellum/try_node.py +38 -0
  217. vellum_ee/workflows/display/nodes/vellum/utils.py +76 -0
  218. vellum_ee/workflows/display/tests/__init__.py +0 -0
  219. vellum_ee/workflows/display/tests/workflow_serialization/__init__.py +0 -0
  220. vellum_ee/workflows/display/tests/workflow_serialization/test_basic_api_node_serialization.py +426 -0
  221. vellum_ee/workflows/display/tests/workflow_serialization/test_basic_code_execution_node_serialization.py +607 -0
  222. vellum_ee/workflows/display/tests/workflow_serialization/test_basic_conditional_node_serialization.py +1175 -0
  223. vellum_ee/workflows/display/tests/workflow_serialization/test_basic_guardrail_node_serialization.py +235 -0
  224. vellum_ee/workflows/display/tests/workflow_serialization/test_basic_inline_subworkflow_serialization.py +511 -0
  225. vellum_ee/workflows/display/tests/workflow_serialization/test_basic_map_node_serialization.py +372 -0
  226. vellum_ee/workflows/display/tests/workflow_serialization/test_basic_merge_node_serialization.py +272 -0
  227. vellum_ee/workflows/display/tests/workflow_serialization/test_basic_prompt_deployment_serialization.py +289 -0
  228. vellum_ee/workflows/display/tests/workflow_serialization/test_basic_subworkflow_deployment_serialization.py +354 -0
  229. vellum_ee/workflows/display/tests/workflow_serialization/test_basic_terminal_node_serialization.py +123 -0
  230. vellum_ee/workflows/display/tests/workflow_serialization/test_basic_try_node_serialization.py +84 -0
  231. vellum_ee/workflows/display/tests/workflow_serialization/test_complex_terminal_node_serialization.py +233 -0
  232. vellum_ee/workflows/display/types.py +46 -0
  233. vellum_ee/workflows/display/utils/__init__.py +0 -0
  234. vellum_ee/workflows/display/utils/tests/__init__.py +0 -0
  235. vellum_ee/workflows/display/utils/tests/test_uuids.py +16 -0
  236. vellum_ee/workflows/display/utils/uuids.py +24 -0
  237. vellum_ee/workflows/display/utils/vellum.py +121 -0
  238. vellum_ee/workflows/display/vellum.py +357 -0
  239. vellum_ee/workflows/display/workflows/__init__.py +5 -0
  240. vellum_ee/workflows/display/workflows/base_workflow_display.py +302 -0
  241. vellum_ee/workflows/display/workflows/get_vellum_workflow_display_class.py +32 -0
  242. vellum_ee/workflows/display/workflows/vellum_workflow_display.py +386 -0
  243. {vellum_ai-0.9.16rc2.dist-info → vellum_ai-0.9.16rc4.dist-info}/LICENSE +0 -0
  244. {vellum_ai-0.9.16rc2.dist-info → vellum_ai-0.9.16rc4.dist-info}/WHEEL +0 -0
  245. {vellum_ai-0.9.16rc2.dist-info → vellum_ai-0.9.16rc4.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,289 @@
1
+ from datetime import datetime
2
+ from uuid import uuid4
3
+
4
+ from deepdiff import DeepDiff
5
+
6
+ from vellum import DeploymentRead
7
+
8
+ from tests.workflows.basic_text_prompt_deployment.workflow import BasicTextPromptDeployment
9
+ from vellum_ee.workflows.display.workflows import VellumWorkflowDisplay
10
+ from vellum_ee.workflows.display.workflows.get_vellum_workflow_display_class import get_workflow_display
11
+
12
+
13
+ def test_serialize_workflow(vellum_client):
14
+ # GIVEN a Workflow with stubbed out API calls
15
+ deployment = DeploymentRead(
16
+ id=str(uuid4()),
17
+ created=datetime.now(),
18
+ label="Example Prompt Deployment",
19
+ name="example_prompt_deployment",
20
+ last_deployed_on=datetime.now(),
21
+ input_variables=[],
22
+ active_model_version_ids=[],
23
+ last_deployed_history_item_id=str(uuid4()),
24
+ )
25
+ vellum_client.deployments.retrieve.return_value = deployment
26
+
27
+ # WHEN we serialize it
28
+ workflow_display = get_workflow_display(
29
+ base_display_class=VellumWorkflowDisplay, workflow_class=BasicTextPromptDeployment
30
+ )
31
+ serialized_workflow: dict = workflow_display.serialize()
32
+
33
+ # THEN we should get a serialized representation of the Workflow
34
+ assert serialized_workflow.keys() == {
35
+ "workflow_raw_data",
36
+ "input_variables",
37
+ "output_variables",
38
+ }
39
+
40
+ # AND its input variables should be what we expect
41
+ input_variables = serialized_workflow["input_variables"]
42
+ assert len(input_variables) == 2
43
+ assert not DeepDiff(
44
+ [
45
+ {
46
+ "id": "52995b50-84c9-465f-8a4b-a4ee2a92e388",
47
+ "key": "city",
48
+ "type": "STRING",
49
+ "required": None,
50
+ "default": None,
51
+ "extensions": None,
52
+ },
53
+ {
54
+ "id": "aa3ca842-250c-4a3f-853f-23928c28d0f8",
55
+ "key": "date",
56
+ "type": "STRING",
57
+ "required": None,
58
+ "default": None,
59
+ "extensions": None,
60
+ },
61
+ ],
62
+ input_variables,
63
+ ignore_order=True,
64
+ )
65
+
66
+ # AND its output variables should be what we expect
67
+ output_variables = serialized_workflow["output_variables"]
68
+ assert len(output_variables) == 1
69
+ assert output_variables == [
70
+ {
71
+ "id": "a609ab19-db1b-4cd0-bdb0-aee5ed31dc28",
72
+ "key": "text",
73
+ "type": "STRING",
74
+ }
75
+ ]
76
+
77
+ # AND its raw data should be what we expect
78
+ workflow_raw_data = serialized_workflow["workflow_raw_data"]
79
+ assert workflow_raw_data.keys() == {"edges", "nodes", "display_data", "definition"}
80
+ assert len(workflow_raw_data["edges"]) == 2
81
+ assert len(workflow_raw_data["nodes"]) == 3
82
+
83
+ # AND each node should be serialized correctly
84
+ entrypoint_node = workflow_raw_data["nodes"][0]
85
+ assert entrypoint_node == {
86
+ "id": "d680afbd-de64-4cf6-aa50-912686c48c64",
87
+ "type": "ENTRYPOINT",
88
+ "inputs": [],
89
+ "definition": {
90
+ "bases": [],
91
+ "module": [
92
+ "vellum",
93
+ "workflows",
94
+ "nodes",
95
+ "bases",
96
+ "base",
97
+ ],
98
+ "name": "BaseNode",
99
+ },
100
+ "data": {
101
+ "label": "Entrypoint Node",
102
+ "source_handle_id": "7065a943-1cab-4afd-9690-e678c5b74a2f",
103
+ },
104
+ "display_data": {
105
+ "position": {"x": 0.0, "y": 0.0},
106
+ },
107
+ }
108
+
109
+ prompt_node = workflow_raw_data["nodes"][1]
110
+ assert prompt_node == {
111
+ "id": "56c74024-19a3-4c0d-a5f5-23e1e9f11b21",
112
+ "type": "PROMPT",
113
+ "inputs": [
114
+ {
115
+ "id": "509cf3d4-db72-483e-897a-0f7f20e70d03",
116
+ "key": "city",
117
+ "value": {
118
+ "combinator": "OR",
119
+ "rules": [
120
+ {
121
+ "type": "INPUT_VARIABLE",
122
+ "data": {
123
+ "input_variable_id": "52995b50-84c9-465f-8a4b-a4ee2a92e388",
124
+ },
125
+ },
126
+ ],
127
+ },
128
+ },
129
+ {
130
+ "id": "7d6ec5ac-c582-4153-bd8a-b8794c367420",
131
+ "key": "date",
132
+ "value": {
133
+ "combinator": "OR",
134
+ "rules": [
135
+ {
136
+ "type": "INPUT_VARIABLE",
137
+ "data": {
138
+ "input_variable_id": "aa3ca842-250c-4a3f-853f-23928c28d0f8",
139
+ },
140
+ },
141
+ ],
142
+ },
143
+ },
144
+ ],
145
+ "data": {
146
+ "label": "Example Prompt Deployment Node",
147
+ "output_id": "4d38b850-79e3-4b85-9158-a41d0c535410",
148
+ "error_output_id": None,
149
+ "array_output_id": "0cf47d33-6d5f-466f-b826-e814f1d0348b",
150
+ "source_handle_id": "2f26c7e0-283d-4f04-b639-adebb56bc679",
151
+ "target_handle_id": "b7605c48-0937-4ecc-914e-0d1058130e65",
152
+ "variant": "DEPLOYMENT",
153
+ "prompt_deployment_id": deployment.id,
154
+ "release_tag": "LATEST",
155
+ },
156
+ "display_data": {
157
+ "position": {
158
+ "x": 0.0,
159
+ "y": 0.0,
160
+ },
161
+ },
162
+ "definition": {
163
+ "bases": [
164
+ {
165
+ "module": [
166
+ "vellum",
167
+ "workflows",
168
+ "nodes",
169
+ "displayable",
170
+ "prompt_deployment_node",
171
+ "node",
172
+ ],
173
+ "name": "PromptDeploymentNode",
174
+ }
175
+ ],
176
+ "module": [
177
+ "tests",
178
+ "workflows",
179
+ "basic_text_prompt_deployment",
180
+ "workflow",
181
+ ],
182
+ "name": "ExamplePromptDeploymentNode",
183
+ },
184
+ }
185
+
186
+ final_output_node = workflow_raw_data["nodes"][2]
187
+ assert final_output_node == {
188
+ "id": "64ff72c7-8ffc-4e1f-b7a7-e7cd0697f576",
189
+ "type": "TERMINAL",
190
+ "definition": {
191
+ "bases": [
192
+ {
193
+ "bases": [],
194
+ "module": [
195
+ "vellum",
196
+ "workflows",
197
+ "nodes",
198
+ "bases",
199
+ "base",
200
+ ],
201
+ "name": "BaseNode",
202
+ },
203
+ ],
204
+ "module": [
205
+ "vellum",
206
+ "workflows",
207
+ "nodes",
208
+ "displayable",
209
+ "final_output_node",
210
+ "node",
211
+ ],
212
+ "name": "FinalOutputNode",
213
+ },
214
+ "inputs": [
215
+ {
216
+ "id": "5f0fdd0f-63fe-4437-bc1b-cd6a84bb84c5",
217
+ "key": "node_input",
218
+ "value": {
219
+ "combinator": "OR",
220
+ "rules": [
221
+ {
222
+ "data": {
223
+ "node_id": "56c74024-19a3-4c0d-a5f5-23e1e9f11b21",
224
+ "output_id": "4d38b850-79e3-4b85-9158-a41d0c535410",
225
+ },
226
+ "type": "NODE_OUTPUT",
227
+ }
228
+ ],
229
+ },
230
+ }
231
+ ],
232
+ "data": {
233
+ "label": "Final Output",
234
+ "name": "text",
235
+ "node_input_id": "5f0fdd0f-63fe-4437-bc1b-cd6a84bb84c5",
236
+ "output_id": "a609ab19-db1b-4cd0-bdb0-aee5ed31dc28",
237
+ "output_type": "STRING",
238
+ "target_handle_id": "dced939a-9122-4290-8482-7daa9525dad6",
239
+ },
240
+ "display_data": {
241
+ "position": {
242
+ "x": 0.0,
243
+ "y": 0.0,
244
+ },
245
+ },
246
+ }
247
+
248
+ # AND each edge should be serialized correctly
249
+ serialized_edges = workflow_raw_data["edges"]
250
+ assert serialized_edges == [
251
+ {
252
+ "id": "8961d02b-074e-45ab-9f77-4e94606a4344",
253
+ "source_handle_id": "7065a943-1cab-4afd-9690-e678c5b74a2f",
254
+ "source_node_id": "d680afbd-de64-4cf6-aa50-912686c48c64",
255
+ "target_handle_id": "b7605c48-0937-4ecc-914e-0d1058130e65",
256
+ "target_node_id": "56c74024-19a3-4c0d-a5f5-23e1e9f11b21",
257
+ "type": "DEFAULT",
258
+ },
259
+ {
260
+ "id": "c2cbf6ef-8582-45c8-a643-fc6ae8fe482f",
261
+ "source_handle_id": "2f26c7e0-283d-4f04-b639-adebb56bc679",
262
+ "source_node_id": "56c74024-19a3-4c0d-a5f5-23e1e9f11b21",
263
+ "target_handle_id": "dced939a-9122-4290-8482-7daa9525dad6",
264
+ "target_node_id": "64ff72c7-8ffc-4e1f-b7a7-e7cd0697f576",
265
+ "type": "DEFAULT",
266
+ },
267
+ ]
268
+
269
+ # AND the display data should be what we expect
270
+ display_data = workflow_raw_data["display_data"]
271
+ assert display_data == {
272
+ "viewport": {
273
+ "x": 0.0,
274
+ "y": 0.0,
275
+ "zoom": 1.0,
276
+ }
277
+ }
278
+
279
+ # AND the definition should be what we expect
280
+ definition = workflow_raw_data["definition"]
281
+ assert definition == {
282
+ "name": "BasicTextPromptDeployment",
283
+ "module": [
284
+ "tests",
285
+ "workflows",
286
+ "basic_text_prompt_deployment",
287
+ "workflow",
288
+ ],
289
+ }
@@ -0,0 +1,354 @@
1
+ from datetime import datetime
2
+ from uuid import uuid4
3
+
4
+ from deepdiff import DeepDiff
5
+
6
+ from vellum import WorkflowDeploymentRead
7
+
8
+ from tests.workflows.basic_subworkflow_deployment.workflow import BasicSubworkflowDeploymentWorkflow
9
+ from vellum_ee.workflows.display.workflows import VellumWorkflowDisplay
10
+ from vellum_ee.workflows.display.workflows.get_vellum_workflow_display_class import get_workflow_display
11
+
12
+
13
+ def test_serialize_workflow(vellum_client):
14
+ # GIVEN a Workflow with stubbed out API calls
15
+ deployment = WorkflowDeploymentRead(
16
+ id=str(uuid4()),
17
+ created=datetime.now(),
18
+ label="Example Subworkflow Deployment",
19
+ name="example_subworkflow_deployment",
20
+ input_variables=[],
21
+ output_variables=[],
22
+ last_deployed_on=datetime.now(),
23
+ last_deployed_history_item_id=str(uuid4()),
24
+ )
25
+ vellum_client.workflow_deployments.retrieve.return_value = deployment
26
+
27
+ # WHEN we serialize it
28
+ workflow_display = get_workflow_display(
29
+ base_display_class=VellumWorkflowDisplay, workflow_class=BasicSubworkflowDeploymentWorkflow
30
+ )
31
+ serialized_workflow: dict = workflow_display.serialize()
32
+
33
+ # THEN we should get a serialized representation of the Workflow
34
+ assert serialized_workflow.keys() == {
35
+ "workflow_raw_data",
36
+ "input_variables",
37
+ "output_variables",
38
+ }
39
+
40
+ # AND its input variables should be what we expect
41
+ input_variables = serialized_workflow["input_variables"]
42
+ assert len(input_variables) == 2
43
+ assert not DeepDiff(
44
+ [
45
+ {
46
+ "id": "693cc9a5-8d74-4a58-bdcf-2b4989cdf250",
47
+ "key": "city",
48
+ "type": "STRING",
49
+ "required": None,
50
+ "default": None,
51
+ "extensions": None,
52
+ },
53
+ {
54
+ "id": "19a78824-9a98-4ae8-a1fc-61f81a422a17",
55
+ "key": "date",
56
+ "type": "STRING",
57
+ "required": None,
58
+ "default": None,
59
+ "extensions": None,
60
+ },
61
+ ],
62
+ input_variables,
63
+ ignore_order=True,
64
+ )
65
+
66
+ # AND its output variables should be what we expect
67
+ output_variables = serialized_workflow["output_variables"]
68
+ assert len(output_variables) == 2
69
+ assert not DeepDiff(
70
+ [
71
+ {
72
+ "id": "3f487916-126f-4d6c-95b4-fa72d875b793",
73
+ "key": "temperature",
74
+ "type": "NUMBER",
75
+ },
76
+ {
77
+ "id": "45d53a1e-26e8-4c43-a010-80d141acc249",
78
+ "key": "reasoning",
79
+ "type": "STRING",
80
+ },
81
+ ],
82
+ output_variables,
83
+ ignore_order=True,
84
+ )
85
+
86
+ # AND its raw data should be what we expect
87
+ workflow_raw_data = serialized_workflow["workflow_raw_data"]
88
+ assert workflow_raw_data.keys() == {"edges", "nodes", "display_data", "definition"}
89
+ assert len(workflow_raw_data["edges"]) == 3
90
+ assert len(workflow_raw_data["nodes"]) == 4
91
+
92
+ # AND each node should be serialized correctly
93
+ entrypoint_node = workflow_raw_data["nodes"][0]
94
+ assert entrypoint_node == {
95
+ "id": "f0eea82b-39cc-44e3-9c0d-12205ed5652c",
96
+ "type": "ENTRYPOINT",
97
+ "definition": {
98
+ "bases": [],
99
+ "module": [
100
+ "vellum",
101
+ "workflows",
102
+ "nodes",
103
+ "bases",
104
+ "base",
105
+ ],
106
+ "name": "BaseNode",
107
+ },
108
+ "inputs": [],
109
+ "data": {
110
+ "label": "Entrypoint Node",
111
+ "source_handle_id": "13d9eb34-aecb-496d-9e57-d5e786b0bc7c",
112
+ },
113
+ "display_data": {
114
+ "position": {"x": 0.0, "y": 0.0},
115
+ },
116
+ }
117
+
118
+ subworkflow_node = workflow_raw_data["nodes"][1]
119
+ assert subworkflow_node == {
120
+ "id": "d71f674e-8a6b-44ab-b552-7f4637a4e7a6",
121
+ "type": "SUBWORKFLOW",
122
+ "inputs": [
123
+ {
124
+ "id": "dade23b9-dab6-4760-9247-da189f1019d2",
125
+ "key": "city",
126
+ "value": {
127
+ "rules": [
128
+ {
129
+ "type": "INPUT_VARIABLE",
130
+ "data": {"input_variable_id": "693cc9a5-8d74-4a58-bdcf-2b4989cdf250"},
131
+ }
132
+ ],
133
+ "combinator": "OR",
134
+ },
135
+ },
136
+ {
137
+ "id": "8d73270e-2cf9-4146-b053-4780b99857a6",
138
+ "key": "date",
139
+ "value": {
140
+ "rules": [
141
+ {
142
+ "type": "INPUT_VARIABLE",
143
+ "data": {"input_variable_id": "19a78824-9a98-4ae8-a1fc-61f81a422a17"},
144
+ }
145
+ ],
146
+ "combinator": "OR",
147
+ },
148
+ },
149
+ ],
150
+ "data": {
151
+ "label": "Example Subworkflow Deployment Node",
152
+ "error_output_id": None,
153
+ "source_handle_id": "ab0db8a9-7b53-4d88-8667-273b31303273",
154
+ "target_handle_id": "e4d80502-9281-42c8-91e3-10817bcd7d9e",
155
+ "variant": "DEPLOYMENT",
156
+ "workflow_deployment_id": deployment.id,
157
+ "release_tag": "LATEST",
158
+ },
159
+ "display_data": {"position": {"x": 0.0, "y": 0.0}},
160
+ "definition": {
161
+ "bases": [
162
+ {
163
+ "module": [
164
+ "vellum",
165
+ "workflows",
166
+ "nodes",
167
+ "displayable",
168
+ "subworkflow_deployment_node",
169
+ "node",
170
+ ],
171
+ "name": "SubworkflowDeploymentNode",
172
+ }
173
+ ],
174
+ "module": [
175
+ "tests",
176
+ "workflows",
177
+ "basic_subworkflow_deployment",
178
+ "workflow",
179
+ ],
180
+ "name": "ExampleSubworkflowDeploymentNode",
181
+ },
182
+ }
183
+
184
+ assert not DeepDiff(
185
+ [
186
+ {
187
+ "id": "18170041-1a70-4836-9fa0-adceba2a1f4f",
188
+ "type": "TERMINAL",
189
+ "definition": {
190
+ "bases": [
191
+ {
192
+ "bases": [],
193
+ "module": [
194
+ "vellum",
195
+ "workflows",
196
+ "nodes",
197
+ "bases",
198
+ "base",
199
+ ],
200
+ "name": "BaseNode",
201
+ },
202
+ ],
203
+ "module": [
204
+ "vellum",
205
+ "workflows",
206
+ "nodes",
207
+ "displayable",
208
+ "final_output_node",
209
+ "node",
210
+ ],
211
+ "name": "FinalOutputNode",
212
+ },
213
+ "data": {
214
+ "label": "Final Output",
215
+ "name": "temperature",
216
+ "target_handle_id": "23117248-df28-4519-bebc-abcb24f966b3",
217
+ "output_id": "3f487916-126f-4d6c-95b4-fa72d875b793",
218
+ "output_type": "NUMBER",
219
+ "node_input_id": "29e10bd7-eb39-4e0f-a406-c3a55b834d6f",
220
+ },
221
+ "inputs": [
222
+ {
223
+ "id": "29e10bd7-eb39-4e0f-a406-c3a55b834d6f",
224
+ "key": "node_input",
225
+ "value": {
226
+ "rules": [
227
+ {
228
+ "type": "NODE_OUTPUT",
229
+ "data": {
230
+ "node_id": "d71f674e-8a6b-44ab-b552-7f4637a4e7a6",
231
+ "output_id": "5170e2fb-2b7c-4cb1-8958-6c0f2a359e1e",
232
+ },
233
+ }
234
+ ],
235
+ "combinator": "OR",
236
+ },
237
+ }
238
+ ],
239
+ "display_data": {"position": {"x": 0.0, "y": 0.0}},
240
+ },
241
+ {
242
+ "id": "94afd0ac-1ec4-486b-a6fb-fa1ec7029d19",
243
+ "type": "TERMINAL",
244
+ "definition": {
245
+ "bases": [
246
+ {
247
+ "bases": [],
248
+ "module": [
249
+ "vellum",
250
+ "workflows",
251
+ "nodes",
252
+ "bases",
253
+ "base",
254
+ ],
255
+ "name": "BaseNode",
256
+ },
257
+ ],
258
+ "module": [
259
+ "vellum",
260
+ "workflows",
261
+ "nodes",
262
+ "displayable",
263
+ "final_output_node",
264
+ "node",
265
+ ],
266
+ "name": "FinalOutputNode",
267
+ },
268
+ "data": {
269
+ "label": "Final Output",
270
+ "name": "reasoning",
271
+ "target_handle_id": "c3aeba92-4faf-4814-9842-eec7436ee555",
272
+ "output_id": "45d53a1e-26e8-4c43-a010-80d141acc249",
273
+ "output_type": "STRING",
274
+ "node_input_id": "daaf0664-0aca-4619-af30-07caa1486b90",
275
+ },
276
+ "inputs": [
277
+ {
278
+ "id": "daaf0664-0aca-4619-af30-07caa1486b90",
279
+ "key": "node_input",
280
+ "value": {
281
+ "rules": [
282
+ {
283
+ "type": "NODE_OUTPUT",
284
+ "data": {
285
+ "node_id": "d71f674e-8a6b-44ab-b552-7f4637a4e7a6",
286
+ "output_id": "d9ab77e4-226f-436f-ad70-585b57510001",
287
+ },
288
+ }
289
+ ],
290
+ "combinator": "OR",
291
+ },
292
+ }
293
+ ],
294
+ "display_data": {"position": {"x": 0.0, "y": 0.0}},
295
+ },
296
+ ],
297
+ workflow_raw_data["nodes"][2:],
298
+ ignore_order=True,
299
+ )
300
+
301
+ # AND each edge should be serialized correctly
302
+ serialized_edges = workflow_raw_data["edges"]
303
+ assert not DeepDiff(
304
+ [
305
+ {
306
+ "id": "77f5b6e0-16e3-4bb5-9344-4d9557289802",
307
+ "source_handle_id": "13d9eb34-aecb-496d-9e57-d5e786b0bc7c",
308
+ "source_node_id": "f0eea82b-39cc-44e3-9c0d-12205ed5652c",
309
+ "target_handle_id": "e4d80502-9281-42c8-91e3-10817bcd7d9e",
310
+ "target_node_id": "d71f674e-8a6b-44ab-b552-7f4637a4e7a6",
311
+ "type": "DEFAULT",
312
+ },
313
+ {
314
+ "id": "69933897-e91e-4c6c-9ba3-ed3e3c265c73",
315
+ "source_handle_id": "ab0db8a9-7b53-4d88-8667-273b31303273",
316
+ "source_node_id": "d71f674e-8a6b-44ab-b552-7f4637a4e7a6",
317
+ "target_handle_id": "c3aeba92-4faf-4814-9842-eec7436ee555",
318
+ "target_node_id": "94afd0ac-1ec4-486b-a6fb-fa1ec7029d19",
319
+ "type": "DEFAULT",
320
+ },
321
+ {
322
+ "id": "86a9af31-f78e-45ac-b170-f66bbba98f9d",
323
+ "source_handle_id": "ab0db8a9-7b53-4d88-8667-273b31303273",
324
+ "source_node_id": "d71f674e-8a6b-44ab-b552-7f4637a4e7a6",
325
+ "target_handle_id": "23117248-df28-4519-bebc-abcb24f966b3",
326
+ "target_node_id": "18170041-1a70-4836-9fa0-adceba2a1f4f",
327
+ "type": "DEFAULT",
328
+ },
329
+ ],
330
+ serialized_edges,
331
+ ignore_order=True,
332
+ )
333
+
334
+ # AND the display data should be what we expect
335
+ display_data = workflow_raw_data["display_data"]
336
+ assert display_data == {
337
+ "viewport": {
338
+ "x": 0.0,
339
+ "y": 0.0,
340
+ "zoom": 1.0,
341
+ }
342
+ }
343
+
344
+ # AND the definition should be what we expect
345
+ definition = workflow_raw_data["definition"]
346
+ assert definition == {
347
+ "name": "BasicSubworkflowDeploymentWorkflow",
348
+ "module": [
349
+ "tests",
350
+ "workflows",
351
+ "basic_subworkflow_deployment",
352
+ "workflow",
353
+ ],
354
+ }