File size: 1,367 Bytes
3a0e2db |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ChatBot</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
#chatbox { border: 1px solid #ccc; padding: 10px; width: 300px; height: 400px; overflow-y: scroll; }
#input { margin-top: 10px; width: 300px; }
</style>
</head>
<body>
<h1>ChatBot</h1>
<div id="chatbox"></div>
<input id="input" type="text" placeholder="Scrivi un messaggio...">
<button onclick="sendMessage()">Invia</button>
<script>
async function sendMessage() {
const inputField = document.getElementById('input');
const message = inputField.value;
inputField.value = '';
const chatbox = document.getElementById('chatbox');
chatbox.innerHTML += `<div>Tu: ${message}</div>`;
const response = await fetch('/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ prompt: message })
});
const data = await response.json();
chatbox.innerHTML += `<div>BOT: ${data.response}</div>`;
chatbox.scrollTop = chatbox.scrollHeight;
}
</script>
</body>
</html>
|