cleanup
This commit is contained in:
parent
debeca96d2
commit
52ef5777d7
3 changed files with 33 additions and 57 deletions
|
|
@ -195,11 +195,11 @@ export abstract class BaseLLM implements ILLM {
|
|||
options.completionOptions?.maxTokens ??
|
||||
(llmInfo?.maxCompletionTokens
|
||||
? Math.min(
|
||||
llmInfo.maxCompletionTokens,
|
||||
// Even if the model has a large maxTokens, we don't want to use that every time,
|
||||
// because it takes away from the context length
|
||||
this.contextLength / 4,
|
||||
)
|
||||
llmInfo.maxCompletionTokens,
|
||||
// Even if the model has a large maxTokens, we don't want to use that every time,
|
||||
// because it takes away from the context length
|
||||
this.contextLength / 4,
|
||||
)
|
||||
: DEFAULT_MAX_TOKENS),
|
||||
};
|
||||
this.requestOptions = options.requestOptions;
|
||||
|
|
@ -840,6 +840,7 @@ export abstract class BaseLLM implements ILLM {
|
|||
signal,
|
||||
completionOptions,
|
||||
)) {
|
||||
|
||||
if (chunk.role === "assistant") {
|
||||
completion += chunk.content;
|
||||
yield chunk;
|
||||
|
|
@ -947,7 +948,7 @@ export abstract class BaseLLM implements ILLM {
|
|||
);
|
||||
}
|
||||
|
||||
protected async *_streamComplete(
|
||||
protected async * _streamComplete(
|
||||
prompt: string,
|
||||
signal: AbortSignal,
|
||||
options: CompletionOptions,
|
||||
|
|
@ -955,7 +956,7 @@ export abstract class BaseLLM implements ILLM {
|
|||
throw new Error("Not implemented");
|
||||
}
|
||||
|
||||
protected async *_streamChat(
|
||||
protected async * _streamChat(
|
||||
messages: ChatMessage[],
|
||||
signal: AbortSignal,
|
||||
options: CompletionOptions,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { ChatMessage, CompletionOptions, LLMOptions } from "../../index.js";
|
||||
import { renderChatMessage, stripImages } from "../../util/messageContent.js";
|
||||
import { BaseLLM } from "../index.js";
|
||||
import { LlmApiRequestType } from "../openaiTypeConverters.js";
|
||||
import { streamSse } from "../stream.js";
|
||||
|
||||
class Anthropic extends BaseLLM {
|
||||
|
|
@ -16,11 +15,6 @@ class Anthropic extends BaseLLM {
|
|||
apiBase: "https://api.anthropic.com/v1/",
|
||||
};
|
||||
|
||||
protected useOpenAIAdapterFor: (LlmApiRequestType | "*")[] = [
|
||||
"streamChat",
|
||||
"chat",
|
||||
];
|
||||
|
||||
public convertArgs(options: CompletionOptions) {
|
||||
// should be public for use within VertexAI
|
||||
const finalOptions = {
|
||||
|
|
@ -36,17 +30,15 @@ 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,
|
||||
};
|
||||
|
||||
|
|
@ -78,23 +70,19 @@ 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
|
||||
}]
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -207,12 +195,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,
|
||||
|
|
@ -252,11 +240,7 @@ 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":
|
||||
|
|
@ -269,11 +253,7 @@ 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) {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ export const streamNormalInput = createAsyncThunk<
|
|||
if (!defaultModel) {
|
||||
throw new Error("Default model not defined");
|
||||
}
|
||||
// debugger;
|
||||
const includeTools = useTools && modelSupportsTools(defaultModel);
|
||||
|
||||
// Send request
|
||||
|
|
@ -103,11 +102,7 @@ export const streamNormalInput = createAsyncThunk<
|
|||
console.error("Failed to send dev data interaction log", e);
|
||||
}
|
||||
}
|
||||
// await new Promise((resolve) =>
|
||||
// setTimeout(() => {
|
||||
// resolve(undefined);
|
||||
// }, 200),
|
||||
// );
|
||||
|
||||
// If it's a tool call that is automatically accepted, we should call it
|
||||
const toolCallState = selectCurrentToolCall(getState());
|
||||
if (toolCallState) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue