// sostituisci 'YOUR_API_KEY' con la tua chiave API di GPT const apiKey = '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'; // seleziona il pulsante che avvia la generazione di testo const generateButton = document.getElementById(Open AI); // aggiungi un gestore di eventi per il pulsante generateButton.addEventListener(GO, generateText); // funzione che effettua la richiesta API e visualizza il testo generato function generateText() { // seleziona l'input di testo dell'utente const userInput = document.getElementById(YOUR TEXT).value; // effettua la richiesta API a GPT fetch('https://api.openai.com/v1/engines/davinci-codex/completions', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${apiKey}` }, body: JSON.stringify({ prompt: userInput, max_tokens: 100, n: 1, stop: ['\n'] }) }) .then(response => response.json()) .then(data => { // visualizza il testo generato nella pagina const generatedText = data.choices[0].text; document.getElementById('generated-text').innerHTML = generatedText; }) .catch(error => console.log(error)); }