Goal: Star a repository on GitHub with natural language

1

Install Composio Package

pip install composio_core 
pip install composio_openai 
2

Authenticate your github account using CLI

composio add github
3

Import python packages

Modify OPENAIKEY before executing it.

from openai import OpenAI
from composio_openai import ComposioToolSet, App, Action

openai_client = OpenAI(api_key="**\*\***OPENAIKEY**\*\***")

# Initialise the Composio Tool Set

composio_toolset = ComposioToolSet(api_key="**\*\***COMPOSIO_API_KEY**\*\***")

4

Fetch all Github actions via Composio

# Get GitHub tools that are pre-configured
actions = composio_toolset.get_actions(actions=[Action.GITHUB_ACTIVITY_STAR_REPO_FOR_AUTHENTICATED_USER])
5

Using Function Call

my_task = "Star a repo ComposioHQ/composio on GitHub"

# Setup openai assistant
assistant_instruction = "You are a super intelligent personal assistant"

assistant = openai_client.beta.assistants.create(
    name="Personal Assistant",
    instructions=assistant_instruction,
    model="gpt-4-turbo-preview",
    tools=actions,  # type: ignore
)


# create a thread
thread = openai_client.beta.threads.create()
message = openai_client.beta.threads.messages.create(thread_id=thread.id,role="user",content=my_task)

# Execute Agent with integrations
run = openai_client.beta.threads.runs.create(thread_id=thread.id,assistant_id=assistant.id)

6

Handle Tool Calls - Execute Actions

# Execute Function calls
response_after_tool_calls = composio_toolset.wait_and_handle_assistant_tool_calls(
    client=openai_client,
    run=run,
    thread=thread,
)

print(response_after_tool_calls)

Putting it all together

Replace OPENAIKEY.

## Step 1
#!pip install composio_core
#!pip install composio_openai

## Step 2
#!composio add github

## Step 3
from openai import OpenAI
from composio_openai import ComposioToolSet, App

openai_client = OpenAI(api_key="******OPENAIKEY******")

# Initialise the Composio Tool Set
composio_toolset = ComposioToolSet(api_key="**\*\***COMPOSIO_API_KEY**\*\***")

## Step 4
# Get GitHub tools that are pre-configured
actions = composio_toolset.get_actions(actions=[Action.GITHUB_ACTIVITY_STAR_REPO_FOR_AUTHENTICATED_USER])


## Step 5
my_task = "Star a repo ComposioHQ/composio on GitHub"

# Create a chat completion request to decide on the action
response = openai_client.chat.completions.create(
model="gpt-4-turbo",
tools=actions, # Passing actions we fetched earlier.
messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": my_task}
  ]
)


## Step 6
# Execute Function calls
response_after_tool_calls = composio_toolset.wait_and_handle_assistant_tool_calls(
    client=openai_client,
    run=run,
    thread=thread,
)

url = f"https://platform.openai.com/playground/assistants?assistant={assistant.id}&thread={thread.id}"
print(f"Open this URL to see the assistant in action: {url}")
print(response_after_tool_calls)