Skip to content

Commit

Permalink
Add example for download file (ENG-1240) (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaavee315 authored Sep 9, 2024
1 parent 7bbf81d commit 3b84d15
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,4 @@ jobs:
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_TECH_WEBHOOK }}
SLACK_TITLE: "Example Tests Failed"
2 changes: 1 addition & 1 deletion python/composio/client/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
66 changes: 66 additions & 0 deletions python/examples/sql_agent/sql_agent_plotter_crewai/run_issue.py
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 13 additions & 1 deletion python/tests/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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, (
Expand Down

0 comments on commit 3b84d15

Please sign in to comment.