Skip to content

Commit b85dd7b

Browse files
authored
Add defaults to ToolFilters (#93)
* Add defaults to ToolFilters * Add empty case to tool filtering tests * Rewrite the tool filtering unit test
1 parent 875e05f commit b85dd7b

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

splunklib/ai/tool_filtering.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
class ToolFilters:
2323
"""Allowlists by which Tools are filtered."""
2424

25-
allowed_names: Sequence[str]
26-
allowed_tags: Sequence[str]
25+
allowed_names: Sequence[str] | None = None
26+
allowed_tags: Sequence[str] | None = None
2727

2828

2929
def _is_allowed(tool: Tool, filters: ToolFilters) -> bool:
3030
return (
31-
tool.name in filters.allowed_names
32-
or len(set(filters.allowed_tags).intersection(tool.tags or [])) > 0
31+
tool.name in (filters.allowed_names or [])
32+
or len(set(filters.allowed_tags or []).intersection(tool.tags or [])) > 0
3333
)
3434

3535

tests/unit/ai/test_tools.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ async def no_op() -> ToolResult:
4949
@pytest.mark.parametrize(
5050
("allowed_names", "allowed_tags", "initial_tools", "expected_tools"),
5151
[
52-
(["test_tool_1"], [], TEST_TOOLS, [TEST_TOOL_1]),
53-
([], ["test_tag_2"], TEST_TOOLS, [TEST_TOOL_2, TEST_TOOL_4]),
52+
(None, None, [], []),
53+
(["test_tool_1"], None, TEST_TOOLS, [TEST_TOOL_1]),
54+
(None, ["test_tag_2"], TEST_TOOLS, [TEST_TOOL_2, TEST_TOOL_4]),
5455
(
5556
["test_tool_1"],
5657
["test_tag_2"],
@@ -61,8 +62,8 @@ async def no_op() -> ToolResult:
6162
],
6263
)
6364
def test_filtering(
64-
allowed_names: Sequence[str],
65-
allowed_tags: Sequence[str],
65+
allowed_names: Sequence[str] | None,
66+
allowed_tags: Sequence[str] | None,
6667
initial_tools: Sequence[Tool],
6768
expected_tools: Sequence[Tool],
6869
) -> None:

0 commit comments

Comments
 (0)