From a55e37f8a110692381dbe07dbaf13d142d4766c7 Mon Sep 17 00:00:00 2001 From: Karan Vaidya Date: Tue, 10 Sep 2024 01:30:29 +0530 Subject: [PATCH 1/2] Add example for download file --- python/composio/client/collections.py | 2 +- .../sql_agent_plotter_crewai/run_issue.py | 66 +++++++++++++++++++ python/tests/test_example.py | 14 +++- 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 python/examples/sql_agent/sql_agent_plotter_crewai/run_issue.py diff --git a/python/composio/client/collections.py b/python/composio/client/collections.py index 29cbfe0646..c134809cd8 100644 --- a/python/composio/client/collections.py +++ b/python/composio/client/collections.py @@ -401,7 +401,7 @@ class TriggerModel(BaseModel): class SuccessExecuteActionResponseModel(BaseModel): """Success execute action response data model.""" - successful: bool + successfull: bool data: t.Dict error: t.Optional[str] = None diff --git a/python/examples/sql_agent/sql_agent_plotter_crewai/run_issue.py b/python/examples/sql_agent/sql_agent_plotter_crewai/run_issue.py new file mode 100644 index 0000000000..bdf0ab0427 --- /dev/null +++ b/python/examples/sql_agent/sql_agent_plotter_crewai/run_issue.py @@ -0,0 +1,66 @@ +import os +from pathlib import Path + +import dotenv +from composio_crewai import ComposioToolSet +from crewai import Agent, Crew, Task +from langchain_openai import ChatOpenAI + +from composio import Action, App + + + +llm = ChatOpenAI(model="gpt-4-turbo") + +main_task = "Plot a bar chart of employee's first letter of name to average salary" +code_interpreter_tools = ComposioToolSet(output_dir=Path.home() / "composio_output").get_tools(apps=[App.CODEINTERPRETER]) +sql_tools = ComposioToolSet(output_dir=Path.home() / "composio_output").get_tools(apps=[App.SQLTOOL]) + +code_interpreter_agent = Agent( + role="Python Code Interpreter Agent", + goal=f"""Run I a code to get achieve a task given by the user""", + backstory="""You are an agent that helps users run Python code.""", + verbose=True, + tools=code_interpreter_tools, + llm=llm, + memory=True, +) + +code_interpreter_task = Task( + description=f"""Run Python code to get achieve a task - {main_task}""", + expected_output=f"""Python code executed successfully. The result of the task is returned - {main_task}""", + agent=code_interpreter_agent, +) + +sql_agent = Agent( + role="SQL Agent", + goal=f"""Run SQL queries to get achieve a task given by the user""", + backstory=( + "You are an agent that helps users run SQL queries. " + "Connect to the local SQlite DB at connection string = company.db" + "Try to analyze the tables first by listing all the tables and columns " + "and doing distinct values for each column and once sure, make a query to get the data you need." + ), + verbose=True, + tools=sql_tools, + llm=llm, + memory=True, + allow_delegation=True, +) + +sql_task = Task( + description=f"""Run SQL queries to get achieve a task - {main_task}""", + expected_output=f"""SQL queries executed successfully. The result of the task is returned - {main_task}""", + agent=sql_agent, +) + +crew = Crew( + agents=[sql_agent, code_interpreter_agent], + tasks=[sql_task, code_interpreter_task], + memory=True, + manager_agent=sql_agent, + cache=False, +) + +result = crew.kickoff() +print(result) diff --git a/python/tests/test_example.py b/python/tests/test_example.py index 390a493c02..6a1fb9ac81 100644 --- a/python/tests/test_example.py +++ b/python/tests/test_example.py @@ -127,6 +127,16 @@ }, "env": {"OPENAI_API_KEY": OPENAI_API_KEY, "COMPOSIO_API_KEY": COMPOSIO_API_KEY}, }, + "download_file": { + "plugin": "crewai", + "file": "run_issue.py", + "match": { + "type": "stdout", + "values": ["composio_output/CODEINTERPRETER_GET_FILE_CMD_default_", ""], + }, + "env": {"OPENAI_API_KEY": OPENAI_API_KEY, "COMPOSIO_API_KEY": COMPOSIO_API_KEY}, + "cwd": EXAMPLES_PATH / "sql_agent" / "sql_agent_plotter_crewai", + }, # "praisonai": { # "plugin": "praisonai", # "file": PLUGINS / "praisonai" / "praisonai_demo.py", @@ -160,16 +170,18 @@ def test_example( val is not None ), f"Please provide value for `{key}` for testing `{example['file']}`" + cwd = example.get("cwd", None) proc = subprocess.Popen( # pylint: disable=consider-using-with args=[sys.executable, example["file"]], # TODO(@angryblade): Sanitize the env before running the process. env={**os.environ, **example["env"]}, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + cwd=cwd, ) # Wait for 2 minutes for example to run - proc.wait(timeout=120) + proc.wait(timeout=180) # Check if process exited with success assert proc.returncode == 0, ( From 72fe8c270aae33d6357855d944aa5f764ff712dd Mon Sep 17 00:00:00 2001 From: Karan Vaidya Date: Tue, 10 Sep 2024 01:39:49 +0530 Subject: [PATCH 2/2] Add example for download file --- .github/workflows/examples.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index d534fd4a49..8c7df604b5 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -82,3 +82,4 @@ jobs: uses: rtCamp/action-slack-notify@v2 env: SLACK_WEBHOOK: ${{ secrets.SLACK_TECH_WEBHOOK }} + SLACK_TITLE: "Example Tests Failed"