From b40c331592fcb2414e6dadf6c03490cfe9386cfe Mon Sep 17 00:00:00 2001 From: Twisha Bansal Date: Tue, 11 Mar 2025 11:29:34 +0530 Subject: [PATCH 1/4] chore: remove temp fix for optional params support --- src/toolbox_llamaindex/utils.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/toolbox_llamaindex/utils.py b/src/toolbox_llamaindex/utils.py index 16830ac..4c22620 100644 --- a/src/toolbox_llamaindex/utils.py +++ b/src/toolbox_llamaindex/utils.py @@ -97,9 +97,7 @@ def _schema_to_model(model_name: str, schema: list[ParameterSchema]) -> Type[Bas field_definitions[field.name] = cast( Any, ( - # TODO: Remove the hardcoded optional types once optional fields - # are supported by Toolbox. - Optional[_parse_type(field)], + _parse_type(field), Field(description=field.description), ), ) From e1ab7f40b6ca35a2688f6d5fa4cfd479333b61c3 Mon Sep 17 00:00:00 2001 From: Twisha Bansal Date: Tue, 11 Mar 2025 11:44:44 +0530 Subject: [PATCH 2/4] fix tests --- tests/test_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 16f3f3d..5a7b8b4 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -154,9 +154,9 @@ def test_schema_to_model(self): model = _schema_to_model("TestModel", schema) assert issubclass(model, BaseModel) - assert model.model_fields["param1"].annotation == Union[str, None] + assert model.model_fields["param1"].annotation == str assert model.model_fields["param1"].description == "Parameter 1" - assert model.model_fields["param2"].annotation == Union[int, None] + assert model.model_fields["param2"].annotation == int assert model.model_fields["param2"].description == "Parameter 2" def test_schema_to_model_empty(self): From 4aae6047c03896d9c4e9354f6fd0666402b85de4 Mon Sep 17 00:00:00 2001 From: Twisha Bansal Date: Wed, 12 Mar 2025 12:44:45 +0530 Subject: [PATCH 3/4] remove optional params workaround --- src/toolbox_llamaindex/utils.py | 26 +------------------------- tests/test_utils.py | 12 +++--------- 2 files changed, 4 insertions(+), 34 deletions(-) diff --git a/src/toolbox_llamaindex/utils.py b/src/toolbox_llamaindex/utils.py index 4c22620..7e53171 100644 --- a/src/toolbox_llamaindex/utils.py +++ b/src/toolbox_llamaindex/utils.py @@ -198,36 +198,12 @@ async def _invoke_tool( async with session.post( url, - json=_convert_none_to_empty_string(data), + json=data, headers=auth_tokens, ) as response: response.raise_for_status() return await response.json() - -def _convert_none_to_empty_string(input_dict): - """ - Temporary fix to convert None values to empty strings in the input data. - This is needed because the current version of the Toolbox service does not - support optional fields. - - TODO: Remove this once optional fields are supported by Toolbox. - - Args: - input_dict: The input data dictionary. - - Returns: - A new dictionary with None values replaced by empty strings. - """ - new_dict = {} - for key, value in input_dict.items(): - if value is None: - new_dict[key] = "" - else: - new_dict[key] = value - return new_dict - - def _find_auth_params( params: list[ParameterSchema], ) -> tuple[list[ParameterSchema], list[ParameterSchema]]: diff --git a/tests/test_utils.py b/tests/test_utils.py index 5a7b8b4..c29a9a7 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -25,7 +25,6 @@ from toolbox_llamaindex.utils import ( ParameterSchema, - _convert_none_to_empty_string, _get_auth_headers, _invoke_tool, _load_manifest, @@ -225,7 +224,7 @@ async def test_invoke_tool(self, mock_post): mock_post.assert_called_once_with( "http://localhost:8000/api/tool/tool_name/invoke", - json=_convert_none_to_empty_string({"input": "data"}), + json={"input": "data"}, headers={}, ) assert result == {"key": "value"} @@ -252,7 +251,7 @@ async def test_invoke_tool_unsecure_with_auth(self, mock_post): mock_post.assert_called_once_with( "http://localhost:8000/api/tool/tool_name/invoke", - json=_convert_none_to_empty_string({"input": "data"}), + json={"input": "data"}, headers={"my_test_auth_token": "fake_id_token"}, ) assert result == {"key": "value"} @@ -278,16 +277,11 @@ async def test_invoke_tool_secure_with_auth(self, mock_post): mock_post.assert_called_once_with( "https://localhost:8000/api/tool/tool_name/invoke", - json=_convert_none_to_empty_string({"input": "data"}), + json={"input": "data"}, headers={"my_test_auth_token": "fake_id_token"}, ) assert result == {"key": "value"} - def test_convert_none_to_empty_string(self): - input_dict = {"a": None, "b": 123} - expected_output = {"a": "", "b": 123} - assert _convert_none_to_empty_string(input_dict) == expected_output - def test_get_auth_headers_deprecation_warning(self): """Test _get_auth_headers deprecation warning.""" with pytest.warns( From 4d4da841145416bbffa1f530a63ecde9e369ec8e Mon Sep 17 00:00:00 2001 From: Twisha Bansal Date: Wed, 12 Mar 2025 12:48:04 +0530 Subject: [PATCH 4/4] lint --- src/toolbox_llamaindex/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/toolbox_llamaindex/utils.py b/src/toolbox_llamaindex/utils.py index 7e53171..d3c4eb7 100644 --- a/src/toolbox_llamaindex/utils.py +++ b/src/toolbox_llamaindex/utils.py @@ -204,6 +204,7 @@ async def _invoke_tool( response.raise_for_status() return await response.json() + def _find_auth_params( params: list[ParameterSchema], ) -> tuple[list[ParameterSchema], list[ParameterSchema]]: