Skip to content

feat(toolbox-core)!: Align toolbox core's bind params API with orchestration packages #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: anubhav-strict
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/toolbox-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ specific tool instance.
toolbox = ToolboxClient("http://127.0.0.1:5000")
tool = await toolbox.load_tool("my-tool")

bound_tool = tool.bind_parameters({"param": "value"})
bound_tool = tool.bind_params({"param": "value"})
```

### Option B: Binding Parameters While Loading Tools
Expand Down
4 changes: 2 additions & 2 deletions packages/toolbox-core/src/toolbox_core/sync_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def add_auth_token_getters(
new_async_tool = self.__async_tool.add_auth_token_getters(auth_token_getters)
return ToolboxSyncTool(new_async_tool, self.__loop, self.__thread)

def bind_parameters(
def bind_params(
self, bound_params: Mapping[str, Union[Callable[[], Any], Any]]
) -> "ToolboxSyncTool":
"""
Expand All @@ -138,5 +138,5 @@ def bind_parameters(
A new ToolboxSyncTool instance with the specified parameters bound.
"""

new_async_tool = self.__async_tool.bind_parameters(bound_params)
new_async_tool = self.__async_tool.bind_params(bound_params)
return ToolboxSyncTool(new_async_tool, self.__loop, self.__thread)
2 changes: 1 addition & 1 deletion packages/toolbox-core/src/toolbox_core/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def add_auth_token_getters(
required_authn_params=new_req_authn_params,
)

def bind_parameters(
def bind_params(
self, bound_params: Mapping[str, Union[Callable[[], Any], Any]]
) -> "ToolboxTool":
"""
Expand Down
26 changes: 13 additions & 13 deletions packages/toolbox-core/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ async def test_bind_param_success(self, tool_name, client):
assert len(tool.__signature__.parameters) == 2
assert "argA" in tool.__signature__.parameters

tool = tool.bind_parameters({"argA": 5})
tool = tool.bind_params({"argA": 5})

assert len(tool.__signature__.parameters) == 1
assert "argA" not in tool.__signature__.parameters
Expand All @@ -458,7 +458,7 @@ async def test_bind_callable_param_success(self, tool_name, client):
assert len(tool.__signature__.parameters) == 2
assert "argA" in tool.__signature__.parameters

tool = tool.bind_parameters({"argA": lambda: 5})
tool = tool.bind_params({"argA": lambda: 5})

assert len(tool.__signature__.parameters) == 1
assert "argA" not in tool.__signature__.parameters
Expand All @@ -468,34 +468,34 @@ async def test_bind_callable_param_success(self, tool_name, client):

@pytest.mark.asyncio
async def test_bind_param_fail(self, tool_name, client):
"""Tests 'bind_parameters' with a bound parameter that doesn't exist."""
"""Tests 'bind_params' with a bound parameter that doesn't exist."""
tool = await client.load_tool(tool_name)

assert len(tool.__signature__.parameters) == 2
assert "argA" in tool.__signature__.parameters

with pytest.raises(Exception) as e:
tool.bind_parameters({"argC": lambda: 5})
tool.bind_params({"argC": lambda: 5})
assert "unable to bind parameters: no parameter named argC" in str(e.value)

@pytest.mark.asyncio
async def test_rebind_param_fail(self, tool_name, client):
"""
Tests that 'bind_parameters' fails when attempting to re-bind a
Tests that 'bind_params' fails when attempting to re-bind a
parameter that has already been bound.
"""
tool = await client.load_tool(tool_name)

assert len(tool.__signature__.parameters) == 2
assert "argA" in tool.__signature__.parameters

tool_with_bound_param = tool.bind_parameters({"argA": lambda: 10})
tool_with_bound_param = tool.bind_params({"argA": lambda: 10})

assert len(tool_with_bound_param.__signature__.parameters) == 1
assert "argA" not in tool_with_bound_param.__signature__.parameters

with pytest.raises(ValueError) as e:
tool_with_bound_param.bind_parameters({"argA": lambda: 20})
tool_with_bound_param.bind_params({"argA": lambda: 20})

assert "cannot re-bind parameter: parameter 'argA' is already bound" in str(
e.value
Expand All @@ -504,13 +504,13 @@ async def test_rebind_param_fail(self, tool_name, client):
@pytest.mark.asyncio
async def test_bind_param_static_value_success(self, tool_name, client):
"""
Tests bind_parameters method with a static value.
Tests bind_params method with a static value.
"""

bound_value = "Test value"

tool = await client.load_tool(tool_name)
bound_tool = tool.bind_parameters({"argB": bound_value})
bound_tool = tool.bind_params({"argB": bound_value})

assert bound_tool is not tool
assert "argB" not in bound_tool.__signature__.parameters
Expand All @@ -524,14 +524,14 @@ async def test_bind_param_static_value_success(self, tool_name, client):
@pytest.mark.asyncio
async def test_bind_param_sync_callable_value_success(self, tool_name, client):
"""
Tests bind_parameters method with a sync callable value.
Tests bind_params method with a sync callable value.
"""

bound_value_result = True
bound_sync_callable = Mock(return_value=bound_value_result)

tool = await client.load_tool(tool_name)
bound_tool = tool.bind_parameters({"argB": bound_sync_callable})
bound_tool = tool.bind_params({"argB": bound_sync_callable})

assert bound_tool is not tool
assert "argB" not in bound_tool.__signature__.parameters
Expand All @@ -546,14 +546,14 @@ async def test_bind_param_sync_callable_value_success(self, tool_name, client):
@pytest.mark.asyncio
async def test_bind_param_async_callable_value_success(self, tool_name, client):
"""
Tests bind_parameters method with an async callable value.
Tests bind_params method with an async callable value.
"""

bound_value_result = True
bound_async_callable = AsyncMock(return_value=bound_value_result)

tool = await client.load_tool(tool_name)
bound_tool = tool.bind_parameters({"argB": bound_async_callable})
bound_tool = tool.bind_params({"argB": bound_async_callable})

assert bound_tool is not tool
assert "argB" not in bound_tool.__signature__.parameters
Expand Down
4 changes: 2 additions & 2 deletions packages/toolbox-core/tests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async def test_bind_params(
self, toolbox: ToolboxClient, get_n_rows_tool: ToolboxTool
):
"""Bind a param to an existing tool."""
new_tool = get_n_rows_tool.bind_parameters({"num_rows": "3"})
new_tool = get_n_rows_tool.bind_params({"num_rows": "3"})
response = await new_tool()
assert isinstance(response, str)
assert "row1" in response
Expand All @@ -117,7 +117,7 @@ async def test_bind_params_callable(
self, toolbox: ToolboxClient, get_n_rows_tool: ToolboxTool
):
"""Bind a callable param to an existing tool."""
new_tool = get_n_rows_tool.bind_parameters({"num_rows": lambda: "3"})
new_tool = get_n_rows_tool.bind_params({"num_rows": lambda: "3"})
response = await new_tool()
assert isinstance(response, str)
assert "row1" in response
Expand Down
4 changes: 2 additions & 2 deletions packages/toolbox-core/tests/test_sync_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_bind_params(
self, toolbox: ToolboxSyncClient, get_n_rows_tool: ToolboxSyncTool
):
"""Bind a param to an existing tool."""
new_tool = get_n_rows_tool.bind_parameters({"num_rows": "3"})
new_tool = get_n_rows_tool.bind_params({"num_rows": "3"})
response = new_tool()
assert isinstance(response, str)
assert "row1" in response
Expand All @@ -100,7 +100,7 @@ def test_bind_params_callable(
self, toolbox: ToolboxSyncClient, get_n_rows_tool: ToolboxSyncTool
):
"""Bind a callable param to an existing tool."""
new_tool = get_n_rows_tool.bind_parameters({"num_rows": lambda: "3"})
new_tool = get_n_rows_tool.bind_params({"num_rows": lambda: "3"})
response = new_tool()
assert isinstance(response, str)
assert "row1" in response
Expand Down