abab / chat.html
MAIRK's picture
Upload chat.html
4e81ac5 verified
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>LLaMA2 聊天机器人</title>
</head>
<body>
<h2>🤖 LLaMA2 Chat</h2>
<div id="chat-box" style="border:1px solid #ccc;padding:10px;height:300px;overflow-y:auto;"></div>
<input id="user-input" type="text" placeholder="请输入..." style="width:80%;">
<button onclick="sendMessage()">发送</button>
<script>
async function sendMessage() {
const input = document.getElementById("user-input").value;
const chat = document.getElementById("chat-box");
chat.innerHTML += `<div><b>你:</b> ${input}</div>`;
const res = await fetch("http://localhost:8000/generate", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({prompt: input, token: "YOUR_SECURE_TOKEN"})
});
const data = await res.json();
chat.innerHTML += `<div><b>助手:</b> ${data.response}</div>`;
chat.scrollTop = chat.scrollHeight;
}
</script>
</body>
</html>