Update templates/index.html
Browse files- templates/index.html +22 -31
templates/index.html
CHANGED
|
@@ -2,66 +2,57 @@
|
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
-
<title>
|
| 6 |
<style>
|
| 7 |
-
body { font-family:
|
| 8 |
-
#chatbox { border: 1px solid #
|
| 9 |
-
.
|
| 10 |
-
.
|
| 11 |
-
|
| 12 |
-
input {
|
|
|
|
|
|
|
| 13 |
</style>
|
| 14 |
</head>
|
| 15 |
<body>
|
| 16 |
-
<
|
| 17 |
<div id="chatbox"></div>
|
| 18 |
<div id="input-area">
|
| 19 |
-
<input type="text" id="user-input" placeholder="
|
| 20 |
-
<button onclick="
|
| 21 |
</div>
|
| 22 |
|
| 23 |
<script>
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
];
|
| 27 |
-
|
| 28 |
-
async function sendMessage() {
|
| 29 |
const input = document.getElementById('user-input');
|
| 30 |
-
const chatbox = document.getElementById('chatbox');
|
| 31 |
const text = input.value;
|
| 32 |
if (!text) return;
|
| 33 |
|
| 34 |
-
|
| 35 |
-
messages.push({"role": "user", "content": text});
|
| 36 |
-
chatbox.innerHTML += `<p><span class="user">User:</span> ${text}</p>`;
|
| 37 |
input.value = '';
|
| 38 |
|
| 39 |
-
const
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
|
| 44 |
-
// 4. Handle Streaming Request
|
| 45 |
-
// This replicates the "Observe -> Think -> Act" loop in real-time [9, 10].
|
| 46 |
const response = await fetch('/chat', {
|
| 47 |
method: 'POST',
|
| 48 |
headers: {'Content-Type': 'application/json'},
|
| 49 |
-
body: JSON.stringify({
|
| 50 |
});
|
| 51 |
|
| 52 |
const reader = response.body.getReader();
|
| 53 |
const decoder = new TextDecoder();
|
| 54 |
-
let fullBotResponse = "";
|
| 55 |
|
| 56 |
while (true) {
|
| 57 |
const { done, value } = await reader.read();
|
| 58 |
if (done) break;
|
| 59 |
const chunk = decoder.decode(value, { stream: true });
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
chatbox.scrollTop = chatbox.scrollHeight;
|
| 63 |
}
|
| 64 |
-
messages.push({"role": "assistant", "content": fullBotResponse});
|
| 65 |
}
|
| 66 |
</script>
|
| 67 |
</body>
|
|
|
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
+
<title>ReAct Agent Console</title>
|
| 6 |
<style>
|
| 7 |
+
body { font-family: 'Courier New', Courier, monospace; background: #1e1e1e; color: #d4d4d4; padding: 20px; }
|
| 8 |
+
#chatbox { border: 1px solid #444; height: 500px; overflow-y: auto; padding: 15px; background: #252526; }
|
| 9 |
+
.message { margin-bottom: 15px; border-left: 3px solid #007acc; padding-left: 10px; white-space: pre-wrap; }
|
| 10 |
+
.user-label { color: #569cd6; font-weight: bold; }
|
| 11 |
+
.agent-label { color: #4ec9b0; font-weight: bold; }
|
| 12 |
+
#input-area { display: flex; margin-top: 20px; }
|
| 13 |
+
input { flex-grow: 1; background: #333; color: white; border: 1px solid #555; padding: 10px; }
|
| 14 |
+
button { background: #007acc; color: white; border: none; padding: 10px 20px; cursor: pointer; }
|
| 15 |
</style>
|
| 16 |
</head>
|
| 17 |
<body>
|
| 18 |
+
<h2>ReAct Agent Trace</h2>
|
| 19 |
<div id="chatbox"></div>
|
| 20 |
<div id="input-area">
|
| 21 |
+
<input type="text" id="user-input" placeholder="Ask for the time or a math problem (e.g., 25 * 4)...">
|
| 22 |
+
<button onclick="send()">Send</button>
|
| 23 |
</div>
|
| 24 |
|
| 25 |
<script>
|
| 26 |
+
async function send() {
|
| 27 |
+
const box = document.getElementById('chatbox');
|
|
|
|
|
|
|
|
|
|
| 28 |
const input = document.getElementById('user-input');
|
|
|
|
| 29 |
const text = input.value;
|
| 30 |
if (!text) return;
|
| 31 |
|
| 32 |
+
box.innerHTML += `<div><span class="user-label">User:</span> ${text}</div>`;
|
|
|
|
|
|
|
| 33 |
input.value = '';
|
| 34 |
|
| 35 |
+
const responseDiv = document.createElement('div');
|
| 36 |
+
responseDiv.className = 'message';
|
| 37 |
+
responseDiv.innerHTML = '<span class="agent-label">Agent Traces:</span><br>';
|
| 38 |
+
box.appendChild(responseDiv);
|
| 39 |
|
|
|
|
|
|
|
| 40 |
const response = await fetch('/chat', {
|
| 41 |
method: 'POST',
|
| 42 |
headers: {'Content-Type': 'application/json'},
|
| 43 |
+
body: JSON.stringify({ message: text })
|
| 44 |
});
|
| 45 |
|
| 46 |
const reader = response.body.getReader();
|
| 47 |
const decoder = new TextDecoder();
|
|
|
|
| 48 |
|
| 49 |
while (true) {
|
| 50 |
const { done, value } = await reader.read();
|
| 51 |
if (done) break;
|
| 52 |
const chunk = decoder.decode(value, { stream: true });
|
| 53 |
+
responseDiv.innerHTML += chunk;
|
| 54 |
+
box.scrollTop = box.scrollHeight;
|
|
|
|
| 55 |
}
|
|
|
|
| 56 |
}
|
| 57 |
</script>
|
| 58 |
</body>
|