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.
- vellum/plugins/__init__.py +0 -0
- vellum/plugins/pydantic.py +74 -0
- vellum/plugins/utils.py +19 -0
- vellum/plugins/vellum_mypy.py +639 -3
- vellum/workflows/README.md +90 -0
- vellum/workflows/__init__.py +5 -0
- vellum/workflows/constants.py +43 -0
- vellum/workflows/descriptors/__init__.py +0 -0
- vellum/workflows/descriptors/base.py +339 -0
- vellum/workflows/descriptors/tests/test_utils.py +83 -0
- vellum/workflows/descriptors/utils.py +90 -0
- vellum/workflows/edges/__init__.py +5 -0
- vellum/workflows/edges/edge.py +23 -0
- vellum/workflows/emitters/__init__.py +5 -0
- vellum/workflows/emitters/base.py +14 -0
- vellum/workflows/environment/__init__.py +5 -0
- vellum/workflows/environment/environment.py +7 -0
- vellum/workflows/errors/__init__.py +6 -0
- vellum/workflows/errors/types.py +20 -0
- vellum/workflows/events/__init__.py +31 -0
- vellum/workflows/events/node.py +125 -0
- vellum/workflows/events/tests/__init__.py +0 -0
- vellum/workflows/events/tests/test_event.py +216 -0
- vellum/workflows/events/types.py +52 -0
- vellum/workflows/events/utils.py +5 -0
- vellum/workflows/events/workflow.py +139 -0
- vellum/workflows/exceptions.py +15 -0
- vellum/workflows/expressions/__init__.py +0 -0
- vellum/workflows/expressions/accessor.py +52 -0
- vellum/workflows/expressions/and_.py +32 -0
- vellum/workflows/expressions/begins_with.py +31 -0
- vellum/workflows/expressions/between.py +38 -0
- vellum/workflows/expressions/coalesce_expression.py +41 -0
- vellum/workflows/expressions/contains.py +30 -0
- vellum/workflows/expressions/does_not_begin_with.py +31 -0
- vellum/workflows/expressions/does_not_contain.py +30 -0
- vellum/workflows/expressions/does_not_end_with.py +31 -0
- vellum/workflows/expressions/does_not_equal.py +25 -0
- vellum/workflows/expressions/ends_with.py +31 -0
- vellum/workflows/expressions/equals.py +25 -0
- vellum/workflows/expressions/greater_than.py +33 -0
- vellum/workflows/expressions/greater_than_or_equal_to.py +33 -0
- vellum/workflows/expressions/in_.py +31 -0
- vellum/workflows/expressions/is_blank.py +24 -0
- vellum/workflows/expressions/is_not_blank.py +24 -0
- vellum/workflows/expressions/is_not_null.py +21 -0
- vellum/workflows/expressions/is_not_undefined.py +22 -0
- vellum/workflows/expressions/is_null.py +21 -0
- vellum/workflows/expressions/is_undefined.py +22 -0
- vellum/workflows/expressions/less_than.py +33 -0
- vellum/workflows/expressions/less_than_or_equal_to.py +33 -0
- vellum/workflows/expressions/not_between.py +38 -0
- vellum/workflows/expressions/not_in.py +31 -0
- vellum/workflows/expressions/or_.py +32 -0
- vellum/workflows/graph/__init__.py +3 -0
- vellum/workflows/graph/graph.py +131 -0
- vellum/workflows/graph/tests/__init__.py +0 -0
- vellum/workflows/graph/tests/test_graph.py +437 -0
- vellum/workflows/inputs/__init__.py +5 -0
- vellum/workflows/inputs/base.py +55 -0
- vellum/workflows/logging.py +14 -0
- vellum/workflows/nodes/__init__.py +46 -0
- vellum/workflows/nodes/bases/__init__.py +7 -0
- vellum/workflows/nodes/bases/base.py +332 -0
- vellum/workflows/nodes/bases/base_subworkflow_node/__init__.py +5 -0
- vellum/workflows/nodes/bases/base_subworkflow_node/node.py +10 -0
- vellum/workflows/nodes/bases/tests/__init__.py +0 -0
- vellum/workflows/nodes/bases/tests/test_base_node.py +125 -0
- vellum/workflows/nodes/core/__init__.py +16 -0
- vellum/workflows/nodes/core/error_node/__init__.py +5 -0
- vellum/workflows/nodes/core/error_node/node.py +26 -0
- vellum/workflows/nodes/core/inline_subworkflow_node/__init__.py +5 -0
- vellum/workflows/nodes/core/inline_subworkflow_node/node.py +73 -0
- vellum/workflows/nodes/core/map_node/__init__.py +5 -0
- vellum/workflows/nodes/core/map_node/node.py +147 -0
- vellum/workflows/nodes/core/map_node/tests/__init__.py +0 -0
- vellum/workflows/nodes/core/map_node/tests/test_node.py +65 -0
- vellum/workflows/nodes/core/retry_node/__init__.py +5 -0
- vellum/workflows/nodes/core/retry_node/node.py +106 -0
- vellum/workflows/nodes/core/retry_node/tests/__init__.py +0 -0
- vellum/workflows/nodes/core/retry_node/tests/test_node.py +93 -0
- vellum/workflows/nodes/core/templating_node/__init__.py +5 -0
- vellum/workflows/nodes/core/templating_node/custom_filters.py +12 -0
- vellum/workflows/nodes/core/templating_node/exceptions.py +2 -0
- vellum/workflows/nodes/core/templating_node/node.py +123 -0
- vellum/workflows/nodes/core/templating_node/render.py +55 -0
- vellum/workflows/nodes/core/templating_node/tests/test_templating_node.py +21 -0
- vellum/workflows/nodes/core/try_node/__init__.py +5 -0
- vellum/workflows/nodes/core/try_node/node.py +110 -0
- vellum/workflows/nodes/core/try_node/tests/__init__.py +0 -0
- vellum/workflows/nodes/core/try_node/tests/test_node.py +82 -0
- vellum/workflows/nodes/displayable/__init__.py +31 -0
- vellum/workflows/nodes/displayable/api_node/__init__.py +5 -0
- vellum/workflows/nodes/displayable/api_node/node.py +44 -0
- vellum/workflows/nodes/displayable/bases/__init__.py +11 -0
- vellum/workflows/nodes/displayable/bases/api_node/__init__.py +5 -0
- vellum/workflows/nodes/displayable/bases/api_node/node.py +70 -0
- vellum/workflows/nodes/displayable/bases/base_prompt_node/__init__.py +5 -0
- vellum/workflows/nodes/displayable/bases/base_prompt_node/node.py +60 -0
- vellum/workflows/nodes/displayable/bases/inline_prompt_node/__init__.py +5 -0
- vellum/workflows/nodes/displayable/bases/inline_prompt_node/constants.py +13 -0
- vellum/workflows/nodes/displayable/bases/inline_prompt_node/node.py +118 -0
- vellum/workflows/nodes/displayable/bases/prompt_deployment_node.py +98 -0
- vellum/workflows/nodes/displayable/bases/search_node.py +90 -0
- vellum/workflows/nodes/displayable/code_execution_node/__init__.py +5 -0
- vellum/workflows/nodes/displayable/code_execution_node/node.py +197 -0
- vellum/workflows/nodes/displayable/code_execution_node/tests/__init__.py +0 -0
- vellum/workflows/nodes/displayable/code_execution_node/tests/fixtures/__init__.py +0 -0
- vellum/workflows/nodes/displayable/code_execution_node/tests/fixtures/main.py +3 -0
- vellum/workflows/nodes/displayable/code_execution_node/tests/test_code_execution_node.py +111 -0
- vellum/workflows/nodes/displayable/code_execution_node/utils.py +10 -0
- vellum/workflows/nodes/displayable/conditional_node/__init__.py +5 -0
- vellum/workflows/nodes/displayable/conditional_node/node.py +25 -0
- vellum/workflows/nodes/displayable/final_output_node/__init__.py +5 -0
- vellum/workflows/nodes/displayable/final_output_node/node.py +43 -0
- vellum/workflows/nodes/displayable/guardrail_node/__init__.py +5 -0
- vellum/workflows/nodes/displayable/guardrail_node/node.py +97 -0
- vellum/workflows/nodes/displayable/inline_prompt_node/__init__.py +5 -0
- vellum/workflows/nodes/displayable/inline_prompt_node/node.py +41 -0
- vellum/workflows/nodes/displayable/merge_node/__init__.py +5 -0
- vellum/workflows/nodes/displayable/merge_node/node.py +10 -0
- vellum/workflows/nodes/displayable/prompt_deployment_node/__init__.py +5 -0
- vellum/workflows/nodes/displayable/prompt_deployment_node/node.py +45 -0
- vellum/workflows/nodes/displayable/search_node/__init__.py +5 -0
- vellum/workflows/nodes/displayable/search_node/node.py +26 -0
- vellum/workflows/nodes/displayable/subworkflow_deployment_node/__init__.py +5 -0
- vellum/workflows/nodes/displayable/subworkflow_deployment_node/node.py +156 -0
- vellum/workflows/nodes/displayable/tests/__init__.py +0 -0
- vellum/workflows/nodes/displayable/tests/test_inline_text_prompt_node.py +148 -0
- vellum/workflows/nodes/displayable/tests/test_search_node_wth_text_output.py +134 -0
- vellum/workflows/nodes/displayable/tests/test_text_prompt_deployment_node.py +80 -0
- vellum/workflows/nodes/utils.py +27 -0
- vellum/workflows/outputs/__init__.py +6 -0
- vellum/workflows/outputs/base.py +196 -0
- vellum/workflows/ports/__init__.py +7 -0
- vellum/workflows/ports/node_ports.py +75 -0
- vellum/workflows/ports/port.py +75 -0
- vellum/workflows/ports/utils.py +40 -0
- vellum/workflows/references/__init__.py +17 -0
- vellum/workflows/references/environment_variable.py +20 -0
- vellum/workflows/references/execution_count.py +20 -0
- vellum/workflows/references/external_input.py +49 -0
- vellum/workflows/references/input.py +7 -0
- vellum/workflows/references/lazy.py +55 -0
- vellum/workflows/references/node.py +43 -0
- vellum/workflows/references/output.py +78 -0
- vellum/workflows/references/state_value.py +23 -0
- vellum/workflows/references/vellum_secret.py +15 -0
- vellum/workflows/references/workflow_input.py +41 -0
- vellum/workflows/resolvers/__init__.py +5 -0
- vellum/workflows/resolvers/base.py +15 -0
- vellum/workflows/runner/__init__.py +5 -0
- vellum/workflows/runner/runner.py +588 -0
- vellum/workflows/runner/types.py +18 -0
- vellum/workflows/state/__init__.py +5 -0
- vellum/workflows/state/base.py +327 -0
- vellum/workflows/state/context.py +18 -0
- vellum/workflows/state/encoder.py +57 -0
- vellum/workflows/state/store.py +28 -0
- vellum/workflows/state/tests/__init__.py +0 -0
- vellum/workflows/state/tests/test_state.py +113 -0
- vellum/workflows/types/__init__.py +0 -0
- vellum/workflows/types/core.py +91 -0
- vellum/workflows/types/generics.py +14 -0
- vellum/workflows/types/stack.py +39 -0
- vellum/workflows/types/tests/__init__.py +0 -0
- vellum/workflows/types/tests/test_utils.py +76 -0
- vellum/workflows/types/utils.py +164 -0
- vellum/workflows/utils/__init__.py +0 -0
- vellum/workflows/utils/names.py +13 -0
- vellum/workflows/utils/tests/__init__.py +0 -0
- vellum/workflows/utils/tests/test_names.py +15 -0
- vellum/workflows/utils/tests/test_vellum_variables.py +25 -0
- vellum/workflows/utils/vellum_variables.py +81 -0
- vellum/workflows/vellum_client.py +18 -0
- vellum/workflows/workflows/__init__.py +5 -0
- vellum/workflows/workflows/base.py +365 -0
- {vellum_ai-0.9.16rc2.dist-info → vellum_ai-0.9.16rc4.dist-info}/METADATA +2 -1
- {vellum_ai-0.9.16rc2.dist-info → vellum_ai-0.9.16rc4.dist-info}/RECORD +245 -7
- vellum_cli/__init__.py +72 -0
- vellum_cli/aliased_group.py +103 -0
- vellum_cli/config.py +96 -0
- vellum_cli/image_push.py +112 -0
- vellum_cli/logger.py +36 -0
- vellum_cli/pull.py +73 -0
- vellum_cli/push.py +121 -0
- vellum_cli/tests/test_config.py +100 -0
- vellum_cli/tests/test_pull.py +152 -0
- vellum_ee/workflows/__init__.py +0 -0
- vellum_ee/workflows/display/__init__.py +0 -0
- vellum_ee/workflows/display/base.py +73 -0
- vellum_ee/workflows/display/nodes/__init__.py +4 -0
- vellum_ee/workflows/display/nodes/base_node_display.py +116 -0
- vellum_ee/workflows/display/nodes/base_node_vellum_display.py +36 -0
- vellum_ee/workflows/display/nodes/get_node_display_class.py +25 -0
- vellum_ee/workflows/display/nodes/tests/__init__.py +0 -0
- vellum_ee/workflows/display/nodes/tests/test_base_node_display.py +47 -0
- vellum_ee/workflows/display/nodes/types.py +18 -0
- vellum_ee/workflows/display/nodes/utils.py +33 -0
- vellum_ee/workflows/display/nodes/vellum/__init__.py +32 -0
- vellum_ee/workflows/display/nodes/vellum/api_node.py +205 -0
- vellum_ee/workflows/display/nodes/vellum/code_execution_node.py +71 -0
- vellum_ee/workflows/display/nodes/vellum/conditional_node.py +217 -0
- vellum_ee/workflows/display/nodes/vellum/final_output_node.py +61 -0
- vellum_ee/workflows/display/nodes/vellum/guardrail_node.py +49 -0
- vellum_ee/workflows/display/nodes/vellum/inline_prompt_node.py +170 -0
- vellum_ee/workflows/display/nodes/vellum/inline_subworkflow_node.py +99 -0
- vellum_ee/workflows/display/nodes/vellum/map_node.py +100 -0
- vellum_ee/workflows/display/nodes/vellum/merge_node.py +48 -0
- vellum_ee/workflows/display/nodes/vellum/prompt_deployment_node.py +68 -0
- vellum_ee/workflows/display/nodes/vellum/search_node.py +193 -0
- vellum_ee/workflows/display/nodes/vellum/subworkflow_deployment_node.py +58 -0
- vellum_ee/workflows/display/nodes/vellum/templating_node.py +67 -0
- vellum_ee/workflows/display/nodes/vellum/tests/__init__.py +0 -0
- vellum_ee/workflows/display/nodes/vellum/tests/test_utils.py +106 -0
- vellum_ee/workflows/display/nodes/vellum/try_node.py +38 -0
- vellum_ee/workflows/display/nodes/vellum/utils.py +76 -0
- vellum_ee/workflows/display/tests/__init__.py +0 -0
- vellum_ee/workflows/display/tests/workflow_serialization/__init__.py +0 -0
- vellum_ee/workflows/display/tests/workflow_serialization/test_basic_api_node_serialization.py +426 -0
- vellum_ee/workflows/display/tests/workflow_serialization/test_basic_code_execution_node_serialization.py +607 -0
- vellum_ee/workflows/display/tests/workflow_serialization/test_basic_conditional_node_serialization.py +1175 -0
- vellum_ee/workflows/display/tests/workflow_serialization/test_basic_guardrail_node_serialization.py +235 -0
- vellum_ee/workflows/display/tests/workflow_serialization/test_basic_inline_subworkflow_serialization.py +511 -0
- vellum_ee/workflows/display/tests/workflow_serialization/test_basic_map_node_serialization.py +372 -0
- vellum_ee/workflows/display/tests/workflow_serialization/test_basic_merge_node_serialization.py +272 -0
- vellum_ee/workflows/display/tests/workflow_serialization/test_basic_prompt_deployment_serialization.py +289 -0
- vellum_ee/workflows/display/tests/workflow_serialization/test_basic_subworkflow_deployment_serialization.py +354 -0
- vellum_ee/workflows/display/tests/workflow_serialization/test_basic_terminal_node_serialization.py +123 -0
- vellum_ee/workflows/display/tests/workflow_serialization/test_basic_try_node_serialization.py +84 -0
- vellum_ee/workflows/display/tests/workflow_serialization/test_complex_terminal_node_serialization.py +233 -0
- vellum_ee/workflows/display/types.py +46 -0
- vellum_ee/workflows/display/utils/__init__.py +0 -0
- vellum_ee/workflows/display/utils/tests/__init__.py +0 -0
- vellum_ee/workflows/display/utils/tests/test_uuids.py +16 -0
- vellum_ee/workflows/display/utils/uuids.py +24 -0
- vellum_ee/workflows/display/utils/vellum.py +121 -0
- vellum_ee/workflows/display/vellum.py +357 -0
- vellum_ee/workflows/display/workflows/__init__.py +5 -0
- vellum_ee/workflows/display/workflows/base_workflow_display.py +302 -0
- vellum_ee/workflows/display/workflows/get_vellum_workflow_display_class.py +32 -0
- vellum_ee/workflows/display/workflows/vellum_workflow_display.py +386 -0
- {vellum_ai-0.9.16rc2.dist-info → vellum_ai-0.9.16rc4.dist-info}/LICENSE +0 -0
- {vellum_ai-0.9.16rc2.dist-info → vellum_ai-0.9.16rc4.dist-info}/WHEEL +0 -0
- {vellum_ai-0.9.16rc2.dist-info → vellum_ai-0.9.16rc4.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
from uuid import UUID
|
2
|
+
from typing import Any, Generic, Optional, TypeVar
|
3
|
+
|
4
|
+
from vellum_ee.workflows.display.nodes.base_node_vellum_display import BaseNodeVellumDisplay
|
5
|
+
from vellum_ee.workflows.display.nodes.utils import raise_if_descriptor
|
6
|
+
from vellum_ee.workflows.display.nodes.vellum.utils import create_node_input
|
7
|
+
from vellum_ee.workflows.display.types import WorkflowDisplayContext
|
8
|
+
from vellum.workflows.nodes import SubworkflowDeploymentNode
|
9
|
+
from vellum.workflows.types.core import JsonObject
|
10
|
+
from vellum.workflows.vellum_client import create_vellum_client
|
11
|
+
|
12
|
+
_SubworkflowDeploymentNodeType = TypeVar("_SubworkflowDeploymentNodeType", bound=SubworkflowDeploymentNode)
|
13
|
+
|
14
|
+
|
15
|
+
class BaseSubworkflowDeploymentNodeDisplay(
|
16
|
+
BaseNodeVellumDisplay[_SubworkflowDeploymentNodeType], Generic[_SubworkflowDeploymentNodeType]
|
17
|
+
):
|
18
|
+
def serialize(
|
19
|
+
self, display_context: WorkflowDisplayContext, error_output_id: Optional[UUID] = None, **kwargs: Any
|
20
|
+
) -> JsonObject:
|
21
|
+
node = self._node
|
22
|
+
node_id = self.node_id
|
23
|
+
|
24
|
+
subworkflow_inputs = raise_if_descriptor(node.subworkflow_inputs)
|
25
|
+
node_inputs = [
|
26
|
+
create_node_input(
|
27
|
+
node_id=node_id,
|
28
|
+
input_name=variable_name,
|
29
|
+
value=variable_value,
|
30
|
+
display_context=display_context,
|
31
|
+
input_id=None,
|
32
|
+
)
|
33
|
+
for variable_name, variable_value in subworkflow_inputs.items()
|
34
|
+
]
|
35
|
+
|
36
|
+
# TODO: Pass through the name instead of retrieving the ID
|
37
|
+
# https://app.shortcut.com/vellum/story/4702
|
38
|
+
vellum_client = create_vellum_client()
|
39
|
+
deployment = vellum_client.workflow_deployments.retrieve(
|
40
|
+
id=str(raise_if_descriptor(node.deployment)),
|
41
|
+
)
|
42
|
+
|
43
|
+
return {
|
44
|
+
"id": str(node_id),
|
45
|
+
"type": "SUBWORKFLOW",
|
46
|
+
"inputs": [node_input.dict() for node_input in node_inputs],
|
47
|
+
"data": {
|
48
|
+
"label": self.label,
|
49
|
+
"error_output_id": str(error_output_id) if error_output_id else None,
|
50
|
+
"source_handle_id": str(self.get_source_handle_id(display_context.port_displays)),
|
51
|
+
"target_handle_id": str(self.get_target_handle_id()),
|
52
|
+
"variant": "DEPLOYMENT",
|
53
|
+
"workflow_deployment_id": str(deployment.id),
|
54
|
+
"release_tag": raise_if_descriptor(node.release_tag),
|
55
|
+
},
|
56
|
+
"display_data": self.get_display_data().dict(),
|
57
|
+
"definition": self.get_definition().dict(),
|
58
|
+
}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
from uuid import UUID
|
2
|
+
from typing import Any, ClassVar, Dict, Generic, Optional, TypeVar
|
3
|
+
|
4
|
+
from vellum_ee.workflows.display.nodes.base_node_vellum_display import BaseNodeVellumDisplay
|
5
|
+
from vellum_ee.workflows.display.nodes.utils import raise_if_descriptor
|
6
|
+
from vellum_ee.workflows.display.nodes.vellum.utils import create_node_input
|
7
|
+
from vellum_ee.workflows.display.types import WorkflowDisplayContext
|
8
|
+
from vellum.workflows.nodes.core.templating_node import TemplatingNode
|
9
|
+
from vellum.workflows.types.core import JsonObject
|
10
|
+
from vellum.workflows.utils.vellum_variables import primitive_type_to_vellum_variable_type
|
11
|
+
|
12
|
+
_TemplatingNodeType = TypeVar("_TemplatingNodeType", bound=TemplatingNode)
|
13
|
+
|
14
|
+
|
15
|
+
class BaseTemplatingNodeDisplay(BaseNodeVellumDisplay[_TemplatingNodeType], Generic[_TemplatingNodeType]):
|
16
|
+
output_id: ClassVar[Optional[UUID]] = None
|
17
|
+
template_input_id: ClassVar[Optional[UUID]] = None
|
18
|
+
input_ids_by_name: ClassVar[Dict[str, UUID]] = {}
|
19
|
+
|
20
|
+
def serialize(
|
21
|
+
self, display_context: WorkflowDisplayContext, error_output_id: Optional[UUID] = None, **kwargs: Any
|
22
|
+
) -> JsonObject:
|
23
|
+
node = self._node
|
24
|
+
node_id = self.node_id
|
25
|
+
|
26
|
+
template_node_input = create_node_input(
|
27
|
+
node_id=node_id,
|
28
|
+
input_name="template",
|
29
|
+
value=node.template,
|
30
|
+
display_context=display_context,
|
31
|
+
input_id=self.template_input_id,
|
32
|
+
)
|
33
|
+
template_node_inputs = raise_if_descriptor(node.inputs)
|
34
|
+
template_inputs = [
|
35
|
+
create_node_input(
|
36
|
+
node_id=node_id,
|
37
|
+
input_name=variable_name,
|
38
|
+
value=variable_value,
|
39
|
+
display_context=display_context,
|
40
|
+
input_id=self.input_ids_by_name.get("template"),
|
41
|
+
)
|
42
|
+
for variable_name, variable_value in template_node_inputs.items()
|
43
|
+
]
|
44
|
+
node_inputs = [template_node_input, *template_inputs]
|
45
|
+
|
46
|
+
# Misc type ignore is due to `node.Outputs` being generic
|
47
|
+
# https://app.shortcut.com/vellum/story/4784
|
48
|
+
output_descriptor = node.Outputs.result # type: ignore [misc]
|
49
|
+
_, output_display = display_context.node_output_displays[output_descriptor]
|
50
|
+
inferred_output_type = primitive_type_to_vellum_variable_type(output_descriptor)
|
51
|
+
|
52
|
+
return {
|
53
|
+
"id": str(node_id),
|
54
|
+
"type": "TEMPLATING",
|
55
|
+
"inputs": [node_input.dict() for node_input in node_inputs],
|
56
|
+
"data": {
|
57
|
+
"label": self.label,
|
58
|
+
"output_id": str(output_display.id),
|
59
|
+
"error_output_id": str(error_output_id) if error_output_id else None,
|
60
|
+
"source_handle_id": str(self.get_source_handle_id(display_context.port_displays)),
|
61
|
+
"target_handle_id": str(self.get_target_handle_id()),
|
62
|
+
"template_node_input_id": str(template_node_input.id),
|
63
|
+
"output_type": inferred_output_type,
|
64
|
+
},
|
65
|
+
"display_data": self.get_display_data().dict(),
|
66
|
+
"definition": self.get_definition().dict(),
|
67
|
+
}
|
File without changes
|
@@ -0,0 +1,106 @@
|
|
1
|
+
import pytest
|
2
|
+
from uuid import UUID, uuid4
|
3
|
+
from typing import List, cast
|
4
|
+
|
5
|
+
from vellum_ee.workflows.display.nodes.base_node_vellum_display import BaseNodeVellumDisplay
|
6
|
+
from vellum_ee.workflows.display.nodes.types import NodeOutputDisplay
|
7
|
+
from vellum_ee.workflows.display.nodes.vellum.utils import create_node_input_value_pointer_rules
|
8
|
+
from vellum_ee.workflows.display.types import WorkflowDisplayContext
|
9
|
+
from vellum_ee.workflows.display.vellum import (
|
10
|
+
ConstantValuePointer,
|
11
|
+
InputVariableData,
|
12
|
+
InputVariablePointer,
|
13
|
+
NodeDisplayData,
|
14
|
+
NodeInputValuePointerRule,
|
15
|
+
NodeOutputData,
|
16
|
+
NodeOutputPointer,
|
17
|
+
StringVellumValue,
|
18
|
+
WorkflowInputsVellumDisplayOverrides,
|
19
|
+
WorkflowMetaVellumDisplay,
|
20
|
+
)
|
21
|
+
from vellum_ee.workflows.display.workflows.vellum_workflow_display import VellumWorkflowDisplay
|
22
|
+
from vellum.workflows.descriptors.base import BaseDescriptor
|
23
|
+
from vellum.workflows.inputs import BaseInputs
|
24
|
+
from vellum.workflows.nodes.bases import BaseNode
|
25
|
+
from vellum.workflows.outputs import BaseOutputs
|
26
|
+
from vellum.workflows.references import OutputReference, WorkflowInputReference
|
27
|
+
|
28
|
+
|
29
|
+
class Inputs(BaseInputs):
|
30
|
+
example_workflow_input: str
|
31
|
+
|
32
|
+
|
33
|
+
class MyNodeA(BaseNode):
|
34
|
+
example_node_input = Inputs.example_workflow_input
|
35
|
+
|
36
|
+
class Outputs(BaseOutputs):
|
37
|
+
output: str
|
38
|
+
|
39
|
+
|
40
|
+
class MyNodeB(BaseNode):
|
41
|
+
example = MyNodeA.Outputs.output
|
42
|
+
fallback_example = MyNodeA.Outputs.output.coalesce(Inputs.example_workflow_input).coalesce("fallback")
|
43
|
+
|
44
|
+
|
45
|
+
@pytest.mark.parametrize(
|
46
|
+
["descriptor", "expected_rules"],
|
47
|
+
[
|
48
|
+
(
|
49
|
+
MyNodeB.example,
|
50
|
+
[
|
51
|
+
NodeOutputPointer(
|
52
|
+
data=NodeOutputData(
|
53
|
+
node_id="b48fa5e0-d7d3-4fe3-ae48-615415011cc5",
|
54
|
+
output_id="4b16a629-11a1-4b3f-a965-a57b872d13b8",
|
55
|
+
)
|
56
|
+
)
|
57
|
+
],
|
58
|
+
),
|
59
|
+
(
|
60
|
+
MyNodeB.fallback_example,
|
61
|
+
[
|
62
|
+
NodeOutputPointer(
|
63
|
+
type="NODE_OUTPUT",
|
64
|
+
data=NodeOutputData(
|
65
|
+
node_id="b48fa5e0-d7d3-4fe3-ae48-615415011cc5",
|
66
|
+
output_id="4b16a629-11a1-4b3f-a965-a57b872d13b8",
|
67
|
+
),
|
68
|
+
),
|
69
|
+
InputVariablePointer(
|
70
|
+
type="INPUT_VARIABLE",
|
71
|
+
data=InputVariableData(input_variable_id="a154c29d-fac0-4cd0-ba88-bc52034f5470"),
|
72
|
+
),
|
73
|
+
ConstantValuePointer(type="CONSTANT_VALUE", data=StringVellumValue(type="STRING", value="fallback")),
|
74
|
+
],
|
75
|
+
),
|
76
|
+
],
|
77
|
+
)
|
78
|
+
def test_create_node_input_value_pointer_rules(
|
79
|
+
descriptor: BaseDescriptor, expected_rules: List[NodeInputValuePointerRule]
|
80
|
+
) -> None:
|
81
|
+
rules = create_node_input_value_pointer_rules(
|
82
|
+
descriptor,
|
83
|
+
WorkflowDisplayContext(
|
84
|
+
workflow_display_class=VellumWorkflowDisplay,
|
85
|
+
workflow_display=WorkflowMetaVellumDisplay(
|
86
|
+
entrypoint_node_id=uuid4(),
|
87
|
+
entrypoint_node_source_handle_id=uuid4(),
|
88
|
+
entrypoint_node_display=NodeDisplayData(),
|
89
|
+
),
|
90
|
+
workflow_input_displays={
|
91
|
+
cast(WorkflowInputReference, Inputs.example_workflow_input): WorkflowInputsVellumDisplayOverrides(
|
92
|
+
id=UUID("a154c29d-fac0-4cd0-ba88-bc52034f5470"),
|
93
|
+
),
|
94
|
+
},
|
95
|
+
node_output_displays={
|
96
|
+
cast(OutputReference, MyNodeA.Outputs.output): (
|
97
|
+
MyNodeA,
|
98
|
+
NodeOutputDisplay(id=UUID("4b16a629-11a1-4b3f-a965-a57b872d13b8"), name="output"),
|
99
|
+
),
|
100
|
+
},
|
101
|
+
node_displays={
|
102
|
+
MyNodeA: BaseNodeVellumDisplay(MyNodeA),
|
103
|
+
},
|
104
|
+
),
|
105
|
+
)
|
106
|
+
assert rules == expected_rules
|
@@ -0,0 +1,38 @@
|
|
1
|
+
from uuid import UUID
|
2
|
+
from typing import Any, ClassVar, Generic, Optional, TypeVar
|
3
|
+
|
4
|
+
from vellum_ee.workflows.display.nodes.base_node_vellum_display import BaseNodeVellumDisplay
|
5
|
+
from vellum_ee.workflows.display.nodes.get_node_display_class import get_node_display_class
|
6
|
+
from vellum_ee.workflows.display.types import WorkflowDisplayContext
|
7
|
+
from vellum_ee.workflows.display.utils.uuids import uuid4_from_hash
|
8
|
+
from vellum.workflows.nodes.core.try_node.node import TryNode
|
9
|
+
from vellum.workflows.nodes.utils import get_wrapped_node
|
10
|
+
from vellum.workflows.types.core import JsonObject
|
11
|
+
|
12
|
+
_TryNodeType = TypeVar("_TryNodeType", bound=TryNode)
|
13
|
+
|
14
|
+
|
15
|
+
class BaseTryNodeDisplay(BaseNodeVellumDisplay[_TryNodeType], Generic[_TryNodeType]):
|
16
|
+
error_output_id: ClassVar[Optional[UUID]] = None
|
17
|
+
|
18
|
+
def serialize(self, display_context: WorkflowDisplayContext, **kwargs: Any) -> JsonObject:
|
19
|
+
node = self._node
|
20
|
+
|
21
|
+
try:
|
22
|
+
inner_node = get_wrapped_node(node)
|
23
|
+
except TypeError:
|
24
|
+
raise NotImplementedError(
|
25
|
+
"Unable to serialize Try Nodes that wrap subworkflows containing more than one Node."
|
26
|
+
)
|
27
|
+
|
28
|
+
# We need the node display class of the underlying node because
|
29
|
+
# it contains the logic for serializing the node and potential display overrides
|
30
|
+
node_display_class = get_node_display_class(BaseNodeVellumDisplay, inner_node)
|
31
|
+
node_display = node_display_class(inner_node)
|
32
|
+
|
33
|
+
serialized_node = node_display.serialize(
|
34
|
+
display_context,
|
35
|
+
error_output_id=str(self.error_output_id or uuid4_from_hash(f"{node_display.node_id}|error_output_id")),
|
36
|
+
)
|
37
|
+
|
38
|
+
return serialized_node
|
@@ -0,0 +1,76 @@
|
|
1
|
+
from uuid import UUID
|
2
|
+
from typing import Any, List, Optional, cast
|
3
|
+
|
4
|
+
from vellum_ee.workflows.display.types import WorkflowDisplayContext
|
5
|
+
from vellum_ee.workflows.display.utils.uuids import uuid4_from_hash
|
6
|
+
from vellum_ee.workflows.display.utils.vellum import create_node_input_value_pointer_rule, primitive_to_vellum_value
|
7
|
+
from vellum_ee.workflows.display.vellum import (
|
8
|
+
ConstantValuePointer,
|
9
|
+
NodeInput,
|
10
|
+
NodeInputValuePointer,
|
11
|
+
NodeInputValuePointerRule,
|
12
|
+
)
|
13
|
+
from vellum.workflows.descriptors.base import BaseDescriptor
|
14
|
+
from vellum.workflows.expressions.coalesce_expression import CoalesceExpression
|
15
|
+
from vellum.workflows.nodes.utils import get_wrapped_node, has_wrapped_node
|
16
|
+
from vellum.workflows.references import NodeReference, OutputReference
|
17
|
+
|
18
|
+
|
19
|
+
def create_node_input(
|
20
|
+
node_id: UUID,
|
21
|
+
input_name: str,
|
22
|
+
value: Any,
|
23
|
+
display_context: WorkflowDisplayContext,
|
24
|
+
input_id: Optional[UUID],
|
25
|
+
) -> NodeInput:
|
26
|
+
input_id = input_id or uuid4_from_hash(f"{node_id}|{input_name}")
|
27
|
+
if (
|
28
|
+
isinstance(value, OutputReference)
|
29
|
+
and value.outputs_class._node_class
|
30
|
+
and has_wrapped_node(value.outputs_class._node_class)
|
31
|
+
):
|
32
|
+
wrapped_node = get_wrapped_node(value.outputs_class._node_class)
|
33
|
+
if wrapped_node._is_wrapped_node:
|
34
|
+
value = getattr(wrapped_node.Outputs, value.name)
|
35
|
+
|
36
|
+
rules = create_node_input_value_pointer_rules(value, display_context)
|
37
|
+
return NodeInput(
|
38
|
+
id=str(input_id),
|
39
|
+
key=input_name,
|
40
|
+
value=NodeInputValuePointer(
|
41
|
+
rules=rules,
|
42
|
+
combinator="OR",
|
43
|
+
),
|
44
|
+
)
|
45
|
+
|
46
|
+
|
47
|
+
def create_node_input_value_pointer_rules(
|
48
|
+
value: Any,
|
49
|
+
display_context: WorkflowDisplayContext,
|
50
|
+
existing_rules: Optional[List[NodeInputValuePointerRule]] = None,
|
51
|
+
) -> List[NodeInputValuePointerRule]:
|
52
|
+
node_input_value_pointer_rules: List[NodeInputValuePointerRule] = existing_rules or []
|
53
|
+
|
54
|
+
if isinstance(value, BaseDescriptor):
|
55
|
+
if isinstance(value, NodeReference):
|
56
|
+
if not value.instance:
|
57
|
+
raise ValueError(f"Expected NodeReference {value.name} to have an instance")
|
58
|
+
value = cast(BaseDescriptor, value.instance)
|
59
|
+
|
60
|
+
if isinstance(value, CoalesceExpression):
|
61
|
+
# Recursively handle the left-hand side
|
62
|
+
lhs_rules = create_node_input_value_pointer_rules(value.lhs, display_context, [])
|
63
|
+
node_input_value_pointer_rules.extend(lhs_rules)
|
64
|
+
|
65
|
+
# Handle the right-hand side
|
66
|
+
if not isinstance(value.rhs, CoalesceExpression):
|
67
|
+
rhs_rules = create_node_input_value_pointer_rules(value.rhs, display_context, [])
|
68
|
+
node_input_value_pointer_rules.extend(rhs_rules)
|
69
|
+
else:
|
70
|
+
# Non-CoalesceExpression case
|
71
|
+
node_input_value_pointer_rules.append(create_node_input_value_pointer_rule(value, display_context))
|
72
|
+
else:
|
73
|
+
vellum_variable_value = primitive_to_vellum_value(value)
|
74
|
+
node_input_value_pointer_rules.append(ConstantValuePointer(type="CONSTANT_VALUE", data=vellum_variable_value))
|
75
|
+
|
76
|
+
return node_input_value_pointer_rules
|
File without changes
|
File without changes
|