AI-API / templates /index.html
JJ94's picture
Update templates/index.html
3a8dd40 verified
raw
history blame
1.96 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat with LLaMA</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js" defer></script>
</head>
<body class="bg-light">
<div class="container py-5" x-data="{ messages: [], userInput: '' }">
<h2 class="mb-4 text-center">Chat with LLaMA 🤖</h2>
<div class="card shadow">
<div class="card-body" style="height: 300px; overflow-y: auto;" id="chatBox">
<template x-for="(msg, index) in messages" :key="index">
<p><b x-text="msg.role + ':'"></b> <span x-text="msg.content"></span></p>
</template>
</div>
</div>
<div class="input-group mt-3">
<input type="text" class="form-control" x-model="userInput" placeholder="Type a message..." @keydown.enter="sendMessage">
<button class="btn btn-primary" @click="sendMessage">Send</button>
</div>
</div>
<script>
function sendMessage() {
const userMessage = this.userInput;
if (!userMessage) return;
// Append user message
this.messages.push({ role: "You", content: userMessage });
this.userInput = "";
axios.post("/chat", { message: userMessage })
.then(response => {
this.messages.push({ role: "Bot", content: response.data.response });
document.getElementById("chatBox").scrollTop = document.getElementById("chatBox").scrollHeight;
})
.catch(error => console.error("Error:", error));
}
</script>
</body>
</html>