File size: 1,361 Bytes
d5f6bc8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
const endpoint = "https://aeris-framework.onrender.com/v1/chat/completions";

const chatWindow = document.getElementById("chat-window");
const userInput = document.getElementById("user-input");

function appendMessage(role, text) {
  const message = document.createElement("div");
  message.className = "message " + (role === "You" ? "user" : "aeris");
  message.innerHTML = `<strong>${role}:</strong> ${text}`;
  chatWindow.appendChild(message);
  chatWindow.scrollTop = chatWindow.scrollHeight;
}

async function sendMessage() {
  const input = userInput.value.trim();
  if (!input) return;

  appendMessage("You", input);
  userInput.value = "";

  appendMessage("AERIS", "<em>thinking…</em>");

  const response = await fetch(endpoint, {
    method: "POST",
    headers: {
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      model: "gpt-4",
      messages: [
        { role: "system", content: "You are AERIS, a dialectical reasoning assistant." },
        { role: "user", content: input }
      ]
    })
  });

  const data = await response.json();
  const message = data.choices?.[0]?.message?.content || "Error: no response.";
  
  chatWindow.lastChild.remove(); // remove thinking…
  appendMessage("AERIS", message);
}

function clearChat() {
  chatWindow.innerHTML = "";
}