-
Notifications
You must be signed in to change notification settings - Fork 90
fix(bedrock): inference profile prefix resolution #189
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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,19 +11,43 @@ import ( | |||||||||||||
|
|
||||||||||||||
| func bedrockBasicAuthConfig(apiKey string) aws.Config { | ||||||||||||||
| return aws.Config{ | ||||||||||||||
| Region: cmp.Or(os.Getenv("AWS_REGION"), "us-east-1"), | ||||||||||||||
| Region: cmp.Or(awsRegion(), "us-east-1"), | ||||||||||||||
| BearerAuthTokenProvider: bearer.StaticTokenProvider{Token: bearer.Token{Value: apiKey}}, | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| func bedrockPrefixModelWithRegion(modelID string) string { | ||||||||||||||
| region := os.Getenv("AWS_REGION") | ||||||||||||||
| if len(region) < 2 { | ||||||||||||||
| region = "us-east-1" | ||||||||||||||
| } | ||||||||||||||
| prefix := region[:2] + "." | ||||||||||||||
| if strings.HasPrefix(modelID, prefix) { | ||||||||||||||
| if hasBedrockInferenceProfilePrefix(modelID) { | ||||||||||||||
| return modelID | ||||||||||||||
| } | ||||||||||||||
| return prefix + modelID | ||||||||||||||
| region := cmp.Or(awsRegion(), "us-east-1") | ||||||||||||||
| return bedrockRegionPrefix(region) + "." + modelID | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| func awsRegion() string { | ||||||||||||||
| return cmp.Or(os.Getenv("AWS_REGION"), os.Getenv("AWS_DEFAULT_REGION")) | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+27
to
+29
|
||||||||||||||
|
|
||||||||||||||
| func bedrockRegionPrefix(region string) string { | ||||||||||||||
| switch { | ||||||||||||||
| case strings.HasPrefix(region, "us-") || region == "ca-central-1": | ||||||||||||||
| return "us" | ||||||||||||||
| case strings.HasPrefix(region, "eu-"): | ||||||||||||||
| return "eu" | ||||||||||||||
| case region == "ap-northeast-1": | ||||||||||||||
| return "jp" | ||||||||||||||
| case region == "ap-southeast-2": | ||||||||||||||
| return "au" | ||||||||||||||
|
Comment on lines
+39
to
+40
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. Let's add the missing case again, to make sure we support the apac region as well:
Suggested change
|
||||||||||||||
| default: | ||||||||||||||
| return "global" | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| func hasBedrockInferenceProfilePrefix(modelID string) bool { | ||||||||||||||
| for _, prefix := range []string{"us.", "eu.", "jp.", "au.", "global."} { | ||||||||||||||
|
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. And finally, the missing apac prefix should be added here as well:
Suggested change
|
||||||||||||||
| if strings.HasPrefix(modelID, prefix) { | ||||||||||||||
| return true | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| return false | ||||||||||||||
| } | ||||||||||||||
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.