Spaces:
Runtime error
Runtime error
mac commited on
Commit ·
af35738
1
Parent(s): 491cbd7
update rewritten ui: flagging think or nothink
Browse files- index.html +14 -8
index.html
CHANGED
|
@@ -344,15 +344,20 @@
|
|
| 344 |
}
|
| 345 |
}
|
| 346 |
|
| 347 |
-
function splitThinking(fullText) {
|
| 348 |
-
const text = fullText.replace('<think>', '');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
const pos = text.indexOf(THINK_CLOSE);
|
| 350 |
if (pos === -1) {
|
| 351 |
return { thinking: text.trim(), answer: '' };
|
| 352 |
}
|
| 353 |
return {
|
| 354 |
thinking: text.slice(0, pos).trim(),
|
| 355 |
-
answer: text.slice(pos + THINK_CLOSE.length).
|
| 356 |
};
|
| 357 |
}
|
| 358 |
|
|
@@ -379,7 +384,8 @@
|
|
| 379 |
function updateBotMessage(div, fullText) {
|
| 380 |
const thinkingContainer = div.querySelector('.thinking-container');
|
| 381 |
const contentContainer = div.querySelector('.content-container');
|
| 382 |
-
const
|
|
|
|
| 383 |
|
| 384 |
if (thinking) {
|
| 385 |
thinkingContainer.classList.remove('hidden');
|
|
@@ -391,16 +397,16 @@
|
|
| 391 |
|
| 392 |
if (answer) {
|
| 393 |
contentContainer.innerHTML = marked.parse(answer);
|
| 394 |
-
} else if (
|
| 395 |
-
contentContainer.innerHTML = marked.parse(fullText.replace('<|im_end|>', ''));
|
| 396 |
-
} else {
|
| 397 |
contentContainer.innerHTML = '<div class="flex gap-1.5 py-1"><div class="typing-dot"></div><div class="typing-dot"></div><div class="typing-dot"></div></div>';
|
|
|
|
|
|
|
| 398 |
}
|
| 399 |
|
| 400 |
renderMath(thinkingContainer);
|
| 401 |
renderMath(contentContainer);
|
| 402 |
chatScrollArea.scrollTo({ top: chatScrollArea.scrollHeight, behavior: 'smooth' });
|
| 403 |
-
return answer
|
| 404 |
}
|
| 405 |
|
| 406 |
async function sendMessage() {
|
|
|
|
| 344 |
}
|
| 345 |
}
|
| 346 |
|
| 347 |
+
function splitThinking(fullText, thinkingEnabled) {
|
| 348 |
+
const text = fullText.replace('<think>', '').replace('<|im_end|>', '');
|
| 349 |
+
|
| 350 |
+
if (!thinkingEnabled) {
|
| 351 |
+
return { thinking: '', answer: text.trim() };
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
const pos = text.indexOf(THINK_CLOSE);
|
| 355 |
if (pos === -1) {
|
| 356 |
return { thinking: text.trim(), answer: '' };
|
| 357 |
}
|
| 358 |
return {
|
| 359 |
thinking: text.slice(0, pos).trim(),
|
| 360 |
+
answer: text.slice(pos + THINK_CLOSE.length).trim()
|
| 361 |
};
|
| 362 |
}
|
| 363 |
|
|
|
|
| 384 |
function updateBotMessage(div, fullText) {
|
| 385 |
const thinkingContainer = div.querySelector('.thinking-container');
|
| 386 |
const contentContainer = div.querySelector('.content-container');
|
| 387 |
+
const thinkingEnabled = thinkingToggle.classList.contains('active');
|
| 388 |
+
const { thinking, answer } = splitThinking(fullText, thinkingEnabled);
|
| 389 |
|
| 390 |
if (thinking) {
|
| 391 |
thinkingContainer.classList.remove('hidden');
|
|
|
|
| 397 |
|
| 398 |
if (answer) {
|
| 399 |
contentContainer.innerHTML = marked.parse(answer);
|
| 400 |
+
} else if (thinkingEnabled && thinking) {
|
|
|
|
|
|
|
| 401 |
contentContainer.innerHTML = '<div class="flex gap-1.5 py-1"><div class="typing-dot"></div><div class="typing-dot"></div><div class="typing-dot"></div></div>';
|
| 402 |
+
} else {
|
| 403 |
+
contentContainer.innerHTML = '';
|
| 404 |
}
|
| 405 |
|
| 406 |
renderMath(thinkingContainer);
|
| 407 |
renderMath(contentContainer);
|
| 408 |
chatScrollArea.scrollTo({ top: chatScrollArea.scrollHeight, behavior: 'smooth' });
|
| 409 |
+
return answer;
|
| 410 |
}
|
| 411 |
|
| 412 |
async function sendMessage() {
|