https://discord.gg/botpress logo
This would be the piece of code you can use to cal...
# 🌎general
w
This would be the piece of code you can use to call GPT directly from your executeCode card. Obviously you would need to change a few things in there to suit your use case
Copy code
// Replace 'YOUR_API_KEY' with your actual API key from OpenAI
const OPENAI_API_KEY = 'YOUR_API_KEY'

// Define the API endpoint URL
const apiUrl = 'https://api.openai.com/v1/chat/completions'

// The message you want to send to GPT-3
const userInput = "Translate the following English text to French: 'Hello, world.'"

// Define the parameters for the API request
const params = {
  model: 'gpt-3.5-turbo', // Engine you want to use
  messages: [
    { role: 'system', content: 'You are a helpful assistant.' },
    { role: 'user', content: userInput }
  ],
  temperature: 0.9, // Controls randomness,
  max_tokens: 1024 // Controls length of response
}

// Set the API authorization header
const headers = {
  Authorization: `Bearer ${OPENAI_API_KEY}`
}

// Make the API request
axios
  .post(apiUrl, params, { headers })
  .then((response) => {
    console.log('GPT-3 Response:', response.data.choices[0].message.content)
  })
  .catch((error) => {
    console.error('Error:', error.response.data.error.message)
  })
4 Views