Skip to content

Commit ab62480

Browse files
committed
webui : put DeepSeek R1 CoT in a collapsible <details> element
1 parent 16d3df7 commit ab62480

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

examples/server/public/index.html.gz

5.17 KB
Binary file not shown.

examples/server/webui/index.html

+4
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ <h3 class="text-lg font-bold mb-6">Settings</h3>
261261
<span v-if="msg.content === null" class="loading loading-dots loading-md"></span>
262262
<!-- render message as markdown -->
263263
<div v-else dir="auto">
264+
<details v-if="msg.role === 'assistant' && msg.cot" class="collapse bg-base-200" :open="isGenerating">
265+
<summary class="collapse-title">Reasoning</summary>
266+
<vue-markdown :source="msg.cot" dir="auto" class="collapse-content"></vue-markdown>
267+
</details>
264268
<vue-markdown :source="msg.content"></vue-markdown>
265269
</div>
266270
<!-- render timings if enabled -->

examples/server/webui/src/main.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -468,14 +468,22 @@ const mainApp = createApp({
468468
for await (const chunk of chunks) {
469469
const stop = chunk.stop;
470470
const addedContent = chunk.choices[0].delta.content;
471-
const lastContent = this.pendingMsg.content || '';
471+
const lastContent = this.pendingMsg.fullContent || '';
472472
if (addedContent) {
473473
this.pendingMsg = {
474474
id: this.pendingMsg.id,
475475
role: 'assistant',
476-
content: lastContent + addedContent,
476+
fullContent: lastContent + addedContent,
477477
};
478478
}
479+
const regex = /<think>(.*?)?(?=(<\/think>)|$)/gis;
480+
const matches = [];
481+
let match;
482+
while ((match = regex.exec(this.pendingMsg.fullContent)) !== null) {
483+
matches.push(match[1]);
484+
}
485+
this.pendingMsg.content = this.pendingMsg.fullContent.replace(/<think>.*?(<\/think>|$)/gis, '');
486+
this.pendingMsg.cot = matches.join('<br/>');
479487
const timings = chunk.timings;
480488
if (timings && this.config.showTokensPerSecond) {
481489
// only extract what's really needed, to save some space

0 commit comments

Comments
 (0)