From 330687d647172d82af6a0b31041cd635e88b04fc Mon Sep 17 00:00:00 2001 From: richardclim <61879224+richardclim@users.noreply.github.com> Date: Wed, 26 Feb 2025 17:30:12 -0500 Subject: [PATCH] 3.7 sonnet thinking tag added start and end tag to thinking and allowed redacted_thinking as a response. --- app/client/platforms/anthropic.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/app/client/platforms/anthropic.ts b/app/client/platforms/anthropic.ts index 9a59905d1..b2582bd3a 100644 --- a/app/client/platforms/anthropic.ts +++ b/app/client/platforms/anthropic.ts @@ -205,6 +205,7 @@ export class ClaudeApi implements LLMApi { const controller = new AbortController(); options.onController?.(controller); + let inThinkingBlock = false; if (shouldStream) { let index = -1; @@ -234,17 +235,20 @@ export class ClaudeApi implements LLMApi { let chunkJson: | undefined | { - type: "content_block_delta" | "content_block_stop"; + type: "content_block_delta" | "content_block_stop" | "content_block_start"; content_block?: { - type: "tool_use"; + type: "tool_use" | "thinking" | "text" | "redacted_thinking"; id: string; name: string; + thinking?: string; + data?: string; }; delta?: { - type: "text_delta" | "input_json_delta" | "thinking_delta"; + type: "text_delta" | "input_json_delta" | "thinking_delta" | "signature_delta"; text?: string; partial_json?: string; thinking?: string; + signature?: string; }; index: number; }; @@ -271,8 +275,19 @@ export class ClaudeApi implements LLMApi { runTools[index]["function"]["arguments"] += chunkJson?.delta?.partial_json; } + if (chunkJson?.type === "content_block_start" && chunkJson?.content_block?.type === "thinking") { + inThinkingBlock = true; + return "🧠"; + } if (chunkJson?.delta?.type === "thinking_delta" && chunkJson?.delta?.thinking) { - return `🧠 ${chunkJson.delta.thinking}`; + return `${chunkJson.delta.thinking}`; + } + if (chunkJson?.type === "content_block_stop" && inThinkingBlock) { + return "🧠"; + inThinkingBlock = false; + } + if (chunkJson?.content_block?.type === "redacted_thinking") { + return `${chunkJson.content_block.data}`; } return chunkJson?.delta?.text; },