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

feat: add no auth entity support #41

Merged
merged 3 commits into from
May 14, 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
4 changes: 2 additions & 2 deletions composio/sdk/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ def execute_action(
tool_name = action.value[0]
no_auth = action.value[2] if len(action.value) > 2 else False
if no_auth:
resp = self.sdk.no_auth_execute_action(action, params)
utkarsh-dixit marked this conversation as resolved.
Show resolved Hide resolved
return resp
resp = self.sdk.get_entity(entity_id)
return resp.execute_action(action, params, entity_id=entity_id)
entity = self.sdk.get_entity(entity_id)
account = entity.get_connection(tool_name, connection_id=connection_id)
if not account:
Expand Down
24 changes: 16 additions & 8 deletions composio/sdk/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class ConnectedAccount(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)
integrationId: str
connectionParams: AuthConnectionParams
clientUniqueUserId: str
appUniqueId: str
id: str
status: str
Expand All @@ -142,7 +143,7 @@ def _execute_action(
):
resp = self.sdk_instance.http_client.post(
f"v1/actions/{action_name.value[1]}/execute",
json={"connectedAccountId": connected_account_id, "input": params},
json={"connectedAccountId": connected_account_id, "input": params, "entityId": self.clientUniqueUserId},
)
return resp.json()

Expand Down Expand Up @@ -461,20 +462,27 @@ def get_entity(self, entity_id: Union[list[str], str]):
entity = Entity(self, entity_id)
return entity

def no_auth_execute_action(self, action: Action, params: dict):
tool_name = action.value[0]
resp = self.http_client.post(
f"v1/actions/{action.value[1]}/execute",
json={"appName": tool_name, "input": params},
)
return resp.json()


class Entity:
def __init__(self, composio: Composio, entity_id: Union[list[str], str]) -> None:
self.client = composio
entity_id = entity_id if isinstance(entity_id, str) else ",".join(entity_id)
self.entity_id = entity_id
self.http_client = self.client.http_client

def execute_action(self, action: Action, params: dict, connected_account_id: Optional[str] = None, entity_id = "default"):
no_auth = action.value[2] if len(action.value) > 2 else False
if no_auth is True:
tool_name = action.value[0]
resp = self.http_client.post(
f"v1/actions/{action.value[1]}/execute",
json={"appName": tool_name, "input": params, "entityId": entity_id},
)
return resp.json()
else:
connected_account = self.client.get_connected_account(connected_account_id)
return connected_account.execute_action(action, params)

def get_all_actions(self, tags: list[Union[str, Tag]] = None) -> list[Action]:
actions = []
Expand Down
32 changes: 32 additions & 0 deletions examples/composio_crewai_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
import dotenv
from crewai import Agent, Task
from langchain_openai import ChatOpenAI
from plugins.crew_ai.composio_crewai import ComposioToolset, App, Action

# Loading the variables from .env file
dotenv.load_dotenv()

llm = ChatOpenAI(openai_api_key=os.environ["OPENAI_API_KEY"])


# Get All the tools
tools = ComposioToolset(actions=[Action.COMPOSIO_CHECK_ACTIVE_CONNECTION], entity_id="soham")


crewai_agent = Agent(
role='User Connection Checker',
goal="""You check if the user connection is active for an app""",
backstory="""You are AI agent that is responsible for making sure that if the user connection is active for an app""",
verbose=True,
tools=tools,
llm=llm
)

task = Task(
description="Check ifthe user connection is active for github",
agent=crewai_agent,
expected_output="Tell me if the user connection is active for github"
)

task.execute()
2 changes: 1 addition & 1 deletion plugins/autogen/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
python_requires=">=3.9,<4",
install_requires=[
"composio_core===0.2.59",
"pyautogen>=0.2.19",
"pyautogen>=0.2.19"
],
include_package_data=True,
)
2 changes: 1 addition & 1 deletion plugins/crew_ai/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
],
python_requires=">=3.9,<4",
install_requires=[
"composio_langchain===0.2.59",
"composio_langchain===0.2.59"
],
include_package_data=True,
)
2 changes: 1 addition & 1 deletion plugins/langchain/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"langchain-openai>=0.0.2.post1",
"pydantic>=2.6.4",
"langchainhub>=0.1.15",
"composio_core===0.2.59",
"composio_core===0.2.59"
],
include_package_data=True,
)
2 changes: 1 addition & 1 deletion plugins/lyzr/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"lyzr-automata>=0.1.3",
"pydantic>=2.6.4",
"composio_core===0.2.59",
"langchain>=0.1.0",
"langchain>=0.1.0"
],
include_package_data=True,
)
2 changes: 1 addition & 1 deletion plugins/openai/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
],
python_requires=">=3.9,<4",
install_requires=[
"composio_core===0.2.59",
"composio_core===0.2.59"
],
include_package_data=True,
)
1 change: 1 addition & 0 deletions tests/autogen_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def test_add_github():
"composio.sdk.sdk.Composio.get_connected_account",
return_value=ConnectedAccount(
sdk_instance=mock.Mock(),
clientUniqueUserId="default",
status="ACTIVE",
integrationId="integ123",
connectionParams={"scope": "read", "base_url": "https://api.example.com"},
Expand Down
1 change: 1 addition & 0 deletions tests/crewai_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def test_add_github():
"composio.sdk.sdk.Composio.get_connected_account",
return_value=ConnectedAccount(
sdk_instance=mock.Mock(),
clientUniqueUserId="default",
status="ACTIVE",
integrationId="integ123",
connectionParams={"scope": "read", "base_url": "https://api.example.com"},
Expand Down
1 change: 1 addition & 0 deletions tests/langchain_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def test_add_github():
sdk_instance=mock.Mock(),
status="ACTIVE",
integrationId="integ123",
clientUniqueUserId="default",
connectionParams={"scope": "read", "base_url": "https://api.example.com"},
appUniqueId="app456",
id="<random_connected_account_id>",
Expand Down
Loading