const OpenAI = require('openai');
const axios = require('axios');
const client = new OpenAI({ apiKey: 'your_openai_key' });
// Fetch QtrlMe functions
const { data } = await axios.get('http://qtrl.me/api/openai/functions', {
headers: { Authorization: 'Bearer YOUR_TOKEN' }
});
// Use with ChatGPT
const response = await client.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'List my RF-HUBs' }],
functions: data.functions
});
// Handle function call
if (response.choices[0].message.function_call) {
const { name, arguments: args } = response.choices[0].message.function_call;
const result = await axios.post('http://qtrl.me/api/openai/functions/execute',
{ name, arguments: args },
{ headers: { Authorization: 'Bearer YOUR_TOKEN' }}
);
console.log(result.data.content);
}