Toto je starší verze dokumentu!
<!DOCTYPE html> <html lang="cs"> <head> <meta charset="utf-8"/> <title>OpenAI API example</title> <style> </style> <script> // Generate your API key on https://beta.openai.com/account/api-keys const API_TOKEN = 'get-your-own' async function queryOpenAI() { const url = 'https://api.openai.com/v1/completions' const bearer = 'Bearer ' + API_TOKEN let apiResponse = null const prompt = 'Bylo nebylo,' try { apiResponse = await fetch(url, { method: 'POST', headers: { 'Authorization': bearer, 'Content-Type': 'application/json' }, body: JSON.stringify({ 'model': 'text-davinci-003', 'prompt': prompt, 'temperature': 1, 'max_tokens': 500, 'n': 3, 'stream': false, 'logprobs': null, 'stop': '\n' }) }) } catch (error) { console.error('There was a problem fetching from OpenAI API: ' + error) } if (apiResponse) { const result = await apiResponse.json() console.log(result) for(const choice of result.choices){ document.body.innerHTML += `<p>${prompt}${choice.text}</p>` } } } setTimeout(queryOpenAI, 0) </script> </head> <body> </body> </html>