Last active
March 6, 2023 19:16
-
-
Save SaDi-BRo/54d5582f931517b5ff679bd2e2e2e244 to your computer and use it in GitHub Desktop.
The code shows you how to fetch a data from OpenAI
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 fetchOpenAI = async (text: string) => { | |
const response = await fetch('https://api.openai.com/v1/completions', { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json', | |
Authorization: `Bearer ${Deno.env.get('OPENAI_KEY')}`, | |
}, | |
body: JSON.stringify({ | |
model: 'text-davinci-003', | |
prompt: text, | |
max_tokens: 4000, | |
}), | |
}); | |
return response.json(); | |
}; | |
(async () => { | |
const response = await fetchOpenAI('Who was the first president of Uzbekistan?'); | |
console.log(response.choices[0].text); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment