You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<script>
const PASSWORD = "1234";
let username = "";
/* ENTER CHAT */
function enterChat(){
const pass = password.value;
const user = usernameInput = document.getElementById("username").value.trim();
const x = Number(document.getElementById("xvalue").value);
if(pass !== PASSWORD){
alert("Wrong password");
return;
}
if(!user){
alert("Username required");
return;
}
if(x < 1 || x > 10){
alert("X must be between 1 and 10");
return;
}
username = user;
login.style.display = "none";
chat.style.display = "block";
addMessage("System","Welcome "+username);
addMessage("Arora","I am Arora, your offline AI assistant.");
}
/* SEND MESSAGE */
function sendMessage(){
const input = document.getElementById("messageInput");
const text = input.value.trim();
if(!text) return;
addMessage(username, text);
input.value = "";
setTimeout(()=>aroraReply(text.toLowerCase()),300);
}
/* ADD MESSAGE */
function addMessage(user,text){
const div = document.createElement("div");
div.className = "msg";
div.innerHTML =
`${user}: ${text}`;
messages.appendChild(div);
messages.scrollTop = messages.scrollHeight;
}
/* OFFLINE AI */
function aroraReply(m){
let r = "I am listening.";
if(m.includes("who") && m.includes("you"))
r = "I am Arora, an offline artificial intelligence.";
else if(m.includes("hello") || m.includes("hi"))
r = "Hello 👋";
else if(m.includes("why"))
r = "Because this system follows simple logic.";
else if(m.includes("how"))
r = "Explain your question clearly.";
else if(m.includes("ai"))
r = "AI means Artificial Intelligence.";
else if(m.includes("language"))
r = "I understand basic English commands.";
addMessage("Arora", r);
}
</script>
<script>
const PASSWORD = "1234";
let username = "";
let lastTopic = "";
function enterChat(){
const pass = password.value;
const user = document.getElementById("username").value.trim();
const x = Number(document.getElementById("xvalue").value);
if(pass !== PASSWORD) return alert("Wrong password");
if(!user) return alert("Username required");
if(x < 1 || x > 10) return alert("X must be 1–10");
username = user;
login.style.display = "none";
chat.style.display = "block";
addMessage("System","Welcome "+username);
addMessage("Arora",
"Hi 👋 I’m Arora. I work like Meta Chat AI, but offline. Ask me anything.");
}
function sendMessage(){
const input = messageInput;
const text = input.value.trim();
if(!text) return;
addMessage(username,text);
input.value="";
setTimeout(()=>aroraReply(text.toLowerCase()),400);
}
function addMessage(user,text){
const div=document.createElement("div");
div.className="msg";
div.innerHTML=
`${user}: ${text}`;
messages.appendChild(div);
messages.scrollTop=messages.scrollHeight;
}
function aroraReply(m){
let r="That’s interesting. Tell me more.";
if(m.includes("who are you")){
r="I’m Arora, a chat AI similar in behavior to Meta AI. I answer, explain, and help.";
}
else if(m.includes("what can you do")){
r="I can chat, explain concepts, answer questions, and keep conversation flowing.";
}
else if(m.includes("ai")){
r="AI means Artificial Intelligence — machines designed to think and respond like humans.";
lastTopic="ai";
}
else if(m.includes("why")){
r="Good question. The reason depends on context — explain more.";
}
else if(m.includes("how")){
r="I’ll explain it step by step. What exactly do you want to know?";
}
else if(m.includes("hello")||m.includes("hi")){
r="Hey 👋 How can I help you today?";
}
else if(lastTopic==="ai"){
r="Since we were talking about AI, remember it learns from data and logic.";
}
addMessage("Arora",r);
}
</script>
<script>
let history = [
{ role: "system", content: "You are ChatGPT-like AI." }
];
async function sendMessage(text){
history.push({ role:"user", content:text });
const res = await fetch("/chat", {
method:"POST",
headers:{ "Content-Type":"application/json" },
body: JSON.stringify({ messages: history })
});
const reply = await res.json();
history.push(reply);
addMessage("AI", reply.content);
}
</script>