This commit is contained in:
Dallin Romney 2025-03-26 17:11:19 -07:00
parent da4a71c12c
commit c12bc10b8d
5 changed files with 41 additions and 28 deletions

View file

@ -30,15 +30,17 @@ class Anthropic extends BaseLLM {
description: tool.function.description,
input_schema: tool.function.parameters,
})),
thinking: options.reasoning ? {
type: "enabled",
budget_tokens: options.reasoningBudgetTokens,
} : undefined,
thinking: options.reasoning
? {
type: "enabled",
budget_tokens: options.reasoningBudgetTokens,
}
: undefined,
tool_choice: options.toolChoice
? {
type: "tool",
name: options.toolChoice.function.name,
}
type: "tool",
name: options.toolChoice.function.name,
}
: undefined,
};
@ -70,19 +72,23 @@ class Anthropic extends BaseLLM {
} else if (message.role === "thinking" && !message.redactedThinking) {
return {
role: "assistant",
content: [{
type: "thinking",
thinking: message.content,
signature: message.signature
}]
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
}]
content: [
{
type: "redacted_thinking",
data: message.redactedThinking,
},
],
};
}
@ -195,12 +201,12 @@ class Anthropic extends BaseLLM {
messages: msgs,
system: shouldCacheSystemMessage
? [
{
type: "text",
text: this.systemMessage,
cache_control: { type: "ephemeral" },
},
]
{
type: "text",
text: this.systemMessage,
cache_control: { type: "ephemeral" },
},
]
: systemMessage,
}),
signal,
@ -240,7 +246,11 @@ class Anthropic extends BaseLLM {
// 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 };
yield {
role: "thinking",
content: "",
redactedThinking: value.content_block.data,
};
}
break;
case "content_block_delta":
@ -253,7 +263,11 @@ class Anthropic extends BaseLLM {
yield { role: "thinking", content: value.delta.thinking };
break;
case "signature_delta":
yield { role: "thinking", content: "", signature: value.delta.signature };
yield {
role: "thinking",
content: "",
signature: value.delta.signature,
};
break;
case "input_json_delta":
if (!lastToolUseId || !lastToolUseName) {

View file

@ -6,7 +6,7 @@ export const readCurrentlyOpenFileTool: Tool = {
displayTitle: "Read Currently Open File",
wouldLikeTo: "read the current file",
isCurrently: "reading the current file",
hasAlready: "read the current file",
hasAlready: "viewed the current file",
readonly: true,
group: BUILT_IN_GROUP_NAME,
function: {

View file

@ -6,7 +6,7 @@ export const readFileTool: Tool = {
displayTitle: "Read File",
wouldLikeTo: "read {{{ filepath }}}",
isCurrently: "reading {{{ filepath }}}",
hasAlready: "read {{{ filepath }}}",
hasAlready: "viewed {{{ filepath }}}",
readonly: true,
group: BUILT_IN_GROUP_NAME,
function: {

View file

@ -54,7 +54,7 @@ export function ToolCallDisplay(props: ToolCallDisplayProps) {
Mustache.render(tool.isCurrently, props.toolCallState.parsedArgs)
) : (
<>
<span>using the</span> {defaultToolDescription}
<span>calling the</span> {defaultToolDescription}
</>
);
} else if (props.toolCallState.status === "done") {

View file

@ -175,7 +175,6 @@ export class AnthropicApi implements BaseLlmApi {
body: ChatCompletionCreateParamsStreaming,
signal: AbortSignal,
): AsyncGenerator<ChatCompletionChunk, any, unknown> {
body.messages;
const response = await customFetch(this.config.requestOptions)(
new URL("messages", this.apiBase),
{