3.7 sonnet thinking tag

added  start and end tag to thinking and allowed redacted_thinking as a response.
This commit is contained in:
richardclim 2025-02-26 17:30:12 -05:00
parent 71d9235cac
commit 330687d647

View File

@ -205,6 +205,7 @@ export class ClaudeApi implements LLMApi {
const controller = new AbortController(); const controller = new AbortController();
options.onController?.(controller); options.onController?.(controller);
let inThinkingBlock = false;
if (shouldStream) { if (shouldStream) {
let index = -1; let index = -1;
@ -234,17 +235,20 @@ export class ClaudeApi implements LLMApi {
let chunkJson: let chunkJson:
| undefined | undefined
| { | {
type: "content_block_delta" | "content_block_stop"; type: "content_block_delta" | "content_block_stop" | "content_block_start";
content_block?: { content_block?: {
type: "tool_use"; type: "tool_use" | "thinking" | "text" | "redacted_thinking";
id: string; id: string;
name: string; name: string;
thinking?: string;
data?: string;
}; };
delta?: { delta?: {
type: "text_delta" | "input_json_delta" | "thinking_delta"; type: "text_delta" | "input_json_delta" | "thinking_delta" | "signature_delta";
text?: string; text?: string;
partial_json?: string; partial_json?: string;
thinking?: string; thinking?: string;
signature?: string;
}; };
index: number; index: number;
}; };
@ -271,8 +275,19 @@ export class ClaudeApi implements LLMApi {
runTools[index]["function"]["arguments"] += runTools[index]["function"]["arguments"] +=
chunkJson?.delta?.partial_json; 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) { 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; return chunkJson?.delta?.text;
}, },