From dcf981fef650157188c713935005e303b6a5417b Mon Sep 17 00:00:00 2001 From: sohamganatra Date: Mon, 25 Mar 2024 16:02:07 +0530 Subject: [PATCH] fixed handle_tool_calls and changed to 0.1.43 --- autogen/pyproject.toml | 2 +- autogen/setup.py | 2 +- core/composio/sdk/enums.py | 28 ++++++++++--- core/composio/sdk/sdk.py | 39 ++++++++----------- core/setup.py | 2 +- crew_ai/pyproject.toml | 2 +- crew_ai/requirements.txt | 2 +- crew_ai/setup.py | 2 +- .../composio_tool_spec.ipynb | 10 ++--- langchain/pyproject.toml | 2 +- langchain/requirements.txt | 2 +- langchain/setup.py | 2 +- 12 files changed, 53 insertions(+), 42 deletions(-) diff --git a/autogen/pyproject.toml b/autogen/pyproject.toml index d613f3dae7..2cc26575b7 100644 --- a/autogen/pyproject.toml +++ b/autogen/pyproject.toml @@ -1,7 +1,7 @@ [project] dynamic = ["classifiers", "version", "readme", "authors", "requires-python", "description"] dependencies = [ - "composio_core===0.1.42", + "composio_core===0.1.43", "pyautogen===0.2.19" ] name = "composio_autogen" diff --git a/autogen/setup.py b/autogen/setup.py index a2a0c99b68..da3f708e9a 100644 --- a/autogen/setup.py +++ b/autogen/setup.py @@ -14,7 +14,7 @@ def resolve_paths(*paths): setup( name="composio_autogen", - version="0.1.42", + version="0.1.43", author="Sawradip", author_email="sawradip@composio.dev", description="Use Composio to get an array of tools with your Autogen agent.", diff --git a/core/composio/sdk/enums.py b/core/composio/sdk/enums.py index a712ee2091..fc6177e9a9 100644 --- a/core/composio/sdk/enums.py +++ b/core/composio/sdk/enums.py @@ -1,5 +1,6 @@ from enum import Enum + class App(Enum): CLICKUP = "clickup" GOOGLE_DRIVE = "google-drive" @@ -22,6 +23,7 @@ class App(Enum): DROPBOX = "dropbox" EVENTBRITE = "eventbrite" + class TestIntegration(Enum): CLICKUP = "test-clickup-connector" GOOGLE_DRIVE = "test-google-drive-connector" @@ -44,17 +46,33 @@ class TestIntegration(Enum): DROPBOX = "test-dropbox-connector" EVENTBRITE = "test-eventbrite-connector" + class Action(Enum): def __init__(self, service, action): self.service = service self.action = action - ZENDESK_CREATE_ZENDESK_ORGANIZATION = ("zendesk", "zendesk_create_zendesk_organization") - ZENDESK_DELETE_ZENDESK_ORGANIZATION = ("zendesk", "zendesk_delete_zendesk_organization") - ZENDESK_COUNT_ZENDESK_ORGANIZATIONS = ("zendesk", "zendesk_count_zendesk_organizations") + ZENDESK_CREATE_ZENDESK_ORGANIZATION = ( + "zendesk", + "zendesk_create_zendesk_organization", + ) + ZENDESK_DELETE_ZENDESK_ORGANIZATION = ( + "zendesk", + "zendesk_delete_zendesk_organization", + ) + ZENDESK_COUNT_ZENDESK_ORGANIZATIONS = ( + "zendesk", + "zendesk_count_zendesk_organizations", + ) ZENDESK_GET_ZENDESK_ORGANIZATION = ("zendesk", "zendesk_get_zendesk_organization") - ZENDESK_GET_ZENDESK_ORGANIZATIONS = ("zendesk", "zendesk_get_all_zendesk_organizations") - ZENDESK_UPDATE_ZENDESK_ORGANIZATION = ("zendesk", "zendesk_update_zendesk_organization") + ZENDESK_GET_ZENDESK_ORGANIZATIONS = ( + "zendesk", + "zendesk_get_all_zendesk_organizations", + ) + ZENDESK_UPDATE_ZENDESK_ORGANIZATION = ( + "zendesk", + "zendesk_update_zendesk_organization", + ) ZENDESK_CREATE_ZENDESK_TICKET = ("zendesk", "zendesk_create_zendesk_ticket") ZENDESK_DELETE_ZENDESK_TICKET = ("zendesk", "zendesk_delete_zendesk_ticket") ZENDESK_GET_ZENDESK_ABOUT_ME = ("zendesk", "zendesk_get_about_me") diff --git a/core/composio/sdk/sdk.py b/core/composio/sdk/sdk.py index 857548bab8..fc667d9e53 100644 --- a/core/composio/sdk/sdk.py +++ b/core/composio/sdk/sdk.py @@ -268,8 +268,11 @@ def get_action_enum(self, action_name: str, tool_name: str) -> Action: f"No matching action found for action: {action_name.lower()} and tool: {tool_name.lower()}" ) - # handles multiple tool calls - connected_accounts = self.get_connected_accounts(entity_id=entity_id) + def get_action_enum_without_tool(self, action_name: str) -> Action: + for action in Action: + if action.action == action_name.lower(): + return action + raise ValueError(f"No matching action found for action: {action_name.lower()}") def get_entity(self, entity_id: Union[list[str], str]): entity = Entity(self, entity_id) @@ -293,39 +296,29 @@ def get_all_actions(self) -> list[Action]: actions.extend(account_actions) return actions - def get_all_action_connections(self) -> list[Tuple[Action, ConnectedAccount]]: - action_connections = [] + def get_connection(self, tool_name: str) -> ConnectedAccount: connected_accounts = self.client.get_connected_accounts( entity_id=self.entity_id ) for account in connected_accounts: - account_actions = account.get_all_actions() - for action in account_actions: - action_connections.append(action, account) - return action_connections + if tool_name == account.appUniqueId: + return account def handle_tools_calls(self, tool_calls: ChatCompletion) -> list[any]: output = [] - action_connections = self.get_all_action_connections() try: if tool_calls.choices: for choice in tool_calls.choices: if choice.message.tool_calls: for tool_call in choice.message.tool_calls: - tool_is_executed = false - function = tool_call.function - # find action_connection with function.name - for action_connection in action_connections: - if tool_is_executed: - break - action = action_connection[0] - connection = action_connection[1] - if action.action == function.name: - arguments = json.loads(function.arguments) - output.append( - connection.execute_action(action, arguments) - ) - tool_is_executed = True + action_name_to_execute = tool_call.function.name + action = self.client.get_action_enum_without_tool( + action_name=action_name_to_execute + ) + arguments = json.loads(tool_call.function.arguments) + account = self.get_connection(tool_name=action.service) + output.append(account.execute_action(action, arguments)) + except Exception as e: print(e) return output diff --git a/core/setup.py b/core/setup.py index 508fc96cb9..3e8749ba1d 100644 --- a/core/setup.py +++ b/core/setup.py @@ -25,7 +25,7 @@ def run(self): setup( name="composio_core", - version="0.1.42", + version="0.1.43", author="Utkarsh", author_email="utkarsh@composio.dev", description="Core package to act as a bridge between composio platform and other services.", diff --git a/crew_ai/pyproject.toml b/crew_ai/pyproject.toml index 880f9838f6..b1dde80ff3 100644 --- a/crew_ai/pyproject.toml +++ b/crew_ai/pyproject.toml @@ -1,7 +1,7 @@ [project] dynamic = ["classifiers", "version", "readme", "authors", "requires-python", "description"] dependencies = [ - "composio_langchain===0.1.42", + "composio_langchain===0.1.43", ] name = "composio_crewai" diff --git a/crew_ai/requirements.txt b/crew_ai/requirements.txt index 83a93fa064..ca952f2cf0 100644 --- a/crew_ai/requirements.txt +++ b/crew_ai/requirements.txt @@ -1 +1 @@ -composio_langchain===0.1.42 \ No newline at end of file +composio_langchain===0.1.43 \ No newline at end of file diff --git a/crew_ai/setup.py b/crew_ai/setup.py index de23df8e3d..f0ba3a677e 100644 --- a/crew_ai/setup.py +++ b/crew_ai/setup.py @@ -14,7 +14,7 @@ def resolve_paths(*paths): setup( name="composio_crewai", - version="0.1.42", + version="0.1.43", author="Himanshu", author_email="himanshu@composio.dev", description="Use Composio to get an array of tools with your CrewAI agent.", diff --git a/langchain/composio_langchain/composio_tool_spec.ipynb b/langchain/composio_langchain/composio_tool_spec.ipynb index 3ae610c065..52970bc10e 100644 --- a/langchain/composio_langchain/composio_tool_spec.ipynb +++ b/langchain/composio_langchain/composio_tool_spec.ipynb @@ -10,7 +10,7 @@ "output_type": "stream", "text": [ "Requirement already satisfied: langchain-openai in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (0.0.8)\n", - "Requirement already satisfied: langchain-core<0.2.0,>=0.1.27 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from langchain-openai) (0.1.42)\n", + "Requirement already satisfied: langchain-core<0.2.0,>=0.1.27 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from langchain-openai) (0.1.43)\n", "Requirement already satisfied: openai<2.0.0,>=1.10.0 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from langchain-openai) (1.12.0)\n", "Requirement already satisfied: tiktoken<1,>=0.5.2 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from langchain-openai) (0.6.0)\n", "Requirement already satisfied: PyYAML>=5.3 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.27->langchain-openai) (6.0.1)\n", @@ -63,7 +63,7 @@ "Requirement already satisfied: jsonpatch<2.0,>=1.33 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from langchain) (1.33)\n", "Collecting langchain-community<0.1,>=0.0.28 (from langchain)\n", " Using cached langchain_community-0.0.28-py3-none-any.whl.metadata (8.3 kB)\n", - "Requirement already satisfied: langchain-core<0.2.0,>=0.1.42 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from langchain) (0.1.42)\n", + "Requirement already satisfied: langchain-core<0.2.0,>=0.1.43 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from langchain) (0.1.43)\n", "Collecting langchain-text-splitters<0.1,>=0.0.1 (from langchain)\n", " Using cached langchain_text_splitters-0.0.1-py3-none-any.whl.metadata (2.0 kB)\n", "Requirement already satisfied: langsmith<0.2.0,>=0.1.17 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from langchain) (0.1.27)\n", @@ -79,8 +79,8 @@ "Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from dataclasses-json<0.7,>=0.5.7->langchain) (3.20.2)\n", "Requirement already satisfied: typing-inspect<1,>=0.4.0 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from dataclasses-json<0.7,>=0.5.7->langchain) (0.9.0)\n", "Requirement already satisfied: jsonpointer>=1.9 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from jsonpatch<2.0,>=1.33->langchain) (2.4)\n", - "Requirement already satisfied: anyio<5,>=3 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.42->langchain) (4.3.0)\n", - "Requirement already satisfied: packaging<24.0,>=23.2 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.42->langchain) (23.2)\n", + "Requirement already satisfied: anyio<5,>=3 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.43->langchain) (4.3.0)\n", + "Requirement already satisfied: packaging<24.0,>=23.2 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from langchain-core<0.2.0,>=0.1.43->langchain) (23.2)\n", "Requirement already satisfied: orjson<4.0.0,>=3.9.14 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from langsmith<0.2.0,>=0.1.17->langchain) (3.9.14)\n", "Requirement already satisfied: annotated-types>=0.4.0 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from pydantic<3,>=1->langchain) (0.6.0)\n", "Requirement already satisfied: pydantic-core==2.16.2 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from pydantic<3,>=1->langchain) (2.16.2)\n", @@ -89,7 +89,7 @@ "Requirement already satisfied: idna<4,>=2.5 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from requests<3,>=2->langchain) (3.6)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from requests<3,>=2->langchain) (2.2.1)\n", "Requirement already satisfied: certifi>=2017.4.17 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from requests<3,>=2->langchain) (2024.2.2)\n", - "Requirement already satisfied: sniffio>=1.1 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from anyio<5,>=3->langchain-core<0.2.0,>=0.1.42->langchain) (1.3.0)\n", + "Requirement already satisfied: sniffio>=1.1 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from anyio<5,>=3->langchain-core<0.2.0,>=0.1.43->langchain) (1.3.0)\n", "Requirement already satisfied: mypy-extensions>=0.3.0 in /Users/karanvaidya/codes/composio_sdk/venv/lib/python3.11/site-packages (from typing-inspect<1,>=0.4.0->dataclasses-json<0.7,>=0.5.7->langchain) (1.0.0)\n", "Using cached langchain-0.1.12-py3-none-any.whl (809 kB)\n", "Using cached langchain_community-0.0.28-py3-none-any.whl (1.8 MB)\n", diff --git a/langchain/pyproject.toml b/langchain/pyproject.toml index f8d7e5807a..926618475d 100644 --- a/langchain/pyproject.toml +++ b/langchain/pyproject.toml @@ -9,7 +9,7 @@ dependencies = [ "langchain-openai===0.0.2.post1", "langchainhub==0.1.15", "pydantic===2.6.4", - "composio_core===0.1.42" + "composio_core===0.1.43" ] name = "composio_langchain" diff --git a/langchain/requirements.txt b/langchain/requirements.txt index 3a02c28f2f..d79867d36f 100644 --- a/langchain/requirements.txt +++ b/langchain/requirements.txt @@ -2,4 +2,4 @@ langchain===0.1.0 langchain-openai===0.0.2.post1 pydantic===2.6.4 langchainhub==0.1.15 -composio_core===0.1.42 \ No newline at end of file +composio_core===0.1.43 \ No newline at end of file diff --git a/langchain/setup.py b/langchain/setup.py index 16679396ee..2f6b1ae167 100644 --- a/langchain/setup.py +++ b/langchain/setup.py @@ -14,7 +14,7 @@ def resolve_paths(*paths): setup( name="composio_langchain", - version="0.1.42", + version="0.1.43", author="Karan", author_email="karan@composio.dev", description="Use Composio to get an array of tools with your LangChain agent.",