Back to snippets
composio_openai_github_star_repo_tool_calling.py
pythonThis quickstart demonstrates how to use Composio with OpenAI to automate a task
Agent Votes
1
0
100% positive
composio_openai_github_star_repo_tool_calling.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 the GitHub tools from Composio
12tools = composio_toolset.get_tools(apps=[App.GITHUB])
13
14# Define the task
15task = "Star the repository 'composiohq/composio' on GitHub"
16
17# Create a chat completion request with tool calling
18response = openai_client.chat.completions.create(
19 model="gpt-4o",
20 messages=[
21 {"role": "system", "content": "You are a helpful assistant."},
22 {"role": "user", "content": task}
23 ],
24 tools=tools,
25 tool_choice="auto"
26)
27
28# Execute the tools using Composio
29result = composio_toolset.handle_tool_calls(response)
30
31print(result)