Skip to content
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

Fix description duplication #773

Merged
merged 2 commits into from
Oct 25, 2024
Merged
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
15 changes: 5 additions & 10 deletions python/composio/tools/toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ def get_action_schemas(
for act in runtime_actions:
schema = act.schema()
schema["name"] = act.enum
items.append(ActionModel(**schema))
items.append(ActionModel(**schema).model_copy(deep=True))

for item in items:
item = self._process_schema(item)
Expand Down Expand Up @@ -873,16 +873,11 @@ def _process_schema(self, action_item: ActionModel) -> ActionModel:
"number",
"boolean",
]:
param_type = param_details["type"]
ext = f'Please provide a value of type {param_details["type"]}.'
description = param_details.get("description", "").rstrip(".")
if description:
param_details["description"] = (
f"{description}. Please provide a value of type {param_type}."
)
else:
param_details["description"] = (
f"Please provide a value of type {param_type}."
)
param_details["description"] = (
f"{description}. {ext}" if description else ext
)

if param_name in required_params:
description = param_details.get("description", "")
Expand Down
26 changes: 26 additions & 0 deletions python/tests/test_tools/test_toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from composio import Action, App
from composio.exceptions import ApiKeyNotProvidedError, ComposioSDKError
from composio.tools.base.abs import action_registry, tool_registry
from composio.tools.base.runtime import action as custom_action
from composio.tools.toolset import ComposioToolSet

from composio_langchain.toolset import ComposioToolSet as LangchainToolSet
Expand Down Expand Up @@ -265,3 +266,28 @@ def test_check_connected_accounts_flag() -> None:
check_connected_accounts=False,
)
mocked.assert_not_called()


def test_get_action_schemas_description_for_runtime_tool() -> None:

@custom_action(toolname="runtime")
def some_action(name: str) -> str:
"""
Some action

:param name: Name of the user
:return message: Message for user
"""
return f"Hello, {name}"

(schema_0,) = ComposioToolSet().get_action_schemas(actions=[some_action])
assert (
schema_0.parameters.properties["name"]["description"]
== "Name of the user. Please provide a value of type string. This parameter is required."
)

(schema_1,) = ComposioToolSet().get_action_schemas(actions=[some_action])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second assertion in this test is redundant as it checks the same condition without any change in state or input. Consider removing it.

Suggested change
(schema_1,) = ComposioToolSet().get_action_schemas(actions=[some_action])

assert (
schema_1.parameters.properties["name"]["description"]
== "Name of the user. Please provide a value of type string. This parameter is required."
)
Loading