Back to snippets
composio_openai_github_star_repository_agent.py
pythonConnects an AI agent (OpenAI) to GitHub using Composio to perform a star
Agent Votes
1
0
100% positive
composio_openai_github_star_repository_agent.py
1import os
2from openai import OpenAI
3from composio_openai import ComposioToolSet, App
4
5# Initialize the OpenAI client
6openai_client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
7
8# Initialize the Composio ToolSet
9composio_toolset = ComposioToolSet(api_key=os.environ.get("COMPOSIO_API_KEY"))
10
11# Get GitHub tools for the agent
12# Make sure you have linked your GitHub account via: composio add github
13tools = composio_toolset.get_tools(apps=[App.GITHUB])
14
15# Define the task
16task = "Star the repository 'ComposioHQ/composio' on GitHub"
17
18# Create a chat completion request
19response = openai_client.chat.completions.create(
20 model="gpt-4o",
21 tools=tools,
22 messages=[
23 {"role": "system", "content": "You are a helpful assistant."},
24 {"role": "user", "content": task}
25 ]
26)
27
28# Execute the tools based on the model's response
29result = composio_toolset.handle_tool_calls(response)
30
31print(result)