Add thinking budget option to Bedrock and Vertex

This commit is contained in:
Saoud Rizwan 2025-03-01 01:39:14 -08:00
parent 0959438db8
commit dda8a6c829
3 changed files with 12 additions and 3 deletions

View file

@ -14,6 +14,8 @@ export class AwsBedrockHandler implements ApiHandler {
}
async *createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream {
let budget_tokens = this.options.thinkingBudgetTokens || 0
const reasoningOn = budget_tokens !== 0 ? true : false
// cross region inference requires prefixing the model id with the region
let modelId = await this.getModelId()
@ -24,7 +26,8 @@ export class AwsBedrockHandler implements ApiHandler {
const stream = await client.messages.create({
model: modelId,
max_tokens: this.getModel().info.maxTokens || 8192,
temperature: 0,
thinking: reasoningOn ? { type: "enabled", budget_tokens: budget_tokens } : undefined,
temperature: reasoningOn ? undefined : 0,
system: systemPrompt,
messages,
stream: true,

View file

@ -24,6 +24,9 @@ export class VertexHandler implements ApiHandler {
const model = this.getModel()
const modelId = model.id
let budget_tokens = this.options.thinkingBudgetTokens || 0
const reasoningOn = budget_tokens !== 0 ? true : false
let stream
switch (modelId) {
case "claude-3-7-sonnet@20250219":
@ -44,7 +47,8 @@ export class VertexHandler implements ApiHandler {
{
model: modelId,
max_tokens: model.info.maxTokens || 8192,
temperature: 0,
thinking: reasoningOn ? { type: "enabled", budget_tokens: budget_tokens } : undefined,
temperature: reasoningOn ? undefined : 0,
system: [
{
text: systemPrompt,

View file

@ -1201,7 +1201,9 @@ const ApiOptions = ({ showModelOptions, apiErrorMessage, modelIdErrorMessage, is
{selectedProvider === "xai" && createDropdown(xaiModels)}
</DropdownContainer>
{selectedProvider === "anthropic" && selectedModelId === "claude-3-7-sonnet-20250219" && (
{((selectedProvider === "anthropic" && selectedModelId === "claude-3-7-sonnet-20250219") ||
(selectedProvider === "bedrock" && selectedModelId === "anthropic.claude-3-7-sonnet-20250219-v1:0") ||
(selectedProvider === "vertex" && selectedModelId === "claude-3-7-sonnet@20250219")) && (
<ThinkingBudgetSlider apiConfiguration={apiConfiguration} setApiConfiguration={setApiConfiguration} />
)}