-
Notifications
You must be signed in to change notification settings - Fork 23
feat(core): Add support for map parameter type #324
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
anubhav756
wants to merge
12
commits into
main
Choose a base branch
from
anubhav-map
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+194
−11
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
885e824
feat(core): Add support for map parameter type
anubhav756 4538bad
chore: Add integration tests
anubhav756 31ce451
chore: Delint
anubhav756 f30c649
chore: Update toolbox version that supports map params for integratio…
anubhav756 0a50892
fix: Fix the param type to 'object' for map params
anubhav756 141d5b2
fix: Update SDK code to read from the correct AdditionalProperties key
anubhav756 4636772
chore: Delint
anubhav756 8636b67
chore: Fix e2e tests
anubhav756 49659ef
fix: Fix e2e tests
anubhav756 ae737a7
Merge branch 'main' into anubhav-map
anubhav756 8068640
fix(langchain): Fix e2e tests
anubhav756 9c8839e
fix(llamaindex): Fix e2e tests
anubhav756 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
# limitations under the License. | ||
|
||
from inspect import Parameter, signature | ||
from typing import Optional | ||
from typing import Any, Optional | ||
|
||
import pytest | ||
import pytest_asyncio | ||
|
@@ -68,7 +68,7 @@ async def test_load_toolset_specific( | |
async def test_load_toolset_default(self, toolbox: ToolboxClient): | ||
"""Load the default toolset, i.e. all tools.""" | ||
toolset = await toolbox.load_toolset() | ||
assert len(toolset) == 6 | ||
assert len(toolset) == 7 | ||
tool_names = {tool.__name__ for tool in toolset} | ||
expected_tools = [ | ||
"get-row-by-content-auth", | ||
|
@@ -77,6 +77,7 @@ async def test_load_toolset_default(self, toolbox: ToolboxClient): | |
"get-row-by-id", | ||
"get-n-rows", | ||
"search-rows", | ||
"process-data", | ||
] | ||
assert tool_names == set(expected_tools) | ||
|
||
|
@@ -379,3 +380,66 @@ async def test_run_tool_with_different_id(self, toolbox: ToolboxClient): | |
response = await tool(email="[email protected]", id=4, data="row3") | ||
assert isinstance(response, str) | ||
assert response == "null" | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.usefixtures("toolbox_server") | ||
class TestMapParams: | ||
""" | ||
End-to-end tests for tools with map parameters. | ||
""" | ||
|
||
async def test_tool_signature_with_map_params(self, toolbox: ToolboxClient): | ||
"""Verify the client correctly constructs the signature for a tool with map params.""" | ||
tool = await toolbox.load_tool("process-data") | ||
sig = signature(tool) | ||
|
||
assert "execution_context" in sig.parameters | ||
assert sig.parameters["execution_context"].annotation == dict[str, Any] | ||
assert sig.parameters["execution_context"].default is Parameter.empty | ||
|
||
assert "user_scores" in sig.parameters | ||
assert sig.parameters["user_scores"].annotation == dict[str, int] | ||
assert sig.parameters["user_scores"].default is Parameter.empty | ||
|
||
assert "feature_flags" in sig.parameters | ||
assert sig.parameters["feature_flags"].annotation == Optional[dict[str, bool]] | ||
assert sig.parameters["feature_flags"].default is None | ||
|
||
async def test_run_tool_with_map_params(self, toolbox: ToolboxClient): | ||
"""Invoke a tool with valid map parameters.""" | ||
tool = await toolbox.load_tool("process-data") | ||
|
||
response = await tool( | ||
execution_context={"env": "prod", "id": 1234, "user": 1234.5}, | ||
user_scores={"user1": 100, "user2": 200}, | ||
feature_flags={"new_feature": True}, | ||
) | ||
assert isinstance(response, str) | ||
assert '"execution_context":{"env":"prod","id":1234,"user":1234.5}' in response | ||
assert '"user_scores":{"user1":100,"user2":200}' in response | ||
assert '"feature_flags":{"new_feature":true}' in response | ||
|
||
async def test_run_tool_with_optional_map_param_omitted( | ||
self, toolbox: ToolboxClient | ||
): | ||
"""Invoke a tool without the optional map parameter.""" | ||
tool = await toolbox.load_tool("process-data") | ||
|
||
response = await tool( | ||
execution_context={"env": "dev"}, user_scores={"user3": 300} | ||
) | ||
assert isinstance(response, str) | ||
assert '"execution_context":{"env":"dev"}' in response | ||
assert '"user_scores":{"user3":300}' in response | ||
assert '"feature_flags":null' in response | ||
|
||
async def test_run_tool_with_wrong_map_value_type(self, toolbox: ToolboxClient): | ||
"""Invoke a tool with a map parameter having the wrong value type.""" | ||
tool = await toolbox.load_tool("process-data") | ||
|
||
with pytest.raises(ValidationError): | ||
await tool( | ||
execution_context={"env": "staging"}, | ||
user_scores={"user4": "not-an-integer"}, | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Should this be a map type parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the manifest the
type
is returned as aobject
.CC: @duwenxin99
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@duwenxin99 are there specific reasons for using different manifest and object types in the server and client?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Unresolving this comment for now)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two reasons:
Open to discussion on this @twishabansal , @anubhav756 we can change it for the server if that's easier on the SDK side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just worried that in the config file, the user defines a
map
. However, during usage with SDK or debugging, the user would see anobject
. Seems like this might be a little confusing for the user. What do you folks think?