Question:
I am trying to get a result like a ChatGPT/Ghostwriter but it isn’t working.
Repl link:
https://replit.com/@python660/SalladShooterGPT#chatbot.html
<!DOCTYPE html>
<html>
<head>
<title>SalladShooterGPT</title>
<style>
html {
font-family: Arial;
background-color: #26283b;
}
.input {
margin-bottom: 2em;
}
#chatbox {
background-color: white;
height: 300px;
width: 400px;
overflow-y: scroll;
border: 1px solid #ccc;
border-radius: 5px;
padding: 10px;
margin-bottom: 10px;
}
h1,h2,h3 {
color: white;
text-align: center;
}
h1 {
font-size: 4em;
margin-bottom: 0;
border: 2px solid white;
text-align: center;
padding: 0.25em;
border-radius: 10px;
}
h2 {
font-size: 3em;
margin-bottom: 0;
}
h3 {
font-size: 2em;
margin-bottom: 1em;
}
.submit {
font-weight: bold;
color: white;
border-radius: 0.5em;
background-color: green;
padding: 0.5em;
border-color: transparent;
box-shadow: 0px 2px 2px 0px #26283b;
}
.container {
margin: auto;
width: 50%;
}
p {
border: 1px solid #26283b;
border-radius: 10px;
padding: 0.5em;
box-shadow: 0px 2px 2px 0px #26283b;
}
.sender {
background-color: #26283b;
border-right: 1px solid #26283b;
display: inline-block;
color: white;
padding: 0.5em ;
margin-left: -0.5em;
border-bottom-left-radius: 9px;
border-top-left-radius: 9px;
margin-top: -0.65em;
margin-bottom: -0.65em;
margin-right: 0.55em;
}
.bot {
background-color: green;
border-right: 1px solid #26283b;
display: inline-block;
color: white;
padding: 0.5em ;
margin-left: -0.5em;
border-bottom-left-radius: 9px;
border-top-left-radius: 9px;
margin-top: -0.65em;
margin-bottom: -0.65em;
margin-right: 0.55em;
}
</style>
</head>
<body onload="onLoad()">
<link rel="stylesheet" href="https://badge.coolcodersj.repl.co/style.css">
<a class="badge" href="https://repl.it/@SalladShooter" target="_blank">
<img src="/DONT-DELETE/Logo.png" alt="SalladShooter" />SalladShooter</a>
<h1>SalladShooterGPT</h2>
<h2 id="hello">Hello, </h2>
<h3>Welcome Back!</h3>
<div class="container">
<div id="chatbox"></div>
<input class="input" type="text" id="userInput">
<button class="submit" onclick="handleUserInput(event)">➤ Send</button>
</div>
<script>
const apiUrl = 'https://ml610-replit-v2-codeinstruct-3b-ggml.hf.space/';
const username = localStorage.getItem("chatbotUsername");
function onLoad() {
const username = localStorage.getItem("chatbotUsername");
document.getElementById("hello").innerHTML = "Hello, " + username + "!";
}
async function handleUserInput(event) {
const userInput = document.getElementById("userInput");
const userMessage = userInput.value;
userInput.value = "";
appendMessage(userMessage, username);
await generateResponse(userMessage);
}
async function generateResponse(userMessage) {
try {
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
message: result
})
});
if (!response.ok) {
throw new Error('Failed to fetch response from the API');
}
const data = await response.json();
const chatbotResponse = data.message;
appendMessage(chatbotResponse, "SalladShooterGPT");
} catch (error) {
console.error(error);
appendMessage("Sorry, an error occurred.", "SalladShooterGPT");
}
}
function appendMessage(message, sender) {
const chatbox = document.getElementById("chatbox");
const messageElement = document.createElement("p");
if (sender == "SalladShooterGPT") {
messageElement.innerHTML = `<div class="bot"><strong>${sender}:</strong></div>${message}`;
} else {
messageElement.innerHTML = `<div class="sender"><strong>${sender}:</strong></div>${message}`;
}
chatbox.appendChild(messageElement);
chatbox.scrollTop = chatbox.scrollHeight;
}
</script>
</body>
</html>