I made this code, but it does not work, if its impossible to do it via ChatGPT AI, is there any other AI I can use to make this work, like pyro or any other AI I can use? I heard there is a way to fork Pyro AI into replit and then give post requests from there, but unsure how to do it, all I’ve been able to do is just to clone the pyro respiratory, not sure what to do from there.
<!DOCTYPE html>
<html>
<head>
<title>ChatGPT Test Chat</title>
</head>
<body>
<div id="chatWindow"></div>
<div class="message user">
<input id="messageInput" placeholder="Enter your message...">
<button onclick="sendMessage()" id="sendMessage">Send</button>
</div>
<script>
function sendMessage() {
const apiKey = '---';
const messageInput = document.getElementById('messageInput').value;
const prompt = encodeURIComponent(messageInput);
const fetchUrl = 'https://api.openai.com/v1/engines/davinci-codex/completions';
fetch(fetchUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
},
body: JSON.stringify({
prompt: prompt,
max_tokens: 50,
temperature: 0.7,
n: 1,
stop: 'n'
})
})
.then(res => {
if (!res.ok) {
throw new Error(`HTTP error ${res.status}`);
}
return res.json();
})
.then(response => {
const chatWindow = document.getElementById('chatWindow');
const messageElement = document.createElement('div');
messageElement.classList.add('message', 'bot');
messageElement.innerHTML = `<p>${response.choices[0].text.trim()}</p>`;
chatWindow.appendChild(messageElement);
})
.catch(error => {
console.error(`Error: ${error}`);
});
}
</script>
<style>
#chatWindow {
height: 80vh;
overflow-y: scroll;
}
.message {
padding: 10px;
}
.message.user {
align-self: flex-end;
}
</style>
</body>
</html>
Tried regenerating the API key but did not work