Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (provider/bedrock): support budgetTokens #5088

Merged
merged 7 commits into from
Mar 7, 2025

Conversation

Und3rf10w
Copy link
Contributor

@Und3rf10w Und3rf10w commented Mar 6, 2025

Adds backwards compatibility to support specifying budgetTokens in reasoning config for amazon-bedrock provider. This will be transformed to budget_tokens before being sent to the model.

@Und3rf10w
Copy link
Contributor Author

I actually don't know if I did the changeset correctly for this.

@lgrammel
Copy link
Collaborator

lgrammel commented Mar 6, 2025

docs needs no changeset (only pkg releases)

…okens in provider options

tweak(docs/amazon-bedrock): Standardize on budgetTokens in amazon docs to reflect anthropic

tweak(examples/amazon-bedrock): Standarize on budgetTokens
Comment on lines 581 to 595
.transform(data => {
if (!data) return data;

// Normalize the data to ensure we have budget_tokens
if (data.budgetTokens !== undefined && data.budget_tokens === undefined) {
return {
...data,
budget_tokens: data.budgetTokens,
// Remove budgetTokens to avoid duplication
budgetTokens: undefined,
};
}

return data;
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be solved in the thinking budget definition instead of having a transform (line 131)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah let me try that

Copy link
Contributor Author

@Und3rf10w Und3rf10w Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My hesitation here is that if I do:

const BedrockReasoningConfigOptionsSchema = z
  .object({
    type: z.union([z.literal('enabled'), z.literal('disabled')]),
  })
  .and(
    z.union([
      z.object({ budget_tokens: z.number() }),
      z.object({ budgetTokens: z.number() }),
    ])
  )
  .nullish();

Instead of the transform, it will break type checking here:

const thinkingBudget = reasoningConfigOptions.data?.budget_tokens ??
      reasoningConfigOptions.data?.budgetTokens;

I can fix that using in, but doesn't seem as clean?

e.g.

const thinkingBudget = reasoningConfigOptions.data && 
      ('budget_tokens' in reasoningConfigOptions.data 
        ? reasoningConfigOptions.data.budget_tokens 
        : 'budgetTokens' in reasoningConfigOptions.data 
          ? reasoningConfigOptions.data.budgetTokens 
          : undefined);

I pushed that in: 35cf123

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attempt to simplify: #5093

@Und3rf10w Und3rf10w changed the title fix(docs/amazon-bedrock): Typo fix on bedrock documentation fix(providers/amazon-bedrock): Backwards compatible budgetTokens Mar 6, 2025
@lgrammel lgrammel changed the title fix(providers/amazon-bedrock): Backwards compatible budgetTokens fix (provider/bedrock): support budgetTokens Mar 6, 2025
@Und3rf10w Und3rf10w requested a review from lgrammel March 6, 2025 18:47
@lgrammel lgrammel merged commit a841484 into vercel:main Mar 7, 2025
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants