From 4c5e444bcb4149cd3e3e1ec8fcbc59edcced6295 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Sun, 16 Feb 2025 05:14:40 +0000 Subject: [PATCH] Improve token streaming support with character-by-character matching Co-Authored-By: Jack Hacksman --- .../contrib/chat/common/chatModel.ts | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/vs/workbench/contrib/chat/common/chatModel.ts b/src/vs/workbench/contrib/chat/common/chatModel.ts index 98519d4f..81b0c970 100644 --- a/src/vs/workbench/contrib/chat/common/chatModel.ts +++ b/src/vs/workbench/contrib/chat/common/chatModel.ts @@ -396,14 +396,27 @@ class ThinkTagSurroundingsRemover extends SurroundingsRemover { } removeThinkTags() { - // Handle token streaming character by character - const chars = ['<', 't', 'h', 'i', 'n', 'k', '>']; - let foundTag = true; + // Handle token streaming at a more granular level + let foundTag = false; - for (const char of chars) { - if (!this.removePrefix(char)) { - foundTag = false; - break; + // Try to remove opening tag, handling partial tokens + foundTag = this.removePrefix('<'); + if (foundTag) { + foundTag = this.removePrefix('t'); + if (foundTag) { + foundTag = this.removePrefix('h'); + if (foundTag) { + foundTag = this.removePrefix('i'); + if (foundTag) { + foundTag = this.removePrefix('n'); + if (foundTag) { + foundTag = this.removePrefix('k'); + if (foundTag) { + foundTag = this.removePrefix('>'); + } + } + } + } } } @@ -411,7 +424,10 @@ class ThinkTagSurroundingsRemover extends SurroundingsRemover { } deltaInfo(recentlyAddedTextLen: number) { + // Get the delta and suffix from parent class const [delta, ignoredSuffix] = super.deltaInfo(recentlyAddedTextLen); + + // Strip any think tags from the delta before returning return [stripThinkTags(delta), ignoredSuffix] as const; } }