File tree Expand file tree Collapse file tree 4 files changed +13
-9
lines changed Expand file tree Collapse file tree 4 files changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -3,12 +3,7 @@ import { ProviderAPIConfig } from '../types';
33const AnthropicAPIConfig : ProviderAPIConfig = {
44 getBaseURL : ( ) => 'https://api.anthropic.com/v1' ,
55
6- headers : ( {
7- providerOptions,
8- fn,
9- headers : requestHeaders ,
10- gatewayRequestBody,
11- } ) => {
6+ headers : ( { providerOptions, fn, gatewayRequestBody } ) => {
127 const apiKey =
138 providerOptions . apiKey || providerOptions . anthropicApiKey || '' ;
149 const headers : Record < string , string > = {
Original file line number Diff line number Diff line change 77 generateAWSHeaders ,
88 getFoundationModelFromInferenceProfile ,
99 providerAssumedRoleCredentials ,
10+ getBedrockModelWithoutRegion ,
1011} from './utils' ;
1112import { GatewayError } from '../../errors/GatewayError' ;
1213
@@ -234,7 +235,10 @@ const BedrockAPIConfig: BedrockAPIConfigInterface = {
234235 return `/model-invocation-job/${ batchId } /stop` ;
235236 }
236237 const { model, stream } = gatewayRequestBody ;
237- const uriEncodedModel = encodeURIComponent ( decodeURIComponent ( model ?? '' ) ) ;
238+ const decodedModel = decodeURIComponent ( model ?? '' ) ;
239+ const uriEncodedModel = encodeURIComponent ( decodedModel ) ;
240+ const modelWithoutRegion = getBedrockModelWithoutRegion ( decodedModel ) ;
241+ const uriEncodedModelWithoutRegion = encodeURIComponent ( modelWithoutRegion ) ;
238242 if ( ! model && ! BEDROCK_NO_MODEL_ENDPOINTS . includes ( fn as endpointStrings ) ) {
239243 throw new GatewayError ( 'Model is required' ) ;
240244 }
@@ -305,7 +309,7 @@ const BedrockAPIConfig: BedrockAPIConfigInterface = {
305309 return `/model-customization-jobs/${ jobId } /stop` ;
306310 }
307311 case 'messagesCountTokens' : {
308- return `/model/${ uriEncodedModel } /count-tokens` ;
312+ return `/model/${ uriEncodedModelWithoutRegion } /count-tokens` ;
309313 }
310314 default :
311315 return '' ;
Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ import {
8585 BedrockConverseMessageCountTokensConfig ,
8686 BedrockConverseMessageCountTokensResponseTransform ,
8787} from './countTokens' ;
88+ import { getBedrockModelWithoutRegion } from './utils' ;
8889
8990const BedrockConfig : ProviderConfigs = {
9091 api : BedrockAPIConfig ,
@@ -101,7 +102,7 @@ const BedrockConfig: ProviderConfigs = {
101102
102103 if ( params . model ) {
103104 let providerModel = providerOptions . foundationModel || params . model ;
104- providerModel = providerModel . replace ( / ^ ( u s \. | e u \. | a p a c \. ) / , '' ) ;
105+ providerModel = getBedrockModelWithoutRegion ( providerModel ) ;
105106 const providerModelArray = providerModel ?. split ( '.' ) ;
106107 const provider = providerModelArray ?. [ 0 ] ;
107108 const model = providerModelArray ?. slice ( 1 ) . join ( '.' ) ;
Original file line number Diff line number Diff line change @@ -537,3 +537,7 @@ export const getBedrockErrorChunk = (id: string, model: string) => {
537537 `data: [DONE]\n\n` ,
538538 ] ;
539539} ;
540+
541+ export const getBedrockModelWithoutRegion = ( model : string ) => {
542+ return model . replace ( / ^ ( u s \. | e u \. | a p a c \. | a u \. | c a \. | j p \. | g l o b a l \. ) / , '' ) ;
543+ } ;
You can’t perform that action at this time.
0 commit comments