Adding thinking blocks and handle redacted_thinking
This commit is contained in:
parent
8c330cb23f
commit
a15d1165c9
5 changed files with 52 additions and 2 deletions
2
core/index.d.ts
vendored
2
core/index.d.ts
vendored
|
|
@ -356,6 +356,8 @@ export interface UserChatMessage {
|
|||
export interface ThinkingChatMessage {
|
||||
role: "thinking";
|
||||
content: MessageContent;
|
||||
signature?: string;
|
||||
redactedThinking?: string;
|
||||
toolCalls?: ToolCallDelta[];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -819,6 +819,7 @@ export abstract class BaseLLM implements ILLM {
|
|||
|
||||
if (chunk.role === "thinking") {
|
||||
thinking += chunk.content;
|
||||
yield chunk;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,23 @@ class Anthropic extends BaseLLM {
|
|||
input: JSON.parse(toolCall.function?.arguments || "{}"),
|
||||
})),
|
||||
};
|
||||
} else if (message.role === "thinking" && !message.redactedThinking) {
|
||||
return {
|
||||
role: "assistant",
|
||||
content: [{
|
||||
type: "thinking",
|
||||
thinking: message.content,
|
||||
signature: message.signature
|
||||
}]
|
||||
};
|
||||
} else if (message.role === "thinking" && message.redactedThinking) {
|
||||
return {
|
||||
role: "assistant",
|
||||
content: [{
|
||||
type: "redacted_thinking",
|
||||
data: message.redactedThinking
|
||||
}]
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof message.content === "string") {
|
||||
|
|
@ -216,6 +233,11 @@ class Anthropic extends BaseLLM {
|
|||
lastToolUseId = value.content_block.id;
|
||||
lastToolUseName = value.content_block.name;
|
||||
}
|
||||
// handle redacted thinking
|
||||
if (value.content_block.type === "redacted_thinking") {
|
||||
console.log("redacted thinking", value.content_block.data);
|
||||
yield { role: "thinking", content: "", redactedThinking: value.content_block.data };
|
||||
}
|
||||
break;
|
||||
case "content_block_delta":
|
||||
// https://docs.anthropic.com/en/api/messages-streaming#delta-types
|
||||
|
|
@ -226,6 +248,9 @@ class Anthropic extends BaseLLM {
|
|||
case "thinking_delta":
|
||||
yield { role: "thinking", content: value.delta.thinking };
|
||||
break;
|
||||
case "signature_delta":
|
||||
yield { role: "thinking", content: "", signature: value.delta.signature };
|
||||
break;
|
||||
case "input_json_delta":
|
||||
if (!lastToolUseId || !lastToolUseName) {
|
||||
throw new Error("No tool use found");
|
||||
|
|
|
|||
4
extensions/vscode/package-lock.json
generated
4
extensions/vscode/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "continue",
|
||||
"version": "1.1.2",
|
||||
"version": "1.1.3",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "continue",
|
||||
"version": "1.1.2",
|
||||
"version": "1.1.3",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@continuedev/fetch": "^1.0.3",
|
||||
|
|
|
|||
|
|
@ -294,6 +294,7 @@ export const sessionSlice = createSlice({
|
|||
state.streamAborter = new AbortController();
|
||||
},
|
||||
streamUpdate: (state, action: PayloadAction<ChatMessage[]>) => {
|
||||
|
||||
if (state.history.length) {
|
||||
function toolCallDeltaToState(
|
||||
toolCallDelta: ToolCallDelta,
|
||||
|
|
@ -319,6 +320,22 @@ export const sessionSlice = createSlice({
|
|||
for (const message of action.payload) {
|
||||
const lastItem = state.history[state.history.length - 1];
|
||||
const lastMessage = lastItem.message;
|
||||
|
||||
if (message.role === "thinking" && message.redactedThinking) {
|
||||
console.log("add redacted_thinking blocks");
|
||||
|
||||
state.history.push({
|
||||
message: {
|
||||
role: "thinking",
|
||||
content: "internal reasoning is hidden due to safety reasons",
|
||||
redactedThinking: message.redactedThinking,
|
||||
id: uuidv4(),
|
||||
},
|
||||
contextItems: [],
|
||||
})
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
lastMessage.role !== message.role ||
|
||||
// This is for when a tool call comes immediately before/after tool call
|
||||
|
|
@ -382,6 +399,11 @@ export const sessionSlice = createSlice({
|
|||
// was already rendered from parts to string
|
||||
lastMessage.content += messageContent;
|
||||
}
|
||||
} else if (message.role === "thinking" && message.signature) {
|
||||
if (lastMessage.role === "thinking") {
|
||||
console.log("add signature", message.signature);
|
||||
lastMessage.signature = message.signature;
|
||||
}
|
||||
} else if (
|
||||
message.role === "assistant" &&
|
||||
message.toolCalls?.[0] &&
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue