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
ts 33 lines 756 Bytes
Raw
1 import { Composio } from '@composio/core';
2 import { OpenAI } from 'openai';
3
4 const openai = new OpenAI({
5 apiKey: process.env.OPENAI_API_KEY,
6 });
7
8 const composio = new Composio({
9 apiKey: process.env.COMPOSIO_API_KEY,
10 });
11
12 const tools = await composio.tools.get('default', {
13 tools: ['HACKERNEWS_GET_USER'],
14 });
15
16 const query = 'What is the user "pg"';
17
18 const response = await openai.chat.completions.create({
19 model: 'gpt-4o',
20 messages: [
21 {
22 role: 'system',
23 content: 'You are a helpful assistant that can use tools to answer questions.',
24 },
25 { role: 'user', content: query },
26 ],
27 tools: tools,
28 tool_choice: 'auto',
29 });
30
31 const toolCall = await composio.provider.handleToolCalls('default', response);
32
33 console.log(toolCall);