Create templates/index.html
Browse files- templates/index.html +68 -0
templates/index.html
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<title>Model-Tiny Chat</title>
|
| 6 |
+
<style>
|
| 7 |
+
body { font-family: sans-serif; max-width: 800px; margin: 2em auto; padding: 0 1em; }
|
| 8 |
+
#chatbox { border: 1px solid #ccc; height: 400px; overflow-y: scroll; padding: 1em; margin-bottom: 1em; }
|
| 9 |
+
.user { color: blue; font-weight: bold; }
|
| 10 |
+
.bot { color: green; font-weight: bold; }
|
| 11 |
+
#input-area { display: flex; gap: 10px; }
|
| 12 |
+
input { flex-grow: 1; padding: 10px; }
|
| 13 |
+
</style>
|
| 14 |
+
</head>
|
| 15 |
+
<body>
|
| 16 |
+
<h1>AshokGakr/model-tiny Agent</h1>
|
| 17 |
+
<div id="chatbox"></div>
|
| 18 |
+
<div id="input-area">
|
| 19 |
+
<input type="text" id="user-input" placeholder="Type your message here...">
|
| 20 |
+
<button onclick="sendMessage()">Send</button>
|
| 21 |
+
</div>
|
| 22 |
+
|
| 23 |
+
<script>
|
| 24 |
+
let messages = [
|
| 25 |
+
{"role": "system", "content": "You are a helpful assistant specialized in reasoning and tool use."}
|
| 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 |
+
// Update UI and Message History
|
| 35 |
+
messages.push({"role": "user", "content": text});
|
| 36 |
+
chatbox.innerHTML += `<p><span class="user">User:</span> ${text}</p>`;
|
| 37 |
+
input.value = '';
|
| 38 |
+
|
| 39 |
+
const botMessageDiv = document.createElement('p');
|
| 40 |
+
botMessageDiv.innerHTML = '<span class="bot">Bot:</span> <span class="content"></span>';
|
| 41 |
+
chatbox.appendChild(botMessageDiv);
|
| 42 |
+
const contentSpan = botMessageDiv.querySelector('.content');
|
| 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({ messages })
|
| 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 |
+
fullBotResponse += chunk;
|
| 61 |
+
contentSpan.innerText = fullBotResponse;
|
| 62 |
+
chatbox.scrollTop = chatbox.scrollHeight;
|
| 63 |
+
}
|
| 64 |
+
messages.push({"role": "assistant", "content": fullBotResponse});
|
| 65 |
+
}
|
| 66 |
+
</script>
|
| 67 |
+
</body>
|
| 68 |
+
</html>
|