Update templates/index.html
Browse files- templates/index.html +32 -25
templates/index.html
CHANGED
|
@@ -1,52 +1,59 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
-
<html
|
| 3 |
<head>
|
| 4 |
-
<
|
| 5 |
-
<title>ReAct Agent Console</title>
|
| 6 |
<style>
|
| 7 |
-
body { font-family:
|
| 8 |
-
#
|
| 9 |
-
.
|
| 10 |
-
.
|
| 11 |
-
input { width:
|
| 12 |
-
button { padding:
|
| 13 |
</style>
|
| 14 |
</head>
|
| 15 |
<body>
|
| 16 |
-
<h2>
|
| 17 |
-
<div id="
|
| 18 |
-
<
|
| 19 |
-
<
|
|
|
|
| 20 |
|
| 21 |
<script>
|
| 22 |
-
async function
|
| 23 |
const input = document.getElementById('user-input');
|
| 24 |
-
const
|
| 25 |
-
const
|
| 26 |
-
if
|
| 27 |
|
| 28 |
-
|
| 29 |
input.value = '';
|
| 30 |
|
| 31 |
-
const
|
| 32 |
-
|
| 33 |
-
consoleBox.appendChild(traceDiv);
|
| 34 |
|
| 35 |
-
// Fetching a streaming response [23, 24]
|
| 36 |
const response = await fetch('/chat', {
|
| 37 |
method: 'POST',
|
| 38 |
headers: {'Content-Type': 'application/json'},
|
| 39 |
-
body: JSON.stringify({ message:
|
| 40 |
});
|
| 41 |
|
| 42 |
const reader = response.body.getReader();
|
| 43 |
const decoder = new TextDecoder();
|
|
|
|
| 44 |
|
| 45 |
while (true) {
|
| 46 |
const { done, value } = await reader.read();
|
| 47 |
if (done) break;
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
}
|
| 51 |
}
|
| 52 |
</script>
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
<head>
|
| 4 |
+
<title>Nanbeige 3B Chat</title>
|
|
|
|
| 5 |
<style>
|
| 6 |
+
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #1e1e1e; color: #ccc; padding: 40px; }
|
| 7 |
+
#chat-box { border: 1px solid #333; height: 500px; overflow-y: auto; padding: 20px; background: #252526; border-radius: 8px; }
|
| 8 |
+
.thought { color: #888; font-style: italic; background: #2d2d2d; padding: 10px; border-left: 3px solid #555; margin: 10px 0; border-radius: 4px; display: block; }
|
| 9 |
+
.response { color: #569cd6; font-weight: bold; margin-bottom: 20px; display: block; }
|
| 10 |
+
input { width: 85%; padding: 12px; background: #3c3c3c; color: white; border: none; border-radius: 4px; }
|
| 11 |
+
button { padding: 12px 20px; background: #007acc; color: white; border: none; cursor: pointer; border-radius: 4px; }
|
| 12 |
</style>
|
| 13 |
</head>
|
| 14 |
<body>
|
| 15 |
+
<h2>Nanbeige 4.1-3B Reasoning Console</h2>
|
| 16 |
+
<div id="chat-box"></div>
|
| 17 |
+
<br>
|
| 18 |
+
<input type="text" id="user-input" placeholder="Ask something...">
|
| 19 |
+
<button onclick="sendMsg()">Send</button>
|
| 20 |
|
| 21 |
<script>
|
| 22 |
+
async function sendMsg() {
|
| 23 |
const input = document.getElementById('user-input');
|
| 24 |
+
const box = document.getElementById('chat-box');
|
| 25 |
+
const msg = input.value;
|
| 26 |
+
if(!msg) return;
|
| 27 |
|
| 28 |
+
box.innerHTML += `<div><strong>User:</strong> ${msg}</div>`;
|
| 29 |
input.value = '';
|
| 30 |
|
| 31 |
+
const resDiv = document.createElement('div');
|
| 32 |
+
box.appendChild(resDiv);
|
|
|
|
| 33 |
|
|
|
|
| 34 |
const response = await fetch('/chat', {
|
| 35 |
method: 'POST',
|
| 36 |
headers: {'Content-Type': 'application/json'},
|
| 37 |
+
body: JSON.stringify({ message: msg })
|
| 38 |
});
|
| 39 |
|
| 40 |
const reader = response.body.getReader();
|
| 41 |
const decoder = new TextDecoder();
|
| 42 |
+
let fullText = "";
|
| 43 |
|
| 44 |
while (true) {
|
| 45 |
const { done, value } = await reader.read();
|
| 46 |
if (done) break;
|
| 47 |
+
|
| 48 |
+
fullText += decoder.decode(value);
|
| 49 |
+
|
| 50 |
+
// Real-time parsing of thoughts vs final response [13]
|
| 51 |
+
let processed = fullText
|
| 52 |
+
.replace(/<thought>([\s\S]*?)<\/thought>/g, '<span class="thought">Thought: $1</span>')
|
| 53 |
+
.replace(/<\/thought>([\s\S]*)/g, '</span><span class="response">$1</span>');
|
| 54 |
+
|
| 55 |
+
resDiv.innerHTML = processed;
|
| 56 |
+
box.scrollTop = box.scrollHeight;
|
| 57 |
}
|
| 58 |
}
|
| 59 |
</script>
|