File size: 794 Bytes
3c971cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
async function sendMessage() {
    const input = document.getElementById("user-input");
    const chatBox = document.getElementById("chat-box");

    const userText = input.value.trim();
    if (!userText) return;

    chatBox.innerHTML += `<div class="message user"><b>You:</b> ${userText}</div>`;
    input.value = "";
    chatBox.scrollTop = chatBox.scrollHeight;

    const response = await fetch("/generate", {
        method: "POST",
        headers: {"Content-Type": "application/json"},
        body: JSON.stringify({prompt: userText})
    });

    const data = await response.json();
    const botText = data.response || "Error generating response.";

    chatBox.innerHTML += `<div class="message bot"><b>MedBot:</b> ${botText}</div>`;
    chatBox.scrollTop = chatBox.scrollHeight;
}