Skip to content

Commit 0359ecb

Browse files
committed
chore: Delint
1 parent 43009d5 commit 0359ecb

File tree

6 files changed

+61
-39
lines changed

6 files changed

+61
-39
lines changed

packages/toolbox-llamaindex/src/toolbox_llamaindex/async_tools.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ def __init__(
4848

4949
@property
5050
def metadata(self) -> ToolMetadata:
51+
if self.__core_tool.__doc__ is None:
52+
raise ValueError("No description found for the tool.")
53+
5154
return ToolMetadata(
5255
name=self.__core_tool.__name__,
5356
description=self.__core_tool.__doc__,
@@ -70,7 +73,13 @@ async def acall(self, **kwargs: Any) -> ToolOutput: # type: ignore
7073
A dictionary containing the parsed JSON response from the tool
7174
invocation.
7275
"""
73-
return await self.__core_tool(**kwargs)
76+
output_content = await self.__core_tool(**kwargs)
77+
return ToolOutput(
78+
content=output_content,
79+
tool_name=self.__core_tool.__name__,
80+
raw_input=kwargs,
81+
raw_output=output_content,
82+
)
7483

7584
def add_auth_token_getters(
7685
self, auth_token_getters: dict[str, Callable[[], str]]

packages/toolbox-llamaindex/src/toolbox_llamaindex/tools.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def __init__(
3838
Args:
3939
core_tool: The underlying core sync ToolboxTool instance.
4040
"""
41-
4241
# Due to how pydantic works, we must initialize the underlying
4342
# AsyncBaseTool class before assigning values to member variables.
4443
super().__init__()
@@ -47,7 +46,9 @@ def __init__(
4746

4847
@property
4948
def metadata(self) -> ToolMetadata:
50-
async_tool = self.__async_tool
49+
if self.__core_tool.__doc__ is None:
50+
raise ValueError("No description found for the tool.")
51+
5152
return ToolMetadata(
5253
name=self.__core_tool.__name__,
5354
description=self.__core_tool.__doc__,
@@ -57,10 +58,22 @@ def metadata(self) -> ToolMetadata:
5758
)
5859

5960
def call(self, **kwargs: Any) -> ToolOutput: # type: ignore
60-
return self.__core_tool(**kwargs)
61+
output_content = self.__core_tool(**kwargs)
62+
return ToolOutput(
63+
content=output_content,
64+
tool_name=self.__core_tool.__name__,
65+
raw_input=kwargs,
66+
raw_output=output_content,
67+
)
6168

6269
async def acall(self, **kwargs: Any) -> ToolOutput: # type: ignore
63-
return await to_thread(self.__core_tool, **kwargs)
70+
output_content = await to_thread(self.__core_tool, **kwargs)
71+
return ToolOutput(
72+
content=output_content,
73+
tool_name=self.__core_tool.__name__,
74+
raw_input=kwargs,
75+
raw_output=output_content,
76+
)
6477

6578
def add_auth_token_getters(
6679
self, auth_token_getters: dict[str, Callable[[], str]]

packages/toolbox-llamaindex/tests/test_async_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ async def test_aload_tool(
136136
)
137137
assert isinstance(tool, AsyncToolboxTool)
138138
assert (
139-
tool.name == tool_name
139+
tool.metadata.name == tool_name
140140
) # AsyncToolboxTool gets its name from the core_tool
141141

142142
async def test_aload_tool_auth_headers_deprecated(self, mock_client):
@@ -236,7 +236,7 @@ async def test_aload_toolset(self, mock_client):
236236
assert len(tools) == 2
237237
for tool in tools:
238238
assert isinstance(tool, AsyncToolboxTool)
239-
assert tool.name in ["test_tool_1", "test_tool_2"]
239+
assert tool.metadata.name in ["test_tool_1", "test_tool_2"]
240240

241241
async def test_aload_toolset_with_toolset_name(self, mock_client):
242242
toolset_name = "test_toolset_1"

packages/toolbox-llamaindex/tests/test_async_tools.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ async def test_toolbox_tool_init(self, MockClientSession, tool_schema_dict):
130130
url="https://test-url",
131131
)
132132
tool = AsyncToolboxTool(core_tool=core_tool_instance)
133-
assert tool.name == "test_tool"
134-
assert tool.description == core_tool_instance.__doc__
133+
assert tool.metadata.name == "test_tool"
134+
assert tool.metadata.description == core_tool_instance.__doc__
135135

136136
@pytest.mark.parametrize(
137137
"params_to_bind",
@@ -257,10 +257,10 @@ async def test_toolbox_tool_call_requires_auth_strict(self, auth_toolbox_tool):
257257
PermissionError,
258258
match="One or more of the following authn services are required to invoke this tool: test-auth-source",
259259
):
260-
await auth_toolbox_tool.acall({"param2": 123})
260+
await auth_toolbox_tool.acall(param2=123)
261261

262262
async def test_toolbox_tool_call(self, toolbox_tool):
263-
result = await toolbox_tool.acall({"param1": "test-value", "param2": 123})
263+
result = await toolbox_tool.acall(param1="test-value", param2=123)
264264
assert result == "test-result"
265265
core_tool = toolbox_tool._AsyncToolboxTool__core_tool
266266
core_tool._ToolboxTool__session.post.assert_called_once_with(
@@ -280,7 +280,7 @@ async def test_toolbox_tool_call_with_bound_params(
280280
self, toolbox_tool, bound_param_map, expected_value
281281
):
282282
tool = toolbox_tool.bind_params(bound_param_map)
283-
result = await tool.acall({"param2": 123})
283+
result = await tool.acall(param2=123)
284284
assert result == "test-result"
285285
core_tool = tool._AsyncToolboxTool__core_tool
286286
core_tool._ToolboxTool__session.post.assert_called_once_with(
@@ -293,7 +293,7 @@ async def test_toolbox_tool_call_with_auth_tokens(self, auth_toolbox_tool):
293293
tool = auth_toolbox_tool.add_auth_token_getters(
294294
{"test-auth-source": lambda: "test-token"}
295295
)
296-
result = await tool.acall({"param2": 123})
296+
result = await tool.acall(param2=123)
297297
assert result == "test-result"
298298
core_tool = tool._AsyncToolboxTool__core_tool
299299
core_tool._ToolboxTool__session.post.assert_called_once_with(
@@ -324,7 +324,7 @@ async def test_toolbox_tool_call_with_auth_tokens_insecure(
324324
tool_with_getter = insecure_auth_langchain_tool.add_auth_token_getters(
325325
{"test-auth-source": lambda: "test-token"}
326326
)
327-
result = await tool_with_getter.acall({"param2": 123})
327+
result = await tool_with_getter.acall(param2=123)
328328
assert result == "test-result"
329329

330330
modified_core_tool_in_new_tool = tool_with_getter._AsyncToolboxTool__core_tool
@@ -342,20 +342,18 @@ async def test_toolbox_tool_call_with_auth_tokens_insecure(
342342
headers={"test-auth-source_token": "test-token"},
343343
)
344344

345+
async def test_toolbox_tool_call_with_empty_input(self, toolbox_tool):
346+
with pytest.raises(TypeError) as e:
347+
await toolbox_tool.acall()
348+
assert "missing a required argument: 'param1'" in str(e.value)
349+
345350
async def test_toolbox_tool_call_with_invalid_input(self, toolbox_tool):
346351
with pytest.raises(ValidationError) as e:
347-
await toolbox_tool.acall({"param1": 123, "param2": "invalid"})
352+
await toolbox_tool.acall(param1=123, param2="invalid")
348353
assert "2 validation errors for test_tool" in str(e.value)
349354
assert "param1\n Input should be a valid string" in str(e.value)
350355
assert "param2\n Input should be a valid integer" in str(e.value)
351356

352-
async def test_toolbox_tool_call_with_empty_input(self, toolbox_tool):
353-
with pytest.raises(ValidationError) as e:
354-
await toolbox_tool.acall({})
355-
assert "2 validation errors for test_tool" in str(e.value)
356-
assert "param1\n Field required" in str(e.value)
357-
assert "param2\n Field required" in str(e.value)
358-
359357
async def test_toolbox_tool_run_not_implemented(self, toolbox_tool):
360358
with pytest.raises(NotImplementedError):
361-
toolbox_tool._run()
359+
toolbox_tool.call()

packages/toolbox-llamaindex/tests/test_client.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,16 @@ def test_load_tool(self, mock_core_load_tool, toolbox_client):
115115
llamaindex_tool = toolbox_client.load_tool("test_tool")
116116

117117
assert isinstance(llamaindex_tool, ToolboxTool)
118-
assert llamaindex_tool.name == mock_core_tool_instance.__name__
119-
assert llamaindex_tool.description == mock_core_tool_instance.__doc__
118+
assert llamaindex_tool.metadata.name == mock_core_tool_instance.__name__
119+
assert llamaindex_tool.metadata.description == mock_core_tool_instance.__doc__
120120

121121
# Generate the expected schema once for comparison
122122
expected_args_schema = params_to_pydantic_model(
123123
mock_core_tool_instance._name, mock_core_tool_instance._params
124124
)
125125

126126
assert_pydantic_models_equivalent(
127-
llamaindex_tool.args_schema,
127+
llamaindex_tool.metadata.fn_schema,
128128
expected_args_schema,
129129
mock_core_tool_instance._name,
130130
)
@@ -154,14 +154,14 @@ def test_load_toolset(self, mock_core_load_toolset, toolbox_client):
154154
for i, tool_instance_mock in enumerate(tool_instances_mocks):
155155
llamaindex_tool = llamaindex_tools[i]
156156
assert isinstance(llamaindex_tool, ToolboxTool)
157-
assert llamaindex_tool.name == tool_instance_mock.__name__
158-
assert llamaindex_tool.description == tool_instance_mock.__doc__
157+
assert llamaindex_tool.metadata.name == tool_instance_mock.__name__
158+
assert llamaindex_tool.metadata.description == tool_instance_mock.__doc__
159159

160160
expected_args_schema = params_to_pydantic_model(
161161
tool_instance_mock._name, tool_instance_mock._params
162162
)
163163
assert_pydantic_models_equivalent(
164-
llamaindex_tool.args_schema,
164+
llamaindex_tool.metadata.fn_schema,
165165
expected_args_schema,
166166
tool_instance_mock._name,
167167
)
@@ -183,14 +183,16 @@ async def test_aload_tool(self, mock_sync_core_load_tool, toolbox_client):
183183
llamaindex_tool = await toolbox_client.aload_tool("test_tool")
184184

185185
assert isinstance(llamaindex_tool, ToolboxTool)
186-
assert llamaindex_tool.name == mock_core_sync_tool_instance.__name__
187-
assert llamaindex_tool.description == mock_core_sync_tool_instance.__doc__
186+
assert llamaindex_tool.metadata.name == mock_core_sync_tool_instance.__name__
187+
assert (
188+
llamaindex_tool.metadata.description == mock_core_sync_tool_instance.__doc__
189+
)
188190

189191
expected_args_schema = params_to_pydantic_model(
190192
mock_core_sync_tool_instance._name, mock_core_sync_tool_instance._params
191193
)
192194
assert_pydantic_models_equivalent(
193-
llamaindex_tool.args_schema,
195+
llamaindex_tool.metadata.fn_schema,
194196
expected_args_schema,
195197
mock_core_sync_tool_instance._name,
196198
)
@@ -224,13 +226,13 @@ async def test_aload_toolset(self, mock_sync_core_load_toolset, toolbox_client):
224226
for i, tool_instance_mock in enumerate(tool_instances_mocks):
225227
llamaindex_tool = llamaindex_tools[i]
226228
assert isinstance(llamaindex_tool, ToolboxTool)
227-
assert llamaindex_tool.name == tool_instance_mock.__name__
229+
assert llamaindex_tool.metadata.name == tool_instance_mock.__name__
228230

229231
expected_args_schema = params_to_pydantic_model(
230232
tool_instance_mock._name, tool_instance_mock._params
231233
)
232234
assert_pydantic_models_equivalent(
233-
llamaindex_tool.args_schema,
235+
llamaindex_tool.metadata.fn_schema,
234236
expected_args_schema,
235237
tool_instance_mock._name,
236238
)

packages/toolbox-llamaindex/tests/test_tools.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,15 @@ def auth_toolbox_tool(self, mock_core_sync_auth_tool):
180180
def test_toolbox_tool_init(self, mock_core_tool):
181181
tool = ToolboxTool(core_tool=mock_core_tool)
182182

183-
assert tool.name == mock_core_tool.__name__
184-
assert tool.description == mock_core_tool.__doc__
183+
assert tool.metadata.name == mock_core_tool.__name__
184+
assert tool.metadata.description == mock_core_tool.__doc__
185185
assert tool._ToolboxTool__core_tool == mock_core_tool
186186

187187
expected_args_schema = params_to_pydantic_model(
188188
mock_core_tool._name, mock_core_tool._params
189189
)
190190
assert_pydantic_models_equivalent(
191-
tool.args_schema, expected_args_schema, mock_core_tool._name
191+
tool.metadata.fn_schema, expected_args_schema, mock_core_tool._name
192192
)
193193

194194
@pytest.mark.parametrize(
@@ -274,7 +274,7 @@ def test_toolbox_tool_run(self, toolbox_tool, mock_core_tool):
274274
expected_result = "sync_run_output"
275275
mock_core_tool.return_value = expected_result
276276

277-
result = toolbox_tool._run(**kwargs_to_run)
277+
result = toolbox_tool.call(**kwargs_to_run)
278278

279279
assert result == expected_result
280280
assert mock_core_tool.call_count == 1
@@ -295,7 +295,7 @@ async def to_thread_side_effect(func, *args, **kwargs_for_func):
295295

296296
mock_to_thread_in_tools.side_effect = to_thread_side_effect
297297

298-
result = await toolbox_tool._arun(**kwargs_to_run)
298+
result = await toolbox_tool.acall(**kwargs_to_run)
299299

300300
assert result == expected_result
301301
mock_to_thread_in_tools.assert_awaited_once_with(

0 commit comments

Comments
 (0)