feat: support for <think></think> tags to allow reasoning tokens formatted in UI (#1205)
Some checks are pending
Docker Publish / docker-build-publish (push) Waiting to run
Update Stable Branch / prepare-release (push) Waiting to run

This commit is contained in:
Anirban Kar 2025-01-29 02:33:53 +05:30 committed by GitHub
parent 32bfdd9c24
commit a199295ad8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -54,8 +54,28 @@ export const allowedHTMLElements = [
'tr',
'ul',
'var',
'think',
];
// Add custom rehype plugin
function remarkThinkRawContent() {
return (tree: any) => {
visit(tree, (node: any) => {
if (node.type === 'html' && node.value && node.value.startsWith('<think>')) {
const cleanedContent = node.value.slice(7);
node.value = `<div class="__boltThought__">${cleanedContent}`;
return;
}
if (node.type === 'html' && node.value && node.value.startsWith('</think>')) {
const cleanedContent = node.value.slice(8);
node.value = `</div>${cleanedContent}`;
}
});
};
}
const rehypeSanitizeOptions: RehypeSanitizeOptions = {
...defaultSchema,
tagNames: allowedHTMLElements,
@ -79,6 +99,8 @@ export function remarkPlugins(limitedMarkdown: boolean) {
plugins.unshift(limitedMarkdownPlugin);
}
plugins.unshift(remarkThinkRawContent);
return plugins;
}