File size: 945 Bytes
32ce9ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const chatBox = document.getElementById("chat-box");
const userInput = document.getElementById("user-input");
const sendBtn = document.getElementById("send-btn");

sendBtn.onclick = async () => {
    const message = userInput.value;
    if (!message) return;

    // عرض رسالة المستخدم
    const userDiv = document.createElement("div");
    userDiv.textContent = "أنت: " + message;
    chatBox.appendChild(userDiv);

    userInput.value = "";

    // إرسال للـ API
    const response = await fetch("http://localhost:8000/chat", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ user_id: "user1", message: message })
    });
    const data = await response.json();

    const novaDiv = document.createElement("div");
    novaDiv.textContent = "NOVA AI: " + data.response;
    chatBox.appendChild(novaDiv);

    chatBox.scrollTop = chatBox.scrollHeight;
};