vellum-ai 0.13.2__py3-none-any.whl → 0.13.3__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.
- vellum/client/core/client_wrapper.py +1 -1
- vellum/workflows/nodes/core/templating_node/node.py +27 -1
- vellum/workflows/nodes/core/templating_node/tests/test_templating_node.py +30 -0
- {vellum_ai-0.13.2.dist-info → vellum_ai-0.13.3.dist-info}/METADATA +2 -2
- {vellum_ai-0.13.2.dist-info → vellum_ai-0.13.3.dist-info}/RECORD +8 -8
- {vellum_ai-0.13.2.dist-info → vellum_ai-0.13.3.dist-info}/LICENSE +0 -0
- {vellum_ai-0.13.2.dist-info → vellum_ai-0.13.3.dist-info}/WHEEL +0 -0
- {vellum_ai-0.13.2.dist-info → vellum_ai-0.13.3.dist-info}/entry_points.txt +0 -0
@@ -18,7 +18,7 @@ class BaseClientWrapper:
|
|
18
18
|
headers: typing.Dict[str, str] = {
|
19
19
|
"X-Fern-Language": "Python",
|
20
20
|
"X-Fern-SDK-Name": "vellum-ai",
|
21
|
-
"X-Fern-SDK-Version": "0.13.
|
21
|
+
"X-Fern-SDK-Version": "0.13.3",
|
22
22
|
}
|
23
23
|
headers["X_API_KEY"] = self.api_key
|
24
24
|
return headers
|
@@ -1,5 +1,7 @@
|
|
1
1
|
import json
|
2
|
-
from typing import Any, Callable, ClassVar, Dict, Generic, Mapping, Tuple, Type, TypeVar, Union, get_args
|
2
|
+
from typing import Any, Callable, ClassVar, Dict, Generic, Mapping, Tuple, Type, TypeVar, Union, get_args, get_origin
|
3
|
+
|
4
|
+
from pydantic import BaseModel
|
3
5
|
|
4
6
|
from vellum.utils.templating.constants import DEFAULT_JINJA_CUSTOM_FILTERS, DEFAULT_JINJA_GLOBALS
|
5
7
|
from vellum.utils.templating.exceptions import JinjaTemplateError
|
@@ -71,6 +73,7 @@ class TemplatingNode(BaseNode[StateType], Generic[StateType, _OutputType], metac
|
|
71
73
|
original_base = get_original_base(self.__class__)
|
72
74
|
all_args = get_args(original_base)
|
73
75
|
|
76
|
+
output_type: Any
|
74
77
|
if len(all_args) < 2 or isinstance(all_args[1], TypeVar):
|
75
78
|
output_type = str
|
76
79
|
else:
|
@@ -88,12 +91,35 @@ class TemplatingNode(BaseNode[StateType], Generic[StateType, _OutputType], metac
|
|
88
91
|
if output_type is bool:
|
89
92
|
return bool(rendered_template)
|
90
93
|
|
94
|
+
if get_origin(output_type) is list:
|
95
|
+
try:
|
96
|
+
data = json.loads(rendered_template)
|
97
|
+
except json.JSONDecodeError:
|
98
|
+
raise ValueError("Invalid JSON Array format for rendered_template")
|
99
|
+
|
100
|
+
if not isinstance(data, list):
|
101
|
+
raise ValueError(f"Expected a list of items for rendered_template, received {data.__class__.__name__}")
|
102
|
+
|
103
|
+
inner_type = get_args(output_type)[0]
|
104
|
+
if issubclass(inner_type, BaseModel):
|
105
|
+
return [inner_type.model_validate(item) for item in data]
|
106
|
+
else:
|
107
|
+
return data
|
108
|
+
|
91
109
|
if output_type is Json:
|
92
110
|
try:
|
93
111
|
return json.loads(rendered_template)
|
94
112
|
except json.JSONDecodeError:
|
95
113
|
raise ValueError("Invalid JSON format for rendered_template")
|
96
114
|
|
115
|
+
if issubclass(output_type, BaseModel):
|
116
|
+
try:
|
117
|
+
data = json.loads(rendered_template)
|
118
|
+
except json.JSONDecodeError:
|
119
|
+
raise ValueError("Invalid JSON format for rendered_template")
|
120
|
+
|
121
|
+
return output_type.model_validate(data)
|
122
|
+
|
97
123
|
raise ValueError(f"Unsupported output type: {output_type}")
|
98
124
|
|
99
125
|
def run(self) -> Outputs:
|
@@ -1,5 +1,7 @@
|
|
1
1
|
import json
|
2
|
+
from typing import List
|
2
3
|
|
4
|
+
from vellum.client.types.chat_message import ChatMessage
|
3
5
|
from vellum.client.types.function_call import FunctionCall
|
4
6
|
from vellum.workflows.nodes.bases.base import BaseNode
|
5
7
|
from vellum.workflows.nodes.core.templating_node.node import TemplatingNode
|
@@ -125,3 +127,31 @@ def test_templating_node__pydantic_to_json():
|
|
125
127
|
|
126
128
|
# THEN the output is the expected JSON
|
127
129
|
assert outputs.result == {"name": "test", "arguments": {"key": "value"}, "id": None}
|
130
|
+
|
131
|
+
|
132
|
+
def test_templating_node__chat_history_output():
|
133
|
+
# GIVEN a templating node that outputs a chat history
|
134
|
+
class ChatHistoryTemplateNode(TemplatingNode[BaseState, List[ChatMessage]]):
|
135
|
+
template = '[{"role": "USER", "text": "Hello"}]'
|
136
|
+
inputs = {}
|
137
|
+
|
138
|
+
# WHEN the node is run
|
139
|
+
node = ChatHistoryTemplateNode()
|
140
|
+
outputs = node.run()
|
141
|
+
|
142
|
+
# THEN the output is the expected chat history
|
143
|
+
assert outputs.result == [ChatMessage(role="USER", text="Hello")]
|
144
|
+
|
145
|
+
|
146
|
+
def test_templating_node__function_call_output():
|
147
|
+
# GIVEN a templating node that outputs a function call
|
148
|
+
class FunctionCallTemplateNode(TemplatingNode[BaseState, FunctionCall]):
|
149
|
+
template = '{"name": "test", "arguments": {"key": "value"}}'
|
150
|
+
inputs = {}
|
151
|
+
|
152
|
+
# WHEN the node is run
|
153
|
+
node = FunctionCallTemplateNode()
|
154
|
+
outputs = node.run()
|
155
|
+
|
156
|
+
# THEN the output is the expected function call
|
157
|
+
assert outputs.result == FunctionCall(name="test", arguments={"key": "value"})
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: vellum-ai
|
3
|
-
Version: 0.13.
|
3
|
+
Version: 0.13.3
|
4
4
|
Summary:
|
5
5
|
License: MIT
|
6
6
|
Requires-Python: >=3.9,<4.0
|
@@ -20,7 +20,7 @@ Classifier: Programming Language :: Python :: 3.12
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.8
|
21
21
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
22
22
|
Classifier: Typing :: Typed
|
23
|
-
Requires-Dist: Jinja2 (
|
23
|
+
Requires-Dist: Jinja2 (>=3.1.2,<4.0.0)
|
24
24
|
Requires-Dist: cdktf (>=0.20.5,<0.21.0)
|
25
25
|
Requires-Dist: click (==8.1.7)
|
26
26
|
Requires-Dist: docker (==7.1.0)
|
@@ -90,7 +90,7 @@ vellum/client/README.md,sha256=JkCJjmMZl4jrPj46pkmL9dpK4gSzQQmP5I7z4aME4LY,4749
|
|
90
90
|
vellum/client/__init__.py,sha256=8nZt88C9SVwWanjLbIQMU3rzb32h5UZfFMBx3VPHB50,111887
|
91
91
|
vellum/client/core/__init__.py,sha256=SQ85PF84B9MuKnBwHNHWemSGuy-g_515gFYNFhvEE0I,1438
|
92
92
|
vellum/client/core/api_error.py,sha256=RE8LELok2QCjABadECTvtDp7qejA1VmINCh6TbqPwSE,426
|
93
|
-
vellum/client/core/client_wrapper.py,sha256=
|
93
|
+
vellum/client/core/client_wrapper.py,sha256=BXgs_0BJXe25LvUtKqWjshTlgNC0aIIpzHAD8cSh1p0,1868
|
94
94
|
vellum/client/core/datetime_utils.py,sha256=nBys2IsYrhPdszxGKCNRPSOCwa-5DWOHG95FB8G9PKo,1047
|
95
95
|
vellum/client/core/file.py,sha256=X9IbmkZmB2bB_DpmZAO3crWdXagOakAyn6UCOCImCPg,2322
|
96
96
|
vellum/client/core/http_client.py,sha256=R0pQpCppnEtxccGvXl4uJ76s7ro_65Fo_erlNNLp_AI,19228
|
@@ -1304,8 +1304,8 @@ vellum/workflows/nodes/core/retry_node/node.py,sha256=QEpxhKOyxDkRoAn2b0PToZWtAG
|
|
1304
1304
|
vellum/workflows/nodes/core/retry_node/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
1305
1305
|
vellum/workflows/nodes/core/retry_node/tests/test_node.py,sha256=RM_OHwxrHwyxvlQQBJPqVBxpedFuWQ9h2-Xa3kP75sc,4399
|
1306
1306
|
vellum/workflows/nodes/core/templating_node/__init__.py,sha256=GmyuYo81_A1_Bz6id69ozVFS6FKiuDsZTiA3I6MaL2U,70
|
1307
|
-
vellum/workflows/nodes/core/templating_node/node.py,sha256=
|
1308
|
-
vellum/workflows/nodes/core/templating_node/tests/test_templating_node.py,sha256=
|
1307
|
+
vellum/workflows/nodes/core/templating_node/node.py,sha256=GxsVS1FoV84kOtluu00V8H74MEnYvEf55p8mt4ub-5w,5188
|
1308
|
+
vellum/workflows/nodes/core/templating_node/tests/test_templating_node.py,sha256=5iZWQWdJKDHMXBY8bhpb-Dpy9FTfW1HXxGUTivykZAA,4621
|
1309
1309
|
vellum/workflows/nodes/core/try_node/__init__.py,sha256=JVD4DrldTIqFQQFrubs9KtWCCc0YCAc7Fzol5ZWIWeM,56
|
1310
1310
|
vellum/workflows/nodes/core/try_node/node.py,sha256=_lTmSYCiz7lktaxpNWUCglNi8_5Sfy8Rpiov5SeKVMw,3920
|
1311
1311
|
vellum/workflows/nodes/core/try_node/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -1419,8 +1419,8 @@ vellum/workflows/vellum_client.py,sha256=ODrq_TSl-drX2aezXegf7pizpWDVJuTXH-j6528
|
|
1419
1419
|
vellum/workflows/workflows/__init__.py,sha256=KY45TqvavCCvXIkyCFMEc0dc6jTMOUci93U2DUrlZYc,66
|
1420
1420
|
vellum/workflows/workflows/base.py,sha256=k0kUWWko4fHyCqLSU_1cBK_pXZpl9MXekWiG-bdOAo0,18353
|
1421
1421
|
vellum/workflows/workflows/event_filters.py,sha256=GSxIgwrX26a1Smfd-6yss2abGCnadGsrSZGa7t7LpJA,2008
|
1422
|
-
vellum_ai-0.13.
|
1423
|
-
vellum_ai-0.13.
|
1424
|
-
vellum_ai-0.13.
|
1425
|
-
vellum_ai-0.13.
|
1426
|
-
vellum_ai-0.13.
|
1422
|
+
vellum_ai-0.13.3.dist-info/LICENSE,sha256=hOypcdt481qGNISA784bnAGWAE6tyIf9gc2E78mYC3E,1574
|
1423
|
+
vellum_ai-0.13.3.dist-info/METADATA,sha256=fhSWP8J92-m3lugLxpvbMyiYC7pNO634YrQrXDC_BoA,5334
|
1424
|
+
vellum_ai-0.13.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
1425
|
+
vellum_ai-0.13.3.dist-info/entry_points.txt,sha256=HCH4yc_V3J_nDv3qJzZ_nYS8llCHZViCDP1ejgCc5Ak,42
|
1426
|
+
vellum_ai-0.13.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|