֎ Using Composio With OpenAI

Star A Repository on Github

In this example, we will use OpenAI Assistant to star a repository on Github using Composio Tools

1

Install Packages

$pip install composio-openai openai
2

Import Libraries & Initialize ComposioToolSet & LLM

1from openai import OpenAI
2from composio_openai import ComposioToolSet, Action
3
4openai_client = OpenAI()
5composio_toolset = ComposioToolSet()
3

Connect Your GitHub Account

You need to have an active GitHub Integration. Learn how to do this here
$composio login
>composio add github

Don’t forget to set your COMPOSIO_API_KEY and OPENAI_API_KEY in your environment variables.

4

Get All Github Tools

You can get all the tools for a given app as shown below, but you can get specific actions and filter actions using usecase & tags. Learn more here

1tools = composio_toolset.get_tools(apps=[App.GITHUB])
5

Define the Assistant

1assistant_instruction = "You are a super intelligent personal assistant"
2
3assistant = openai_client.beta.assistants.create(
4 name="Personal Assistant",
5 instructions=assistant_instruction,
6 model="gpt-4-turbo-preview",
7 tools=tools,
8)
9
10thread = openai_client.beta.threads.create()
11my_task = "Star a repo composiohq/composio on GitHub"
12message = openai_client.beta.threads.messages.create(thread_id=thread.id,role="user",content=my_task)
13
14run = openai_client.beta.threads.runs.create(thread_id=thread.id,assistant_id=assistant.id)
15
16response_after_tool_calls = composio_toolset.wait_and_handle_assistant_tool_calls(
17 client=openai_client,
18 run=run,
19 thread=thread,
20)
6

Execute the Agent

1print(response_after_tool_calls)
Built with