Skip to content

Commit ef8268f

Browse files
authored
fix(ui): render thinking/reasoning block content as markdown (ggml-org#24611)
* fix(ui): render thinking/reasoning block content as markdown * feat(ui): add toggle setting for thinking block markdown rendering
1 parent 5f04dc7 commit ef8268f

3 files changed

Lines changed: 28 additions & 6 deletions

File tree

tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessageAgenticContent.svelte

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
5757
const showToolCallInProgress = $derived(config().showToolCallInProgress as boolean);
5858
const showThoughtInProgress = $derived(config().showThoughtInProgress as boolean);
59+
const renderThinkingAsMarkdown = $derived(config().renderThinkingAsMarkdown as boolean);
5960
6061
const hasReasoningError = $derived(
6162
isLastAssistantMessage ? !!agenticLastError(message.convId) : false
@@ -316,9 +317,13 @@
316317
onToggle={() => toggleExpanded(index, section)}
317318
>
318319
<div class="pt-3">
319-
<div class="text-xs leading-relaxed break-words whitespace-pre-wrap">
320-
{section.content}
321-
</div>
320+
{#if renderThinkingAsMarkdown}
321+
<MarkdownContent content={section.content} attachments={message?.extra} />
322+
{:else}
323+
<div class="text-xs leading-relaxed break-words whitespace-pre-wrap">
324+
{section.content}
325+
</div>
326+
{/if}
322327
</div>
323328
</CollapsibleContentBlock>
324329
{:else if section.type === AgenticSectionType.REASONING_PENDING}
@@ -336,9 +341,13 @@
336341
onToggle={() => toggleExpanded(index, section)}
337342
>
338343
<div class="pt-3">
339-
<div class="text-xs leading-relaxed break-words whitespace-pre-wrap">
340-
{section.content}
341-
</div>
344+
{#if renderThinkingAsMarkdown}
345+
<MarkdownContent content={section.content} attachments={message?.extra} />
346+
{:else}
347+
<div class="text-xs leading-relaxed break-words whitespace-pre-wrap">
348+
{section.content}
349+
</div>
350+
{/if}
342351
</div>
343352
</CollapsibleContentBlock>
344353
{/if}

tools/ui/src/lib/constants/settings-keys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const SETTINGS_KEYS = {
3333
SHOW_MODEL_TAGS: 'showModelTags',
3434
SHOW_BUILD_VERSION: 'showBuildVersion',
3535
SHOW_SYSTEM_MESSAGE: 'showSystemMessage',
36+
RENDER_THINKING_AS_MARKDOWN: 'renderThinkingAsMarkdown',
3637
// Sampling
3738
TEMPERATURE: 'temperature',
3839
DYNATEMP_RANGE: 'dynatemp_range',

tools/ui/src/lib/constants/settings-registry.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,18 @@ const SETTINGS_REGISTRY: Record<string, SettingsSectionEntry> = {
282282
paramType: SyncableParameterType.BOOLEAN
283283
}
284284
},
285+
{
286+
key: SETTINGS_KEYS.RENDER_THINKING_AS_MARKDOWN,
287+
label: 'Render thinking as Markdown',
288+
help: 'Render the reasoning/thinking block content as formatted Markdown instead of plain text.',
289+
defaultValue: true,
290+
type: SettingsFieldType.CHECKBOX,
291+
section: SETTINGS_SECTION_SLUGS.DISPLAY,
292+
sync: {
293+
serverKey: SETTINGS_KEYS.RENDER_THINKING_AS_MARKDOWN,
294+
paramType: SyncableParameterType.BOOLEAN
295+
}
296+
},
285297
{
286298
key: SETTINGS_KEYS.FULL_HEIGHT_CODE_BLOCKS,
287299
label: 'Use full height code blocks',

0 commit comments

Comments
 (0)