diff --git a/core/package-lock.json b/core/package-lock.json index 3a3f77c43..41aeca5cb 100644 --- a/core/package-lock.json +++ b/core/package-lock.json @@ -27,7 +27,7 @@ "comment-json": "^4.2.3", "dbinfoz": "^0.14.0", "diff": "^7.0.0", - "dotenv": "^16.4.7", + "dotenv": "^16.4.5", "fastest-levenshtein": "^1.0.16", "follow-redirects": "^1.15.5", "google-auth-library": "^9.14.2", diff --git a/core/util/chatDescriber.ts b/core/util/chatDescriber.ts index e44ec85a0..d4c7413ae 100644 --- a/core/util/chatDescriber.ts +++ b/core/util/chatDescriber.ts @@ -1,10 +1,9 @@ import { ILLM, LLMFullCompletionOptions } from ".."; -import { removeQuotesAndEscapes } from "."; +import { removeQuotesAndEscapes, removeCodeBlocksAndTrim } from "."; import type { FromCoreProtocol, ToCoreProtocol } from "../protocol"; import type { IMessenger } from "./messenger"; -import { removeCodeBlocksAndTrim } from "./markdown"; export class ChatDescriber { static prompt: string | undefined = diff --git a/core/util/index.ts b/core/util/index.ts index 7f46278f9..9a896baff 100644 --- a/core/util/index.ts +++ b/core/util/index.ts @@ -328,3 +328,17 @@ export function dedent(strings: TemplateStringsArray, ...values: any[]) { return lines.join("\n"); } + +/** + * Removes code blocks from a message. + * + * Return modified message text. + */ +export function removeCodeBlocksAndTrim(text: string): string { + const codeBlockRegex = /```[\s\S]*?```/g; + + // Remove code blocks from the message text + const textWithoutCodeBlocks = text.replace(codeBlockRegex, ""); + + return textWithoutCodeBlocks.trim(); +} diff --git a/core/util/tts.ts b/core/util/tts.ts index bf62c6e29..1fd41607c 100644 --- a/core/util/tts.ts +++ b/core/util/tts.ts @@ -1,7 +1,7 @@ import { exec, ChildProcess } from "child_process"; import os from "node:os"; -import { removeCodeBlocksAndTrim } from "./markdown"; +import { removeCodeBlocksAndTrim } from "."; import type { IMessenger } from "./messenger"; import type { FromCoreProtocol, ToCoreProtocol } from "../protocol";