nvidia-nat-test 1.2.1__py3-none-any.whl → 1.3.0__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.
Potentially problematic release.
This version of nvidia-nat-test might be problematic. Click here for more details.
- nat/test/functions.py +9 -1
- nat/test/llm.py +236 -0
- nat/test/plugin.py +543 -12
- nat/test/register.py +2 -1
- nat/test/tool_test_runner.py +114 -47
- nat/test/utils.py +155 -0
- {nvidia_nat_test-1.2.1.dist-info → nvidia_nat_test-1.3.0.dist-info}/METADATA +14 -3
- nvidia_nat_test-1.3.0.dist-info/RECORD +18 -0
- nvidia_nat_test-1.3.0.dist-info/licenses/LICENSE-3rd-party.txt +5478 -0
- nvidia_nat_test-1.3.0.dist-info/licenses/LICENSE.md +201 -0
- nvidia_nat_test-1.2.1.dist-info/RECORD +0 -14
- {nvidia_nat_test-1.2.1.dist-info → nvidia_nat_test-1.3.0.dist-info}/WHEEL +0 -0
- {nvidia_nat_test-1.2.1.dist-info → nvidia_nat_test-1.3.0.dist-info}/entry_points.txt +0 -0
- {nvidia_nat_test-1.2.1.dist-info → nvidia_nat_test-1.3.0.dist-info}/top_level.txt +0 -0
nat/test/tool_test_runner.py
CHANGED
|
@@ -14,18 +14,33 @@
|
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
|
|
16
16
|
import asyncio
|
|
17
|
+
import inspect
|
|
17
18
|
import logging
|
|
18
19
|
import typing
|
|
20
|
+
from collections.abc import Sequence
|
|
19
21
|
from contextlib import asynccontextmanager
|
|
20
22
|
from unittest.mock import AsyncMock
|
|
21
23
|
from unittest.mock import MagicMock
|
|
22
24
|
|
|
25
|
+
from nat.authentication.interfaces import AuthProviderBase
|
|
23
26
|
from nat.builder.builder import Builder
|
|
24
27
|
from nat.builder.function import Function
|
|
28
|
+
from nat.builder.function import FunctionGroup
|
|
25
29
|
from nat.builder.function_info import FunctionInfo
|
|
26
30
|
from nat.cli.type_registry import GlobalTypeRegistry
|
|
31
|
+
from nat.data_models.authentication import AuthProviderBaseConfig
|
|
32
|
+
from nat.data_models.embedder import EmbedderBaseConfig
|
|
27
33
|
from nat.data_models.function import FunctionBaseConfig
|
|
34
|
+
from nat.data_models.function import FunctionGroupBaseConfig
|
|
35
|
+
from nat.data_models.function_dependencies import FunctionDependencies
|
|
36
|
+
from nat.data_models.llm import LLMBaseConfig
|
|
37
|
+
from nat.data_models.memory import MemoryBaseConfig
|
|
28
38
|
from nat.data_models.object_store import ObjectStoreBaseConfig
|
|
39
|
+
from nat.data_models.retriever import RetrieverBaseConfig
|
|
40
|
+
from nat.data_models.ttc_strategy import TTCStrategyBaseConfig
|
|
41
|
+
from nat.experimental.test_time_compute.models.stage_enums import PipelineTypeEnum
|
|
42
|
+
from nat.experimental.test_time_compute.models.stage_enums import StageTypeEnum
|
|
43
|
+
from nat.memory.interfaces import MemoryEditor
|
|
29
44
|
from nat.object_store.interfaces import ObjectStore
|
|
30
45
|
from nat.runtime.loader import PluginTypes
|
|
31
46
|
from nat.runtime.loader import discover_and_register_plugins
|
|
@@ -46,6 +61,10 @@ class MockBuilder(Builder):
|
|
|
46
61
|
"""Add a mock function that returns a fixed response."""
|
|
47
62
|
self._mocks[name] = mock_response
|
|
48
63
|
|
|
64
|
+
def mock_function_group(self, name: str, mock_response: typing.Any):
|
|
65
|
+
"""Add a mock function group that returns a fixed response."""
|
|
66
|
+
self._mocks[name] = mock_response
|
|
67
|
+
|
|
49
68
|
def mock_llm(self, name: str, mock_response: typing.Any):
|
|
50
69
|
"""Add a mock LLM that returns a fixed response."""
|
|
51
70
|
self._mocks[f"llm_{name}"] = mock_response
|
|
@@ -70,14 +89,16 @@ class MockBuilder(Builder):
|
|
|
70
89
|
"""Add a mock TTC strategy that returns a fixed response."""
|
|
71
90
|
self._mocks[f"ttc_strategy_{name}"] = mock_response
|
|
72
91
|
|
|
73
|
-
|
|
92
|
+
def mock_auth_provider(self, name: str, mock_response: typing.Any):
|
|
93
|
+
"""Add a mock auth provider that returns a fixed response."""
|
|
94
|
+
self._mocks[f"auth_provider_{name}"] = mock_response
|
|
95
|
+
|
|
96
|
+
async def add_ttc_strategy(self, name: str, config: TTCStrategyBaseConfig) -> None:
|
|
74
97
|
"""Mock implementation (no‑op)."""
|
|
75
98
|
pass
|
|
76
99
|
|
|
77
|
-
async def get_ttc_strategy(self,
|
|
78
|
-
|
|
79
|
-
pipeline_type: typing.Any = None,
|
|
80
|
-
stage_type: typing.Any = None):
|
|
100
|
+
async def get_ttc_strategy(self, strategy_name: str, pipeline_type: PipelineTypeEnum,
|
|
101
|
+
stage_type: StageTypeEnum) -> typing.Any:
|
|
81
102
|
"""Return a mock TTC strategy if one is configured."""
|
|
82
103
|
key = f"ttc_strategy_{strategy_name}"
|
|
83
104
|
if key in self._mocks:
|
|
@@ -90,16 +111,29 @@ class MockBuilder(Builder):
|
|
|
90
111
|
|
|
91
112
|
async def get_ttc_strategy_config(self,
|
|
92
113
|
strategy_name: str,
|
|
93
|
-
pipeline_type:
|
|
94
|
-
stage_type:
|
|
114
|
+
pipeline_type: PipelineTypeEnum,
|
|
115
|
+
stage_type: StageTypeEnum) -> TTCStrategyBaseConfig:
|
|
95
116
|
"""Mock implementation."""
|
|
117
|
+
return TTCStrategyBaseConfig()
|
|
118
|
+
|
|
119
|
+
async def add_auth_provider(self, name: str, config: AuthProviderBaseConfig) -> None:
|
|
120
|
+
"""Mock implementation (no‑op)."""
|
|
96
121
|
pass
|
|
97
122
|
|
|
123
|
+
async def get_auth_provider(self, auth_provider_name: str) -> AuthProviderBase:
|
|
124
|
+
"""Return a mock auth provider if one is configured."""
|
|
125
|
+
key = f"auth_provider_{auth_provider_name}"
|
|
126
|
+
if key in self._mocks:
|
|
127
|
+
mock_auth = MagicMock()
|
|
128
|
+
mock_auth.authenticate = AsyncMock(return_value=self._mocks[key])
|
|
129
|
+
return mock_auth
|
|
130
|
+
raise ValueError(f"Auth provider '{auth_provider_name}' not mocked. Use mock_auth_provider() to add it.")
|
|
131
|
+
|
|
98
132
|
async def add_function(self, name: str, config: FunctionBaseConfig) -> Function:
|
|
99
133
|
"""Mock implementation - not used in tool testing."""
|
|
100
134
|
raise NotImplementedError("Mock implementation does not support add_function")
|
|
101
135
|
|
|
102
|
-
def get_function(self, name: str) -> Function:
|
|
136
|
+
async def get_function(self, name: str) -> Function:
|
|
103
137
|
"""Return a mock function if one is configured."""
|
|
104
138
|
if name in self._mocks:
|
|
105
139
|
mock_fn = AsyncMock()
|
|
@@ -109,25 +143,49 @@ class MockBuilder(Builder):
|
|
|
109
143
|
|
|
110
144
|
def get_function_config(self, name: str) -> FunctionBaseConfig:
|
|
111
145
|
"""Mock implementation."""
|
|
112
|
-
|
|
146
|
+
return FunctionBaseConfig()
|
|
147
|
+
|
|
148
|
+
async def add_function_group(self, name: str, config: FunctionGroupBaseConfig) -> FunctionGroup:
|
|
149
|
+
"""Mock implementation - not used in tool testing."""
|
|
150
|
+
raise NotImplementedError("Mock implementation does not support add_function_group")
|
|
151
|
+
|
|
152
|
+
async def get_function_group(self, name: str) -> FunctionGroup:
|
|
153
|
+
"""Return a mock function group if one is configured."""
|
|
154
|
+
if name in self._mocks:
|
|
155
|
+
mock_fn_group = MagicMock(spec=FunctionGroup)
|
|
156
|
+
mock_fn_group.ainvoke = AsyncMock(return_value=self._mocks[name])
|
|
157
|
+
return mock_fn_group
|
|
158
|
+
raise ValueError(f"Function group '{name}' not mocked. Use mock_function_group() to add it.")
|
|
159
|
+
|
|
160
|
+
def get_function_group_config(self, name: str) -> FunctionGroupBaseConfig:
|
|
161
|
+
"""Mock implementation."""
|
|
162
|
+
return FunctionGroupBaseConfig()
|
|
113
163
|
|
|
114
164
|
async def set_workflow(self, config: FunctionBaseConfig) -> Function:
|
|
115
165
|
"""Mock implementation."""
|
|
116
|
-
|
|
166
|
+
mock_fn = AsyncMock()
|
|
167
|
+
mock_fn.ainvoke = AsyncMock(return_value="mock_workflow_result")
|
|
168
|
+
return mock_fn
|
|
117
169
|
|
|
118
170
|
def get_workflow(self) -> Function:
|
|
119
171
|
"""Mock implementation."""
|
|
120
|
-
|
|
172
|
+
mock_fn = AsyncMock()
|
|
173
|
+
mock_fn.ainvoke = AsyncMock(return_value="mock_workflow_result")
|
|
174
|
+
return mock_fn
|
|
121
175
|
|
|
122
176
|
def get_workflow_config(self) -> FunctionBaseConfig:
|
|
123
177
|
"""Mock implementation."""
|
|
124
|
-
|
|
178
|
+
return FunctionBaseConfig()
|
|
179
|
+
|
|
180
|
+
async def get_tools(self, tool_names: Sequence[str], wrapper_type) -> list[typing.Any]:
|
|
181
|
+
"""Mock implementation."""
|
|
182
|
+
return []
|
|
125
183
|
|
|
126
|
-
def get_tool(self, fn_name: str, wrapper_type):
|
|
184
|
+
async def get_tool(self, fn_name: str, wrapper_type) -> typing.Any:
|
|
127
185
|
"""Mock implementation."""
|
|
128
186
|
pass
|
|
129
187
|
|
|
130
|
-
async def add_llm(self, name: str, config):
|
|
188
|
+
async def add_llm(self, name: str, config) -> None:
|
|
131
189
|
"""Mock implementation."""
|
|
132
190
|
pass
|
|
133
191
|
|
|
@@ -141,11 +199,11 @@ class MockBuilder(Builder):
|
|
|
141
199
|
return mock_llm
|
|
142
200
|
raise ValueError(f"LLM '{llm_name}' not mocked. Use mock_llm() to add it.")
|
|
143
201
|
|
|
144
|
-
def get_llm_config(self, llm_name: str):
|
|
202
|
+
def get_llm_config(self, llm_name: str) -> LLMBaseConfig:
|
|
145
203
|
"""Mock implementation."""
|
|
146
|
-
|
|
204
|
+
return LLMBaseConfig()
|
|
147
205
|
|
|
148
|
-
async def add_embedder(self, name: str, config):
|
|
206
|
+
async def add_embedder(self, name: str, config) -> None:
|
|
149
207
|
"""Mock implementation."""
|
|
150
208
|
pass
|
|
151
209
|
|
|
@@ -159,15 +217,14 @@ class MockBuilder(Builder):
|
|
|
159
217
|
return mock_embedder
|
|
160
218
|
raise ValueError(f"Embedder '{embedder_name}' not mocked. Use mock_embedder() to add it.")
|
|
161
219
|
|
|
162
|
-
def get_embedder_config(self, embedder_name: str):
|
|
220
|
+
def get_embedder_config(self, embedder_name: str) -> EmbedderBaseConfig:
|
|
163
221
|
"""Mock implementation."""
|
|
164
|
-
|
|
222
|
+
return EmbedderBaseConfig()
|
|
165
223
|
|
|
166
|
-
async def add_memory_client(self, name: str, config):
|
|
167
|
-
|
|
168
|
-
pass
|
|
224
|
+
async def add_memory_client(self, name: str, config) -> MemoryEditor:
|
|
225
|
+
return MagicMock(spec=MemoryEditor)
|
|
169
226
|
|
|
170
|
-
def get_memory_client(self, memory_name: str):
|
|
227
|
+
async def get_memory_client(self, memory_name: str) -> MemoryEditor:
|
|
171
228
|
"""Return a mock memory client if one is configured."""
|
|
172
229
|
key = f"memory_{memory_name}"
|
|
173
230
|
if key in self._mocks:
|
|
@@ -177,11 +234,11 @@ class MockBuilder(Builder):
|
|
|
177
234
|
return mock_memory
|
|
178
235
|
raise ValueError(f"Memory client '{memory_name}' not mocked. Use mock_memory_client() to add it.")
|
|
179
236
|
|
|
180
|
-
def get_memory_client_config(self, memory_name: str):
|
|
237
|
+
def get_memory_client_config(self, memory_name: str) -> MemoryBaseConfig:
|
|
181
238
|
"""Mock implementation."""
|
|
182
|
-
|
|
239
|
+
return MemoryBaseConfig()
|
|
183
240
|
|
|
184
|
-
async def add_retriever(self, name: str, config):
|
|
241
|
+
async def add_retriever(self, name: str, config) -> None:
|
|
185
242
|
"""Mock implementation."""
|
|
186
243
|
pass
|
|
187
244
|
|
|
@@ -194,13 +251,13 @@ class MockBuilder(Builder):
|
|
|
194
251
|
return mock_retriever
|
|
195
252
|
raise ValueError(f"Retriever '{retriever_name}' not mocked. Use mock_retriever() to add it.")
|
|
196
253
|
|
|
197
|
-
async def get_retriever_config(self, retriever_name: str):
|
|
254
|
+
async def get_retriever_config(self, retriever_name: str) -> RetrieverBaseConfig:
|
|
198
255
|
"""Mock implementation."""
|
|
199
|
-
|
|
256
|
+
return RetrieverBaseConfig()
|
|
200
257
|
|
|
201
|
-
async def add_object_store(self, name: str, config: ObjectStoreBaseConfig):
|
|
258
|
+
async def add_object_store(self, name: str, config: ObjectStoreBaseConfig) -> ObjectStore:
|
|
202
259
|
"""Mock implementation for object store."""
|
|
203
|
-
|
|
260
|
+
return MagicMock(spec=ObjectStore)
|
|
204
261
|
|
|
205
262
|
async def get_object_store_client(self, object_store_name: str) -> ObjectStore:
|
|
206
263
|
"""Return a mock object store client if one is configured."""
|
|
@@ -216,7 +273,7 @@ class MockBuilder(Builder):
|
|
|
216
273
|
|
|
217
274
|
def get_object_store_config(self, object_store_name: str) -> ObjectStoreBaseConfig:
|
|
218
275
|
"""Mock implementation for object store config."""
|
|
219
|
-
|
|
276
|
+
return ObjectStoreBaseConfig()
|
|
220
277
|
|
|
221
278
|
def get_user_manager(self):
|
|
222
279
|
"""Mock implementation."""
|
|
@@ -224,9 +281,13 @@ class MockBuilder(Builder):
|
|
|
224
281
|
mock_user.get_id = MagicMock(return_value="test_user")
|
|
225
282
|
return mock_user
|
|
226
283
|
|
|
227
|
-
def get_function_dependencies(self, fn_name: str):
|
|
284
|
+
def get_function_dependencies(self, fn_name: str) -> FunctionDependencies:
|
|
228
285
|
"""Mock implementation."""
|
|
229
|
-
|
|
286
|
+
return FunctionDependencies()
|
|
287
|
+
|
|
288
|
+
def get_function_group_dependencies(self, fn_name: str) -> FunctionDependencies:
|
|
289
|
+
"""Mock implementation."""
|
|
290
|
+
return FunctionDependencies()
|
|
230
291
|
|
|
231
292
|
|
|
232
293
|
class ToolTestRunner:
|
|
@@ -322,15 +383,19 @@ class ToolTestRunner:
|
|
|
322
383
|
|
|
323
384
|
# Execute the tool
|
|
324
385
|
if input_data is not None:
|
|
325
|
-
if
|
|
386
|
+
if isinstance(tool_function, Function):
|
|
387
|
+
result = await tool_function.ainvoke(input_data)
|
|
388
|
+
elif asyncio.iscoroutinefunction(tool_function):
|
|
326
389
|
result = await tool_function(input_data)
|
|
327
390
|
else:
|
|
328
391
|
result = tool_function(input_data)
|
|
392
|
+
elif isinstance(tool_function, Function):
|
|
393
|
+
# Function objects require input, so pass None if no input_data
|
|
394
|
+
result = await tool_function.ainvoke(None)
|
|
395
|
+
elif asyncio.iscoroutinefunction(tool_function):
|
|
396
|
+
result = await tool_function()
|
|
329
397
|
else:
|
|
330
|
-
|
|
331
|
-
result = await tool_function()
|
|
332
|
-
else:
|
|
333
|
-
result = tool_function()
|
|
398
|
+
result = tool_function()
|
|
334
399
|
|
|
335
400
|
# Assert expected output if provided
|
|
336
401
|
if expected_output is not None:
|
|
@@ -402,8 +467,8 @@ class ToolTestRunner:
|
|
|
402
467
|
elif isinstance(tool_result, FunctionInfo):
|
|
403
468
|
if tool_result.single_fn:
|
|
404
469
|
tool_function = tool_result.single_fn
|
|
405
|
-
elif tool_result.
|
|
406
|
-
tool_function = tool_result.
|
|
470
|
+
elif tool_result.stream_fn:
|
|
471
|
+
tool_function = tool_result.stream_fn
|
|
407
472
|
else:
|
|
408
473
|
raise ValueError("Tool function not found in FunctionInfo")
|
|
409
474
|
elif callable(tool_result):
|
|
@@ -413,15 +478,17 @@ class ToolTestRunner:
|
|
|
413
478
|
|
|
414
479
|
# Execute the tool
|
|
415
480
|
if input_data is not None:
|
|
416
|
-
if
|
|
417
|
-
result = await tool_function(input_data)
|
|
481
|
+
if isinstance(tool_function, Function):
|
|
482
|
+
result = await tool_function.ainvoke(input_data)
|
|
418
483
|
else:
|
|
419
|
-
|
|
484
|
+
maybe_result = tool_function(input_data)
|
|
485
|
+
result = await maybe_result if inspect.isawaitable(maybe_result) else maybe_result
|
|
486
|
+
elif isinstance(tool_function, Function):
|
|
487
|
+
# Function objects require input, so pass None if no input_data
|
|
488
|
+
result = await tool_function.ainvoke(None)
|
|
420
489
|
else:
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
else:
|
|
424
|
-
result = tool_function()
|
|
490
|
+
maybe_result = tool_function()
|
|
491
|
+
result = await maybe_result if inspect.isawaitable(maybe_result) else maybe_result
|
|
425
492
|
|
|
426
493
|
# Assert expected output if provided
|
|
427
494
|
if expected_output is not None:
|
nat/test/utils.py
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
import importlib.resources
|
|
17
|
+
import inspect
|
|
18
|
+
import json
|
|
19
|
+
import subprocess
|
|
20
|
+
import typing
|
|
21
|
+
from contextlib import asynccontextmanager
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
|
|
24
|
+
if typing.TYPE_CHECKING:
|
|
25
|
+
from collections.abc import AsyncIterator
|
|
26
|
+
|
|
27
|
+
from httpx import AsyncClient
|
|
28
|
+
|
|
29
|
+
from nat.data_models.config import Config
|
|
30
|
+
from nat.front_ends.fastapi.fastapi_front_end_plugin_worker import FastApiFrontEndPluginWorker
|
|
31
|
+
from nat.utils.type_utils import StrPath
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def locate_repo_root() -> Path:
|
|
35
|
+
result = subprocess.run(["git", "rev-parse", "--show-toplevel"], check=False, capture_output=True, text=True)
|
|
36
|
+
assert result.returncode == 0, f"Failed to get git root: {result.stderr}"
|
|
37
|
+
return Path(result.stdout.strip())
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def locate_example_src_dir(example_config_class: type) -> Path:
|
|
41
|
+
"""
|
|
42
|
+
Locate the example src directory for an example's config class.
|
|
43
|
+
"""
|
|
44
|
+
package_name = inspect.getmodule(example_config_class).__package__
|
|
45
|
+
return importlib.resources.files(package_name)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def locate_example_dir(example_config_class: type) -> Path:
|
|
49
|
+
"""
|
|
50
|
+
Locate the example directory for an example's config class.
|
|
51
|
+
"""
|
|
52
|
+
src_dir = locate_example_src_dir(example_config_class)
|
|
53
|
+
example_dir = src_dir.parent.parent
|
|
54
|
+
return example_dir
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def locate_example_config(example_config_class: type,
|
|
58
|
+
config_file: str = "config.yml",
|
|
59
|
+
assert_exists: bool = True) -> Path:
|
|
60
|
+
"""
|
|
61
|
+
Locate the example config file for an example's config class, assumes the example contains a 'configs' directory
|
|
62
|
+
"""
|
|
63
|
+
example_dir = locate_example_src_dir(example_config_class)
|
|
64
|
+
config_path = example_dir.joinpath("configs", config_file).absolute()
|
|
65
|
+
if assert_exists:
|
|
66
|
+
assert config_path.exists(), f"Config file {config_path} does not exist"
|
|
67
|
+
|
|
68
|
+
return config_path
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
async def run_workflow(
|
|
72
|
+
*,
|
|
73
|
+
config: "Config | None" = None,
|
|
74
|
+
config_file: "StrPath | None" = None,
|
|
75
|
+
question: str,
|
|
76
|
+
expected_answer: str,
|
|
77
|
+
assert_expected_answer: bool = True,
|
|
78
|
+
) -> str:
|
|
79
|
+
from nat.builder.workflow_builder import WorkflowBuilder
|
|
80
|
+
from nat.runtime.loader import load_config
|
|
81
|
+
from nat.runtime.session import SessionManager
|
|
82
|
+
|
|
83
|
+
if config is None:
|
|
84
|
+
assert config_file is not None, "Either config_file or config must be provided"
|
|
85
|
+
assert Path(config_file).exists(), f"Config file {config_file} does not exist"
|
|
86
|
+
config = load_config(config_file)
|
|
87
|
+
|
|
88
|
+
async with WorkflowBuilder.from_config(config=config) as workflow_builder:
|
|
89
|
+
workflow = SessionManager(await workflow_builder.build())
|
|
90
|
+
async with workflow.run(question) as runner:
|
|
91
|
+
result = await runner.result(to_type=str)
|
|
92
|
+
|
|
93
|
+
if assert_expected_answer:
|
|
94
|
+
assert expected_answer.lower() in result.lower(), f"Expected '{expected_answer}' in '{result}'"
|
|
95
|
+
|
|
96
|
+
return result
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@asynccontextmanager
|
|
100
|
+
async def build_nat_client(
|
|
101
|
+
config: "Config",
|
|
102
|
+
worker_class: "type[FastApiFrontEndPluginWorker] | None" = None) -> "AsyncIterator[AsyncClient]":
|
|
103
|
+
"""
|
|
104
|
+
Build a NAT client for testing purposes.
|
|
105
|
+
|
|
106
|
+
Creates a test client with an ASGI transport for the specified configuration.
|
|
107
|
+
The client is backed by a FastAPI application built from the provided worker class.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
config: The NAT configuration to use for building the client.
|
|
111
|
+
worker_class: Optional worker class to use. Defaults to FastApiFrontEndPluginWorker.
|
|
112
|
+
|
|
113
|
+
Yields:
|
|
114
|
+
An AsyncClient instance configured for testing.
|
|
115
|
+
"""
|
|
116
|
+
from asgi_lifespan import LifespanManager
|
|
117
|
+
from httpx import ASGITransport
|
|
118
|
+
from httpx import AsyncClient
|
|
119
|
+
|
|
120
|
+
from nat.front_ends.fastapi.fastapi_front_end_plugin_worker import FastApiFrontEndPluginWorker
|
|
121
|
+
|
|
122
|
+
if worker_class is None:
|
|
123
|
+
worker_class = FastApiFrontEndPluginWorker
|
|
124
|
+
|
|
125
|
+
worker = worker_class(config)
|
|
126
|
+
app = worker.build_app()
|
|
127
|
+
|
|
128
|
+
async with LifespanManager(app):
|
|
129
|
+
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
|
130
|
+
yield client
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def validate_workflow_output(workflow_output_file: Path) -> None:
|
|
134
|
+
"""
|
|
135
|
+
Validate the contents of the workflow output file.
|
|
136
|
+
WIP: output format should be published as a schema and this validation should be done against that schema.
|
|
137
|
+
"""
|
|
138
|
+
# Ensure the workflow_output.json file was created
|
|
139
|
+
assert workflow_output_file.exists(), "The workflow_output.json file was not created"
|
|
140
|
+
|
|
141
|
+
# Read and validate the workflow_output.json file
|
|
142
|
+
try:
|
|
143
|
+
with open(workflow_output_file, encoding="utf-8") as f:
|
|
144
|
+
result_json = json.load(f)
|
|
145
|
+
except json.JSONDecodeError as err:
|
|
146
|
+
raise RuntimeError("Failed to parse workflow_output.json as valid JSON") from err
|
|
147
|
+
|
|
148
|
+
assert isinstance(result_json, list), "The workflow_output.json file is not a list"
|
|
149
|
+
assert len(result_json) > 0, "The workflow_output.json file is empty"
|
|
150
|
+
assert isinstance(result_json[0], dict), "The workflow_output.json file is not a list of dictionaries"
|
|
151
|
+
|
|
152
|
+
# Ensure required keys exist
|
|
153
|
+
required_keys = ["id", "question", "answer", "generated_answer", "intermediate_steps"]
|
|
154
|
+
for key in required_keys:
|
|
155
|
+
assert all(item.get(key) for item in result_json), f"The '{key}' key is missing in workflow_output.json"
|
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nvidia-nat-test
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.0
|
|
4
4
|
Summary: Testing utilities for NeMo Agent toolkit
|
|
5
|
+
Author: NVIDIA Corporation
|
|
6
|
+
Maintainer: NVIDIA Corporation
|
|
7
|
+
License: Apache-2.0
|
|
8
|
+
Project-URL: documentation, https://docs.nvidia.com/nemo/agent-toolkit/latest/
|
|
9
|
+
Project-URL: source, https://github.com/NVIDIA/NeMo-Agent-Toolkit
|
|
5
10
|
Keywords: ai,rag,agents
|
|
6
11
|
Classifier: Programming Language :: Python
|
|
7
|
-
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Requires-Python: <3.14,>=3.11
|
|
8
16
|
Description-Content-Type: text/markdown
|
|
9
|
-
|
|
17
|
+
License-File: LICENSE-3rd-party.txt
|
|
18
|
+
License-File: LICENSE.md
|
|
19
|
+
Requires-Dist: nvidia-nat==v1.3.0
|
|
10
20
|
Requires-Dist: langchain-community~=0.3
|
|
11
21
|
Requires-Dist: pytest~=8.3
|
|
22
|
+
Dynamic: license-file
|
|
12
23
|
|
|
13
24
|
<!--
|
|
14
25
|
SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
nat/meta/pypi.md,sha256=LLKJHg5oN1-M9Pqfk3Bmphkk4O2TFsyiixuK5T0Y-gw,1100
|
|
2
|
+
nat/test/__init__.py,sha256=_RnTJnsUucHvla_nYKqD4O4g8Bz0tcuDRzWk1bEhcy0,875
|
|
3
|
+
nat/test/embedder.py,sha256=ClDyK1kna4hCBSlz71gK1B-ZjlwcBHTDQRekoNM81Bs,1809
|
|
4
|
+
nat/test/functions.py,sha256=ZxXVzfaLBGOpR5qtmMrKU7q-M9-vVGGj3Xi5mrw4vHY,3557
|
|
5
|
+
nat/test/llm.py,sha256=f6bz6arAQjhjuOKFrLfu_U1LbiyFzQmpM-q8b-WKSrU,9550
|
|
6
|
+
nat/test/memory.py,sha256=xki_A2yiMhEZuQk60K7t04QRqf32nQqnfzD5Iv7fkvw,1456
|
|
7
|
+
nat/test/object_store_tests.py,sha256=PyJioOtoSzILPq6LuD-sOZ_89PIcgXWZweoHBQpK2zQ,4281
|
|
8
|
+
nat/test/plugin.py,sha256=VbKEduSIll8TlyKQtLX5LJ0LzCyXQDwCTxeirZKnrMY,22257
|
|
9
|
+
nat/test/register.py,sha256=o1BEA5fyxyFyCxXhQ6ArmtuNpgRyTEfvw6HdBgECPLI,897
|
|
10
|
+
nat/test/tool_test_runner.py,sha256=SxavwXHkvCQDl_PUiiiqgvGfexKJJTeBdI5i1qk6AzI,21712
|
|
11
|
+
nat/test/utils.py,sha256=Lml187P9SUP3IB_HhBaU1XNhiljcpOFFZOAxgQR1vQo,5936
|
|
12
|
+
nvidia_nat_test-1.3.0.dist-info/licenses/LICENSE-3rd-party.txt,sha256=fOk5jMmCX9YoKWyYzTtfgl-SUy477audFC5hNY4oP7Q,284609
|
|
13
|
+
nvidia_nat_test-1.3.0.dist-info/licenses/LICENSE.md,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
|
|
14
|
+
nvidia_nat_test-1.3.0.dist-info/METADATA,sha256=xW11lwoKQIoD6bkD-SKBUZPnkdUZshmM9FgdObuApr0,1907
|
|
15
|
+
nvidia_nat_test-1.3.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
16
|
+
nvidia_nat_test-1.3.0.dist-info/entry_points.txt,sha256=7dOP9XB6iMDqvav3gYx9VWUwA8RrFzhbAa8nGeC8e4Y,99
|
|
17
|
+
nvidia_nat_test-1.3.0.dist-info/top_level.txt,sha256=8-CJ2cP6-f0ZReXe5Hzqp-5pvzzHz-5Ds5H2bGqh1-U,4
|
|
18
|
+
nvidia_nat_test-1.3.0.dist-info/RECORD,,
|