Spaces:
Running
Running
ai: Bump script version.
Browse files- README.md +5 -0
- assets/css/chat/markdown.css +0 -1
- assets/plugins/loader.js +150 -67
- package.json +1 -1
README.md
CHANGED
@@ -56,4 +56,9 @@ models:
|
|
56 |
- zai-org/GLM-4.5
|
57 |
- zai-org/GLM-4.5-Air
|
58 |
- zai-org/GLM-4.5V
|
|
|
|
|
|
|
|
|
|
|
59 |
---
|
|
|
56 |
- zai-org/GLM-4.5
|
57 |
- zai-org/GLM-4.5-Air
|
58 |
- zai-org/GLM-4.5V
|
59 |
+
- deepseek-ai/DeepSeek-V3.1
|
60 |
+
- deepseek-ai/DeepSeek-V3.1-Base
|
61 |
+
# Used to promote this Hugging Face Space
|
62 |
+
datasets:
|
63 |
+
- fka/awesome-chatgpt-prompts
|
64 |
---
|
assets/css/chat/markdown.css
CHANGED
@@ -159,6 +159,5 @@
|
|
159 |
}
|
160 |
|
161 |
.md-content table td pre, .md-content table th pre {
|
162 |
-
max-width: 480px;
|
163 |
overflow: auto;
|
164 |
}
|
|
|
159 |
}
|
160 |
|
161 |
.md-content table td pre, .md-content table th pre {
|
|
|
162 |
overflow: auto;
|
163 |
}
|
assets/plugins/loader.js
CHANGED
@@ -6,8 +6,10 @@
|
|
6 |
// Prism.
|
7 |
Prism.plugins.autoloader.languages_path = 'https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/';
|
8 |
|
9 |
-
// WebSocket.
|
10 |
-
|
|
|
|
|
11 |
|
12 |
// UI elements.
|
13 |
const chatArea = document.getElementById('chatArea');
|
@@ -24,9 +26,12 @@ const homeBtn = document.getElementById('homeBtn');
|
|
24 |
const clearBtn = document.getElementById('clearBtn');
|
25 |
|
26 |
// Track state.
|
|
|
27 |
let streamMsg = null;
|
28 |
let conversationHistory = [];
|
29 |
let currentAssistantText = "";
|
|
|
|
|
30 |
|
31 |
// Render markdown content.
|
32 |
function renderMarkdown(el) {
|
@@ -84,23 +89,23 @@ function leaveChatView() {
|
|
84 |
// Chat bubble.
|
85 |
function addMsg(who, text) {
|
86 |
const div = document.createElement('div');
|
87 |
-
div.className = 'bubble ' + (who==='user' ? 'bubble-user' : 'bubble-assist');
|
88 |
div.dataset.text = text;
|
89 |
renderMarkdown(div);
|
90 |
chatBox.appendChild(div);
|
91 |
-
chatBox.style.display='flex';
|
92 |
chatBox.scrollTop = chatBox.scrollHeight;
|
93 |
return div;
|
94 |
}
|
95 |
|
96 |
// Clear all chat.
|
97 |
function clearAllMessages() {
|
98 |
-
|
99 |
conversationHistory = [];
|
100 |
currentAssistantText = "";
|
101 |
-
if(streamMsg) {
|
102 |
const loadingEl = streamMsg.querySelector('.loading');
|
103 |
-
if(loadingEl) loadingEl.remove();
|
104 |
streamMsg = null;
|
105 |
}
|
106 |
chatBox.innerHTML = "";
|
@@ -111,57 +116,164 @@ function clearAllMessages() {
|
|
111 |
enterChatView();
|
112 |
}
|
113 |
|
114 |
-
//
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
socket.
|
120 |
-
|
121 |
-
|
122 |
-
|
|
|
123 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
}
|
125 |
|
126 |
-
//
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
// Send user message.
|
135 |
async function submitMessage() {
|
136 |
const message = input.value.trim();
|
137 |
-
if(!message) return;
|
138 |
enterChatView();
|
139 |
addMsg('user', message);
|
140 |
-
conversationHistory.push({role: 'user', content: message});
|
141 |
streamMsg = addMsg('assistant', '');
|
142 |
const loadingEl = document.createElement('span');
|
143 |
loadingEl.className = 'loading';
|
144 |
streamMsg.appendChild(loadingEl);
|
145 |
stopBtn.style.display = 'inline-flex';
|
146 |
btn.style.display = 'none';
|
147 |
-
input.value='';
|
148 |
btn.disabled = true;
|
|
|
|
|
|
|
|
|
|
|
149 |
try {
|
150 |
-
socket.send(JSON.stringify({
|
|
|
|
|
|
|
|
|
|
|
151 |
} catch (error) {
|
152 |
-
if(streamMsg){
|
153 |
const loadingEl = streamMsg.querySelector('.loading');
|
154 |
-
if(loadingEl) loadingEl.remove();
|
155 |
streamMsg.dataset.text = error.message || 'An error occurred during the request.';
|
156 |
renderMarkdown(streamMsg);
|
157 |
-
streamMsg.dataset.done='1';
|
158 |
-
streamMsg=null;
|
|
|
|
|
159 |
}
|
160 |
btn.style.display = 'inline-flex';
|
161 |
stopBtn.style.display = 'none';
|
162 |
}
|
163 |
}
|
164 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
// Submit.
|
166 |
form.addEventListener('submit', e => {
|
167 |
e.preventDefault();
|
@@ -171,7 +283,7 @@ form.addEventListener('submit', e => {
|
|
171 |
// Stop.
|
172 |
stopBtn.addEventListener('click', () => {
|
173 |
stopBtn.style.pointerEvents = 'none';
|
174 |
-
|
175 |
});
|
176 |
|
177 |
// Home.
|
@@ -184,49 +296,20 @@ clearBtn.addEventListener('click', () => {
|
|
184 |
clearAllMessages();
|
185 |
});
|
186 |
|
187 |
-
// Socket messages.
|
188 |
-
socket.onmessage = (e) => {
|
189 |
-
const data = JSON.parse(e.data);
|
190 |
-
if(data.type==='chunk') {
|
191 |
-
if(streamMsg) {
|
192 |
-
const loadingEl = streamMsg.querySelector('.loading');
|
193 |
-
if(loadingEl) loadingEl.remove();
|
194 |
-
streamMsg.dataset.text += data.chunk;
|
195 |
-
currentAssistantText = streamMsg.dataset.text ||"";
|
196 |
-
renderMarkdown(streamMsg);
|
197 |
-
chatBox.scrollTop = chatBox.scrollHeight;
|
198 |
-
}
|
199 |
-
} else if(data.type==='end' || data.type==='error') {
|
200 |
-
if(streamMsg){
|
201 |
-
const text = streamMsg.dataset.text || "";
|
202 |
-
const loadingEl = streamMsg.querySelector('.loading');
|
203 |
-
if(loadingEl) loadingEl.remove();
|
204 |
-
streamMsg.dataset.done='1';
|
205 |
-
if(data.type==='error') {
|
206 |
-
streamMsg.dataset.text = data.error || 'An error occurred during the request.';
|
207 |
-
renderMarkdown(streamMsg);
|
208 |
-
} else {
|
209 |
-
conversationHistory.push({role: 'assistant', content: text});
|
210 |
-
}
|
211 |
-
streamMsg = null;
|
212 |
-
}
|
213 |
-
btn.style.display = 'inline-flex';
|
214 |
-
stopBtn.style.display = 'none';
|
215 |
-
stopBtn.style.pointerEvents = 'auto';
|
216 |
-
}
|
217 |
-
};
|
218 |
-
|
219 |
// Enable send button only if input has text.
|
220 |
input.addEventListener('input', () => {
|
221 |
-
btn.disabled= input.value.trim() === '';
|
222 |
});
|
223 |
|
224 |
// Animations.
|
225 |
-
document.addEventListener('DOMContentLoaded', function() {
|
226 |
AOS.init({
|
227 |
duration: 800,
|
228 |
easing: 'ease-out-cubic',
|
229 |
once: true,
|
230 |
offset: 50
|
231 |
});
|
232 |
-
});
|
|
|
|
|
|
|
|
6 |
// Prism.
|
7 |
Prism.plugins.autoloader.languages_path = 'https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/';
|
8 |
|
9 |
+
// WebSocket URL helper.
|
10 |
+
function createWebSocket() {
|
11 |
+
return new WebSocket((window.location.protocol === "https:" ? "wss" : "ws") + "//" + window.location.host);
|
12 |
+
}
|
13 |
|
14 |
// UI elements.
|
15 |
const chatArea = document.getElementById('chatArea');
|
|
|
26 |
const clearBtn = document.getElementById('clearBtn');
|
27 |
|
28 |
// Track state.
|
29 |
+
let socket = null;
|
30 |
let streamMsg = null;
|
31 |
let conversationHistory = [];
|
32 |
let currentAssistantText = "";
|
33 |
+
let isRequestActive = false;
|
34 |
+
let abortController = null;
|
35 |
|
36 |
// Render markdown content.
|
37 |
function renderMarkdown(el) {
|
|
|
89 |
// Chat bubble.
|
90 |
function addMsg(who, text) {
|
91 |
const div = document.createElement('div');
|
92 |
+
div.className = 'bubble ' + (who === 'user' ? 'bubble-user' : 'bubble-assist');
|
93 |
div.dataset.text = text;
|
94 |
renderMarkdown(div);
|
95 |
chatBox.appendChild(div);
|
96 |
+
chatBox.style.display = 'flex';
|
97 |
chatBox.scrollTop = chatBox.scrollHeight;
|
98 |
return div;
|
99 |
}
|
100 |
|
101 |
// Clear all chat.
|
102 |
function clearAllMessages() {
|
103 |
+
stopStream(true);
|
104 |
conversationHistory = [];
|
105 |
currentAssistantText = "";
|
106 |
+
if (streamMsg) {
|
107 |
const loadingEl = streamMsg.querySelector('.loading');
|
108 |
+
if (loadingEl) loadingEl.remove();
|
109 |
streamMsg = null;
|
110 |
}
|
111 |
chatBox.innerHTML = "";
|
|
|
116 |
enterChatView();
|
117 |
}
|
118 |
|
119 |
+
// Reconnect WebSocket.
|
120 |
+
let reconnectAttempts = 0;
|
121 |
+
function setupWebSocket() {
|
122 |
+
if (socket) {
|
123 |
+
socket.onopen = null;
|
124 |
+
socket.onclose = null;
|
125 |
+
socket.onmessage = null;
|
126 |
+
socket.onerror = null;
|
127 |
+
socket.close();
|
128 |
+
socket = null;
|
129 |
}
|
130 |
+
|
131 |
+
socket = createWebSocket();
|
132 |
+
|
133 |
+
socket.onopen = () => {
|
134 |
+
reconnectAttempts = 0;
|
135 |
+
};
|
136 |
+
|
137 |
+
socket.onclose = () => {
|
138 |
+
reconnectAttempts++;
|
139 |
+
// Try reconnecting.
|
140 |
+
const delay = Math.min(30000, 1000 * Math.pow(2, reconnectAttempts)); // 30 seconds.
|
141 |
+
setTimeout(setupWebSocket, delay);
|
142 |
+
};
|
143 |
+
|
144 |
+
socket.onmessage = handleSocketMessage;
|
145 |
+
|
146 |
+
socket.onerror = () => {
|
147 |
+
socket.close();
|
148 |
+
};
|
149 |
}
|
150 |
|
151 |
+
// Handle incoming socket messages.
|
152 |
+
function handleSocketMessage(e) {
|
153 |
+
const data = JSON.parse(e.data);
|
154 |
+
if (data.type === 'chunk') {
|
155 |
+
if (streamMsg) {
|
156 |
+
const loadingEl = streamMsg.querySelector('.loading');
|
157 |
+
if (loadingEl) loadingEl.remove();
|
158 |
+
streamMsg.dataset.text += data.chunk;
|
159 |
+
currentAssistantText = streamMsg.dataset.text || "";
|
160 |
+
renderMarkdown(streamMsg);
|
161 |
+
chatBox.scrollTop = chatBox.scrollHeight;
|
162 |
+
}
|
163 |
+
} else if (data.type === 'end' || data.type === 'error') {
|
164 |
+
if (streamMsg) {
|
165 |
+
const loadingEl = streamMsg.querySelector('.loading');
|
166 |
+
if (loadingEl) loadingEl.remove();
|
167 |
+
streamMsg.dataset.done = '1';
|
168 |
+
if (data.type === 'error') {
|
169 |
+
streamMsg.dataset.text = data.error || 'An error occurred during the request.';
|
170 |
+
renderMarkdown(streamMsg);
|
171 |
+
} else {
|
172 |
+
conversationHistory.push({ role: 'assistant', content: streamMsg.dataset.text });
|
173 |
+
}
|
174 |
+
streamMsg = null;
|
175 |
+
isRequestActive = false;
|
176 |
+
abortController = null;
|
177 |
+
}
|
178 |
+
btn.style.display = 'inline-flex';
|
179 |
+
stopBtn.style.display = 'none';
|
180 |
+
stopBtn.style.pointerEvents = 'auto';
|
181 |
+
}
|
182 |
+
}
|
183 |
|
184 |
// Send user message.
|
185 |
async function submitMessage() {
|
186 |
const message = input.value.trim();
|
187 |
+
if (!message || isRequestActive) return;
|
188 |
enterChatView();
|
189 |
addMsg('user', message);
|
190 |
+
conversationHistory.push({ role: 'user', content: message });
|
191 |
streamMsg = addMsg('assistant', '');
|
192 |
const loadingEl = document.createElement('span');
|
193 |
loadingEl.className = 'loading';
|
194 |
streamMsg.appendChild(loadingEl);
|
195 |
stopBtn.style.display = 'inline-flex';
|
196 |
btn.style.display = 'none';
|
197 |
+
input.value = '';
|
198 |
btn.disabled = true;
|
199 |
+
|
200 |
+
isRequestActive = true;
|
201 |
+
|
202 |
+
// Stopping request.
|
203 |
+
abortController = new AbortController();
|
204 |
try {
|
205 |
+
socket.send(JSON.stringify({
|
206 |
+
type: 'ask',
|
207 |
+
message,
|
208 |
+
history: conversationHistory,
|
209 |
+
abortSignal: true
|
210 |
+
}));
|
211 |
} catch (error) {
|
212 |
+
if (streamMsg) {
|
213 |
const loadingEl = streamMsg.querySelector('.loading');
|
214 |
+
if (loadingEl) loadingEl.remove();
|
215 |
streamMsg.dataset.text = error.message || 'An error occurred during the request.';
|
216 |
renderMarkdown(streamMsg);
|
217 |
+
streamMsg.dataset.done = '1';
|
218 |
+
streamMsg = null;
|
219 |
+
isRequestActive = false;
|
220 |
+
abortController = null;
|
221 |
}
|
222 |
btn.style.display = 'inline-flex';
|
223 |
stopBtn.style.display = 'none';
|
224 |
}
|
225 |
}
|
226 |
|
227 |
+
// Stop streaming and cancel the ongoing request.
|
228 |
+
function stopStream(forceCancel = false) {
|
229 |
+
if (!isRequestActive) return;
|
230 |
+
|
231 |
+
isRequestActive = false;
|
232 |
+
|
233 |
+
if (abortController) {
|
234 |
+
abortController.abort();
|
235 |
+
abortController = null;
|
236 |
+
}
|
237 |
+
|
238 |
+
// Notify server to stop sending streams / processing.
|
239 |
+
try {
|
240 |
+
socket.send(JSON.stringify({ type: 'stop' }));
|
241 |
+
} catch {}
|
242 |
+
|
243 |
+
if (streamMsg && !forceCancel) {
|
244 |
+
const loadingEl = streamMsg.querySelector('.loading');
|
245 |
+
if (loadingEl) loadingEl.remove();
|
246 |
+
streamMsg.dataset.text += '';
|
247 |
+
renderMarkdown(streamMsg);
|
248 |
+
streamMsg.dataset.done = '1';
|
249 |
+
streamMsg = null;
|
250 |
+
}
|
251 |
+
|
252 |
+
stopBtn.style.display = 'none';
|
253 |
+
btn.style.display = 'inline-flex';
|
254 |
+
stopBtn.style.pointerEvents = 'auto';
|
255 |
+
}
|
256 |
+
|
257 |
+
// Wait for socket ready.
|
258 |
+
function sendWhenReady(msgFn) {
|
259 |
+
if (socket.readyState === WebSocket.OPEN) {
|
260 |
+
msgFn();
|
261 |
+
} else {
|
262 |
+
socket.addEventListener('open', function handler() {
|
263 |
+
msgFn();
|
264 |
+
socket.removeEventListener('open', handler);
|
265 |
+
});
|
266 |
+
}
|
267 |
+
}
|
268 |
+
|
269 |
+
// Prompts.
|
270 |
+
promptItems.forEach(p => {
|
271 |
+
p.addEventListener('click', () => {
|
272 |
+
input.value = p.dataset.prompt;
|
273 |
+
sendWhenReady(submitMessage);
|
274 |
+
});
|
275 |
+
});
|
276 |
+
|
277 |
// Submit.
|
278 |
form.addEventListener('submit', e => {
|
279 |
e.preventDefault();
|
|
|
283 |
// Stop.
|
284 |
stopBtn.addEventListener('click', () => {
|
285 |
stopBtn.style.pointerEvents = 'none';
|
286 |
+
stopStream();
|
287 |
});
|
288 |
|
289 |
// Home.
|
|
|
296 |
clearAllMessages();
|
297 |
});
|
298 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
299 |
// Enable send button only if input has text.
|
300 |
input.addEventListener('input', () => {
|
301 |
+
btn.disabled = input.value.trim() === '';
|
302 |
});
|
303 |
|
304 |
// Animations.
|
305 |
+
document.addEventListener('DOMContentLoaded', function () {
|
306 |
AOS.init({
|
307 |
duration: 800,
|
308 |
easing: 'ease-out-cubic',
|
309 |
once: true,
|
310 |
offset: 50
|
311 |
});
|
312 |
+
});
|
313 |
+
|
314 |
+
// Initialize WebSocket connection.
|
315 |
+
setupWebSocket();
|
package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
{
|
2 |
"name": "UltimaX Intelligence",
|
3 |
-
"version": "0.0.
|
4 |
"type": "module",
|
5 |
"main": "mapping.js",
|
6 |
"scripts": {
|
|
|
1 |
{
|
2 |
"name": "UltimaX Intelligence",
|
3 |
+
"version": "0.0.4",
|
4 |
"type": "module",
|
5 |
"main": "mapping.js",
|
6 |
"scripts": {
|