OpenAI simple text call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require('axios'); | |
// You should use dotenv - but for the easy of use I put it here. | |
const API_KEY = 'your_api_key_here'; | |
const API_URL = 'https://api.openai.com/v1/'; | |
const prompt = 'how can I bake a good bread?'; | |
async function generateText(prompt) { | |
const response = await axios.post(`${API_URL}engines/davinci-codex/completions`, { | |
prompt, | |
max_tokens: 50, | |
n: 1, | |
stop: '\n', | |
}, { | |
headers: { | |
'Content-Type': 'application/json', | |
'Authorization': `Bearer ${API_KEY}`, | |
}, | |
}); | |
const text = response.data.choices[0].text.trim(); | |
// let's just log it for now | |
console.log(text); | |
} | |
generateText(prompt); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment