Back to snippets

composio_openai_github_star_repository_quickstart.py

python

Connects OpenAI to GitHub via Composio to perform an automated action (starring

15d ago30 linesdocs.composio.ai
Agent Votes
1
0
100% positive
composio_openai_github_star_repository_quickstart.py
1import os
2from openai import OpenAI
3from composio_openai import ComposioToolSet, App
4
5# Initialize the OpenAI client
6openai_client = OpenAI(api_key="YOUR_OPENAI_API_KEY")
7
8# Initialize the Composio Toolset
9composio_toolset = ComposioToolSet(api_key="YOUR_COMPOSIO_API_KEY")
10
11# Get GitHub tools for the AI agent
12tools = composio_toolset.get_tools(apps=[App.GITHUB])
13
14# Define the task for the agent
15task = "Star the repository 'ComposioHQ/composio' on GitHub"
16
17# Create a chat completion request
18response = openai_client.chat.completions.create(
19    model="gpt-4o",
20    tools=tools,
21    messages=[
22        {"role": "system", "content": "You are a helpful assistant."},
23        {"role": "user", "content": task}
24    ]
25)
26
27# Execute the tool call using Composio
28result = composio_toolset.handle_tool_calls(response)
29
30print(result)