vellum-ai 0.14.55__py3-none-any.whl → 0.14.57__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,5 @@
1
+ from deepdiff import DeepDiff
2
+
1
3
  from vellum_ee.workflows.display.workflows.get_vellum_workflow_display_class import get_workflow_display
2
4
 
3
5
  from tests.workflows.basic_inline_prompt_node_with_functions.workflow import BasicInlinePromptWithFunctionsWorkflow
@@ -7,9 +9,267 @@ def test_serialize_workflow():
7
9
  # WHEN we serialize it
8
10
  workflow_display = get_workflow_display(workflow_class=BasicInlinePromptWithFunctionsWorkflow)
9
11
  serialized_workflow: dict = workflow_display.serialize()
10
- assert (
11
- serialized_workflow["workflow_raw_data"]["nodes"][-2]["data"]["exec_config"]["prompt_template_block_data"][
12
- "blocks"
13
- ][-1]["block_type"]
14
- == "FUNCTION_DEFINITION"
12
+
13
+ # THEN we should get a serialized representation of the Workflow
14
+ assert serialized_workflow.keys() == {
15
+ "workflow_raw_data",
16
+ "input_variables",
17
+ "state_variables",
18
+ "output_variables",
19
+ }
20
+
21
+ # AND its input variables should be what we expect
22
+ input_variables = serialized_workflow["input_variables"]
23
+ assert len(input_variables) == 1
24
+ assert not DeepDiff(
25
+ [
26
+ {
27
+ "id": "ceb5cc94-48ee-4968-b37a-421623a8f1ef",
28
+ "key": "noun",
29
+ "type": "STRING",
30
+ "default": None,
31
+ "required": True,
32
+ "extensions": {"color": None},
33
+ }
34
+ ],
35
+ input_variables,
36
+ ignore_order=True,
37
+ )
38
+
39
+ # AND its output variables should be what we expect
40
+ output_variables = serialized_workflow["output_variables"]
41
+ assert len(output_variables) == 1
42
+ assert not DeepDiff(
43
+ [{"id": "15a0ab89-8ed4-43b9-afa2-3c0b29d4dc3e", "key": "results", "type": "JSON"}],
44
+ output_variables,
45
+ ignore_order=True,
15
46
  )
47
+
48
+ # AND its raw data should be what we expect
49
+ workflow_raw_data = serialized_workflow["workflow_raw_data"]
50
+ assert len(workflow_raw_data["edges"]) == 2
51
+ assert len(workflow_raw_data["nodes"]) == 3
52
+
53
+ # AND each node should be serialized correctly
54
+ entrypoint_node = workflow_raw_data["nodes"][0]
55
+ assert entrypoint_node == {
56
+ "id": "382842a3-0490-4dee-b87b-eef86766f07c",
57
+ "type": "ENTRYPOINT",
58
+ "inputs": [],
59
+ "data": {"label": "Entrypoint Node", "source_handle_id": "8294baa6-8bf4-4b54-a56b-407b64851b77"},
60
+ "display_data": {"position": {"x": 0.0, "y": 0.0}},
61
+ "base": None,
62
+ "definition": None,
63
+ }
64
+
65
+ prompt_node = workflow_raw_data["nodes"][1]
66
+ assert not DeepDiff(
67
+ {
68
+ "id": "8450dd06-975a-41a4-a564-808ee8808fe6",
69
+ "type": "PROMPT",
70
+ "inputs": [
71
+ {
72
+ "id": "f7fca55e-93e9-4009-9227-acf839c7990d",
73
+ "key": "noun",
74
+ "value": {
75
+ "rules": [
76
+ {
77
+ "type": "INPUT_VARIABLE",
78
+ "data": {"input_variable_id": "ceb5cc94-48ee-4968-b37a-421623a8f1ef"},
79
+ }
80
+ ],
81
+ "combinator": "OR",
82
+ },
83
+ }
84
+ ],
85
+ "data": {
86
+ "label": "Example Base Inline Prompt Node With Functions",
87
+ "output_id": "ead0ccb5-092f-4d9b-a9ec-5eb83d498188",
88
+ "error_output_id": None,
89
+ "array_output_id": "628df199-a049-40b9-a29b-a378edd759bb",
90
+ "source_handle_id": "d4a097ab-e22d-42f1-b6bc-2ed96856377a",
91
+ "target_handle_id": "c2dccecb-8a41-40a8-95af-325d3ab8bfe5",
92
+ "variant": "INLINE",
93
+ "exec_config": {
94
+ "parameters": {
95
+ "stop": [],
96
+ "temperature": 0.0,
97
+ "max_tokens": 4096,
98
+ "top_p": 1.0,
99
+ "top_k": 0,
100
+ "frequency_penalty": 0.0,
101
+ "presence_penalty": 0.0,
102
+ "logit_bias": None,
103
+ "custom_parameters": None,
104
+ },
105
+ "input_variables": [
106
+ {"id": "f7fca55e-93e9-4009-9227-acf839c7990d", "key": "noun", "type": "STRING"}
107
+ ],
108
+ "prompt_template_block_data": {
109
+ "version": 1,
110
+ "blocks": [
111
+ {
112
+ "block_type": "CHAT_MESSAGE",
113
+ "properties": {
114
+ "chat_role": "SYSTEM",
115
+ "chat_source": None,
116
+ "chat_message_unterminated": False,
117
+ "blocks": [
118
+ {
119
+ "block_type": "JINJA",
120
+ "properties": {
121
+ "template": "What's your favorite {{noun}}?",
122
+ "template_type": "STRING",
123
+ },
124
+ "id": "467fe2b1-312b-40db-8869-9c6ada7c7077",
125
+ "cache_config": None,
126
+ "state": "ENABLED",
127
+ }
128
+ ],
129
+ },
130
+ "id": "1d1e117d-19dc-4282-b1e3-9534014fb6e5",
131
+ "cache_config": None,
132
+ "state": "ENABLED",
133
+ },
134
+ {
135
+ "id": "9b34f084-449d-423f-8691-37518b1ee9ca",
136
+ "block_type": "FUNCTION_DEFINITION",
137
+ "properties": {
138
+ "function_name": "favorite_noun",
139
+ "function_description": "Returns the favorite noun of the user",
140
+ "function_parameters": {},
141
+ "function_forced": None,
142
+ "function_strict": None,
143
+ },
144
+ },
145
+ ],
146
+ },
147
+ },
148
+ "ml_model_name": "gpt-4o",
149
+ },
150
+ "display_data": {"position": {"x": 0.0, "y": 0.0}},
151
+ "base": {
152
+ "name": "InlinePromptNode",
153
+ "module": ["vellum", "workflows", "nodes", "displayable", "inline_prompt_node", "node"],
154
+ },
155
+ "definition": {
156
+ "name": "ExampleBaseInlinePromptNodeWithFunctions",
157
+ "module": ["tests", "workflows", "basic_inline_prompt_node_with_functions", "workflow"],
158
+ },
159
+ "outputs": [
160
+ {"id": "9557bd86-702d-4b45-b8c1-c3980bffe28f", "name": "json", "type": "JSON", "value": None},
161
+ {"id": "ead0ccb5-092f-4d9b-a9ec-5eb83d498188", "name": "text", "type": "STRING", "value": None},
162
+ {"id": "628df199-a049-40b9-a29b-a378edd759bb", "name": "results", "type": "ARRAY", "value": None},
163
+ ],
164
+ "ports": [{"id": "d4a097ab-e22d-42f1-b6bc-2ed96856377a", "name": "default", "type": "DEFAULT"}],
165
+ "attributes": [
166
+ {
167
+ "id": "6cd5395c-6e46-4bc9-b98c-8f8924554555",
168
+ "name": "ml_model",
169
+ "value": {"type": "CONSTANT_VALUE", "value": {"type": "STRING", "value": "gpt-4o"}},
170
+ },
171
+ {
172
+ "id": "ffabe7d2-8ab6-4201-9d41-c4d7be1386e1",
173
+ "name": "prompt_inputs",
174
+ "value": {
175
+ "type": "DICTIONARY_REFERENCE",
176
+ "entries": [
177
+ {
178
+ "key": "noun",
179
+ "value": {
180
+ "type": "WORKFLOW_INPUT",
181
+ "input_variable_id": "ceb5cc94-48ee-4968-b37a-421623a8f1ef",
182
+ },
183
+ }
184
+ ],
185
+ },
186
+ },
187
+ ],
188
+ },
189
+ prompt_node,
190
+ ignore_order=True,
191
+ )
192
+
193
+ final_output_node = workflow_raw_data["nodes"][2]
194
+ assert not DeepDiff(
195
+ {
196
+ "id": "42318326-3ae8-417f-9609-f6d8ae47eafb",
197
+ "type": "TERMINAL",
198
+ "data": {
199
+ "label": "Final Output",
200
+ "name": "results",
201
+ "target_handle_id": "46c99277-2b4b-477d-851c-ea497aef6b16",
202
+ "output_id": "15a0ab89-8ed4-43b9-afa2-3c0b29d4dc3e",
203
+ "output_type": "JSON",
204
+ "node_input_id": "d7c89dce-765b-494d-a256-aba4bcf87b42",
205
+ },
206
+ "inputs": [
207
+ {
208
+ "id": "d7c89dce-765b-494d-a256-aba4bcf87b42",
209
+ "key": "node_input",
210
+ "value": {
211
+ "rules": [
212
+ {
213
+ "type": "NODE_OUTPUT",
214
+ "data": {
215
+ "node_id": "8450dd06-975a-41a4-a564-808ee8808fe6",
216
+ "output_id": "628df199-a049-40b9-a29b-a378edd759bb",
217
+ },
218
+ }
219
+ ],
220
+ "combinator": "OR",
221
+ },
222
+ }
223
+ ],
224
+ "display_data": {"position": {"x": 0.0, "y": 0.0}},
225
+ "base": {
226
+ "name": "FinalOutputNode",
227
+ "module": ["vellum", "workflows", "nodes", "displayable", "final_output_node", "node"],
228
+ },
229
+ "definition": None,
230
+ },
231
+ final_output_node,
232
+ ignore_order=True,
233
+ )
234
+
235
+ # AND each edge should be serialized correctly
236
+ serialized_edges = workflow_raw_data["edges"]
237
+ assert not DeepDiff(
238
+ [
239
+ {
240
+ "id": "924f693f-3f4c-466a-8cde-648ba3baf9fd",
241
+ "source_node_id": "382842a3-0490-4dee-b87b-eef86766f07c",
242
+ "source_handle_id": "8294baa6-8bf4-4b54-a56b-407b64851b77",
243
+ "target_node_id": "8450dd06-975a-41a4-a564-808ee8808fe6",
244
+ "target_handle_id": "c2dccecb-8a41-40a8-95af-325d3ab8bfe5",
245
+ "type": "DEFAULT",
246
+ },
247
+ {
248
+ "id": "05ca58fb-e02d-48d4-9207-2dad0833a25b",
249
+ "source_node_id": "8450dd06-975a-41a4-a564-808ee8808fe6",
250
+ "source_handle_id": "d4a097ab-e22d-42f1-b6bc-2ed96856377a",
251
+ "target_node_id": "42318326-3ae8-417f-9609-f6d8ae47eafb",
252
+ "target_handle_id": "46c99277-2b4b-477d-851c-ea497aef6b16",
253
+ "type": "DEFAULT",
254
+ },
255
+ ],
256
+ serialized_edges,
257
+ ignore_order=True,
258
+ )
259
+
260
+ # AND the display data should be what we expect
261
+ display_data = workflow_raw_data["display_data"]
262
+ assert display_data == {
263
+ "viewport": {
264
+ "x": 0.0,
265
+ "y": 0.0,
266
+ "zoom": 1.0,
267
+ }
268
+ }
269
+
270
+ # AND the definition should be what we expect
271
+ definition = workflow_raw_data["definition"]
272
+ assert definition == {
273
+ "name": "BasicInlinePromptWithFunctionsWorkflow",
274
+ "module": ["tests", "workflows", "basic_inline_prompt_node_with_functions", "workflow"],
275
+ }
@@ -130,17 +130,21 @@ def test_serialize_workflow():
130
130
  "type": "JSON",
131
131
  "value": [
132
132
  {
133
- "state": None,
134
- "cache_config": None,
135
- "name": "get_current_weather",
136
- "description": None,
137
- "parameters": {
138
- "type": "object",
139
- "properties": {"location": {"type": "string"}, "unit": {"type": "string"}},
140
- "required": ["location", "unit"],
133
+ "type": "CODE_EXECUTION",
134
+ "definition": {
135
+ "state": None,
136
+ "cache_config": None,
137
+ "name": "get_current_weather",
138
+ "description": "\n Get the current weather in a given location.\n ",
139
+ "parameters": {
140
+ "type": "object",
141
+ "properties": {"location": {"type": "string"}, "unit": {"type": "string"}},
142
+ "required": ["location", "unit"],
143
+ },
144
+ "forced": None,
145
+ "strict": None,
141
146
  },
142
- "forced": None,
143
- "strict": None,
147
+ "src": 'def get_current_weather(location: str, unit: str) -> str:\n """\n Get the current weather in a given location.\n """\n return f"The current weather in {location} is sunny with a temperature of 70 degrees {unit}."\n', # noqa: E501
144
148
  }
145
149
  ],
146
150
  },