From d7db93ead179c61475dd4aa1a1dbb58616daa72f Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Sat, 21 Dec 2024 21:16:31 -0800 Subject: [PATCH] Use more flexible empty code block match to fix gemini bug --- src/core/Cline.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/core/Cline.ts b/src/core/Cline.ts index 5f3f3d8dc5..dc41a7e973 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -936,10 +936,12 @@ export class Cline { } if (!block.partial) { - // gemini models add this artifact to the end of text content: - const TOOL_CODE_SUFFIX = "```tool_code" - if (content?.trimEnd().endsWith(TOOL_CODE_SUFFIX)) { - content = content.trimEnd().slice(0, -TOOL_CODE_SUFFIX.length) + // Some models add code block artifacts (around the tool calls) which show up at the end of text content + // matches ``` with atleast one char after the last backtick, at the end of the string + const match = content?.trimEnd().match(/```[a-zA-Z0-9_-]+$/) + if (match) { + const matchLength = match[0].length + content = content.trimEnd().slice(0, -matchLength) } }