diff --git a/core/util/index.test.ts b/core/util/index.test.ts
index fc48a49b2..a77473c25 100644
--- a/core/util/index.test.ts
+++ b/core/util/index.test.ts
@@ -1,9 +1,9 @@
// File generated by Continue
import {
+ copyOf,
dedent,
dedentAndGetCommonWhitespace,
deduplicateArray,
- copyOf,
getMarkdownLanguageTagForFile,
removeCodeBlocksAndTrim,
removeQuotesAndEscapes,
@@ -463,4 +463,30 @@ describe("removeCodeBlocksAndTrim", () => {
const output = removeCodeBlocksAndTrim(text);
expect(output).toBe("");
});
+ it("should remove think blocks from text", () => {
+ const text =
+ "Okay, the user wants me to help with...Here is my actual response.";
+ const output = removeCodeBlocksAndTrim(text);
+ expect(output).toBe("Here is my actual response.");
+ });
+
+ it("should remove both code blocks and think blocks", () => {
+ const text =
+ "Let me plan this...Here's some code:\n```javascript\nconsole.log('hello');\n```\nThat should work!";
+ const output = removeCodeBlocksAndTrim(text);
+ expect(output).toBe("Here's some code:\n\nThat should work!");
+ });
+
+ it("should handle multiple think blocks", () => {
+ const text =
+ "First thoughtSome textSecond thoughtMore text";
+ const output = removeCodeBlocksAndTrim(text);
+ expect(output).toBe("Some textMore text");
+ });
+
+ it("should handle think blocks with newlines", () => {
+ const text = "\nMultiline\nthinking\n\nActual response";
+ const output = removeCodeBlocksAndTrim(text);
+ expect(output).toBe("Actual response");
+ });
});
diff --git a/core/util/index.ts b/core/util/index.ts
index 4b3b17535..76b319bdd 100644
--- a/core/util/index.ts
+++ b/core/util/index.ts
@@ -197,11 +197,13 @@ export function dedent(strings: TemplateStringsArray, ...values: any[]) {
*/
export function removeCodeBlocksAndTrim(text: string): string {
const codeBlockRegex = /```[\s\S]*?```/g;
+ const thinkBlockRegex = /[\s\S]*?<\/think>/g;
- // Remove code blocks from the message text
- const textWithoutCodeBlocks = text.replace(codeBlockRegex, "");
+ // Remove code blocks and think blocks from the message text
+ let processedText = text.replace(codeBlockRegex, "");
+ processedText = processedText.replace(thinkBlockRegex, "");
- return textWithoutCodeBlocks.trim();
+ return processedText.trim();
}
export function splitCamelCaseAndNonAlphaNumeric(value: string) {