Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
py 33 lines 796 Bytes
Raw
1 """
2 OpenAI demo.
3 """
4
5 from composio_openai import OpenAIProvider
6 from openai import OpenAI
7
8 from composio import Composio
9
10 # Initialize tools.
11 openai_client = OpenAI()
12 composio = Composio(provider=OpenAIProvider())
13
14 # Define task.
15 task = "Star a repo composiohq/composio on GitHub"
16
17 # Get GitHub tools that are pre-configured
18 tools = composio.tools.get(user_id="default", toolkits=["GITHUB"])
19
20 # Get response from the LLM
21 response = openai_client.chat.completions.create(
22 model="gpt-4o-mini",
23 tools=tools,
24 messages=[
25 {"role": "system", "content": "You are a helpful assistant."},
26 {"role": "user", "content": task},
27 ],
28 )
29 print(response)
30
31 # Execute the function calls.
32 result = composio.provider.handle_tool_calls(response=response, user_id="default")
33 print(result)