Code viewer for World: Hello World

// Use JS to write whatever HTML and data you want to the page 

// One way of using JS to write HTML and data is with a multi-line string
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

const token = "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";
const url = "https://api.openai.com/v1/chat/completions";

fetch(url, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + token,
    },
    body: JSON.stringify({
        'model': 'gpt-3.5-turbo',
        'messages': [{"role": "user", "content": "Say 'Hello, world!'"}]
    })
})
.then(response => {
    return response.json(); // Return JSON from the response
})
.then(result => { 
    console.log(result.choices[0].message.content);
    s = document.getElementById("output");
    s.innerHTML = result.choices[0].message.content;
})
.catch(error => {
    console.error('Error:', error);
});

// Using document.write() to display the fetched data on the webpage
document.write(`
    <div>
        <center><h1 id="output"></h1></center>
    </div>`
 );