-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: update AWS Bedrock cross-region inference profile mapping, Closed issue #2704 #4973
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import { | |
BEDROCK_MAX_TOKENS, | ||
BEDROCK_DEFAULT_CONTEXT, | ||
BEDROCK_REGION_INFO, | ||
AWS_INFERENCE_PROFILE_MAPPING, | ||
} from "@roo-code/types" | ||
|
||
import { ApiStream } from "../transform/stream" | ||
|
@@ -900,14 +901,12 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH | |
//a model was selected from the drop down | ||
modelConfig = this.getModelById(this.options.apiModelId as string) | ||
|
||
if (this.options.awsUseCrossRegionInference) { | ||
// Get the current region | ||
const region = this.options.awsRegion || "" | ||
// Use the helper method to get the appropriate prefix for this region | ||
const prefix = AwsBedrockHandler.getPrefixForRegion(region) | ||
|
||
// Apply the prefix if one was found, otherwise use the model ID as is | ||
modelConfig.id = prefix ? `${prefix}${modelConfig.id}` : modelConfig.id | ||
// Add cross-region inference prefix if enabled | ||
if (this.options.awsUseCrossRegionInference && this.options.awsRegion) { | ||
const prefix = AwsBedrockHandler.getPrefixForRegion(this.options.awsRegion) | ||
if (prefix) { | ||
modelConfig.id = `${prefix}${modelConfig.id}` | ||
} | ||
} | ||
} | ||
|
||
|
@@ -978,11 +977,16 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH | |
} | ||
|
||
private static getPrefixForRegion(region: string): string | undefined { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be helpful to add test coverage for this new
This would help ensure the mapping works correctly and prevent regressions. |
||
for (const [prefix, info] of Object.entries(BEDROCK_REGION_INFO)) { | ||
if (info.pattern && region.startsWith(info.pattern)) { | ||
return prefix | ||
// Use AWS recommended inference profile prefixes | ||
// Sort by prefix length (descending) to ensure more specific prefixes match first (e.g., us-gov- before us-) | ||
const sortedMappings = Object.entries(AWS_INFERENCE_PROFILE_MAPPING).sort(([a], [b]) => b.length - a.length) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add a comment explaining this? It would help future maintainers understand why the sorting is necessary: // Sort by prefix length (descending) to ensure more specific prefixes match first
// This prevents "us-" from matching "us-gov-" regions, for example
const sortedMappings = Object.entries(AWS_INFERENCE_PROFILE_MAPPING).sort(([a], [b]) => b.length - a.length) |
||
|
||
for (const [regionPattern, inferenceProfile] of sortedMappings) { | ||
if (region.startsWith(regionPattern)) { | ||
return inferenceProfile | ||
} | ||
} | ||
|
||
return undefined | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice the comment mentions "apac." as the updated prefix per AWS documentation, which is great. However, the existing
BEDROCK_REGION_INFO
object below (lines 422-427) still contains the old "ap." prefix entry. Is this intentional for backward compatibility? If so, it might be worth adding a note to clarify the relationship between the old and new prefixes.