witty-football-93730
09/15/2023, 1:53 PM// 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)
})