mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
Improve token streaming support for think tags
Co-Authored-By: Jack Hacksman <slack@hannis.io>
This commit is contained in:
parent
a519bd7690
commit
b24cd1ecb7
2 changed files with 22 additions and 11 deletions
|
|
@ -409,16 +409,15 @@ class ThinkTagSurroundingsRemover extends SurroundingsRemover {
|
|||
}
|
||||
|
||||
removeThinkTags() {
|
||||
const foundTag = this.removePrefix('<think>');
|
||||
if (!foundTag) {
|
||||
// Handle partial tags during streaming
|
||||
if (this.originalS.startsWith('<thi', this.i)) {
|
||||
this.i += 4;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
// Try to remove opening tag, handling partial tokens during streaming
|
||||
const foundOpenTag = this.removePrefix('<think>');
|
||||
if (!foundOpenTag) {
|
||||
// Let removePrefix handle partial matches character by character
|
||||
this.removePrefix('<');
|
||||
this.removePrefix('think');
|
||||
this.removePrefix('>');
|
||||
}
|
||||
return true;
|
||||
return foundOpenTag;
|
||||
}
|
||||
|
||||
deltaInfo(recentlyAddedTextLen: number) {
|
||||
|
|
|
|||
|
|
@ -8,8 +8,20 @@ import { Response, stripThinkTags } from '../../../common/chatModel';
|
|||
import { MarkdownString } from '../../../../../../base/common/htmlContent';
|
||||
|
||||
suite('ChatModel - Think Tags', () => {
|
||||
test('handles partial tags during streaming', () => {
|
||||
const response = new Response(new MarkdownString('<thi'));
|
||||
test('handles partial tokens during streaming', () => {
|
||||
const response = new Response(new MarkdownString('<'));
|
||||
assert.strictEqual(response.toString(), '');
|
||||
|
||||
response.updateContent({ kind: 'markdownContent', content: new MarkdownString('<t') });
|
||||
assert.strictEqual(response.toString(), '');
|
||||
|
||||
response.updateContent({ kind: 'markdownContent', content: new MarkdownString('<thi') });
|
||||
assert.strictEqual(response.toString(), '');
|
||||
|
||||
response.updateContent({ kind: 'markdownContent', content: new MarkdownString('<think') });
|
||||
assert.strictEqual(response.toString(), '');
|
||||
|
||||
response.updateContent({ kind: 'markdownContent', content: new MarkdownString('<think>') });
|
||||
assert.strictEqual(response.toString(), '');
|
||||
|
||||
response.updateContent({ kind: 'markdownContent', content: new MarkdownString('<think>test') });
|
||||
|
|
|
|||
Loading…
Reference in a new issue