Code viewer for World: English To Irish Dictionary
document.write ( `

<!DOCTYPE html>
<html>
<head>
</head>
<body>
    <h1>My web page</h1>
    <p>Enter what you want to translate.</p>
    <input type="text" id="input" name="input">
    <input type="submit" id="submit" value="Submit">
    <br>
    <p id="output"></p>
    
    <script>
        r = document.getElementById("submit");
        r.addEventListener("click", translate);
        
        i = document.getElementById("input").value
        
        console.log("Translate the following message from English to Irish: " + i)
    
        const token = "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";

        const url = "https://api.openai.com/v1/chat/completions";

        function translate() {
            fetch(url, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'Authorization': 'Bearer ' + token,
                },
                body: JSON.stringify({
                    "model": "gpt-3.5-turbo",
                    "messages": [{
                        "role": "user",
                        "content": "Translate the following message from English to Irish: " + i
                    }]
                })
            })
            .then(response => {
                return response.json(); // Return the JSON data from the response
            })
            .then(result => {
                r = result.choices[0].message.content
                out = document.getElementById("output");
                out.innerHTML = i + " in Irish is: " + r
                console.log(r)
            })
            .catch(error => {
                console.error(error); // Handle any errors that occur during the request
            });
        }
    </script>
</body>
</html>


` );