Skip to content

Commit 8587fbb

Browse files
author
awstools
committed
feat(client-bedrock): Add support for API Keys, Re-Ranker, implicit filter for RAG / KB evaluation for Bedrock APIs.
1 parent 1b200b5 commit 8587fbb

14 files changed

+1190
-220
lines changed

clients/client-bedrock/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@aws-sdk/middleware-recursion-detection": "*",
2828
"@aws-sdk/middleware-user-agent": "*",
2929
"@aws-sdk/region-config-resolver": "*",
30+
"@aws-sdk/token-providers": "*",
3031
"@aws-sdk/types": "*",
3132
"@aws-sdk/util-endpoints": "*",
3233
"@aws-sdk/util-user-agent-browser": "*",

clients/client-bedrock/src/BedrockClient.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ export class BedrockClient extends __Client<
625625
identityProviderConfigProvider: async (config: BedrockClientResolvedConfig) =>
626626
new DefaultIdentityProviderConfig({
627627
"aws.auth#sigv4": config.credentials,
628+
"smithy.api#httpBearerAuth": config.token,
628629
}),
629630
})
630631
);

clients/client-bedrock/src/auth/httpAuthExtensionConfiguration.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
// smithy-typescript generated code
2-
import { AwsCredentialIdentity, AwsCredentialIdentityProvider, HttpAuthScheme } from "@smithy/types";
2+
import {
3+
AwsCredentialIdentity,
4+
AwsCredentialIdentityProvider,
5+
HttpAuthScheme,
6+
TokenIdentity,
7+
TokenIdentityProvider,
8+
} from "@smithy/types";
39

410
import { BedrockHttpAuthSchemeProvider } from "./httpAuthSchemeProvider";
511

@@ -13,6 +19,8 @@ export interface HttpAuthExtensionConfiguration {
1319
httpAuthSchemeProvider(): BedrockHttpAuthSchemeProvider;
1420
setCredentials(credentials: AwsCredentialIdentity | AwsCredentialIdentityProvider): void;
1521
credentials(): AwsCredentialIdentity | AwsCredentialIdentityProvider | undefined;
22+
setToken(token: TokenIdentity | TokenIdentityProvider): void;
23+
token(): TokenIdentity | TokenIdentityProvider | undefined;
1624
}
1725

1826
/**
@@ -22,6 +30,7 @@ export type HttpAuthRuntimeConfig = Partial<{
2230
httpAuthSchemes: HttpAuthScheme[];
2331
httpAuthSchemeProvider: BedrockHttpAuthSchemeProvider;
2432
credentials: AwsCredentialIdentity | AwsCredentialIdentityProvider;
33+
token: TokenIdentity | TokenIdentityProvider;
2534
}>;
2635

2736
/**
@@ -33,6 +42,7 @@ export const getHttpAuthExtensionConfiguration = (
3342
const _httpAuthSchemes = runtimeConfig.httpAuthSchemes!;
3443
let _httpAuthSchemeProvider = runtimeConfig.httpAuthSchemeProvider!;
3544
let _credentials = runtimeConfig.credentials;
45+
let _token = runtimeConfig.token;
3646
return {
3747
setHttpAuthScheme(httpAuthScheme: HttpAuthScheme): void {
3848
const index = _httpAuthSchemes.findIndex((scheme) => scheme.schemeId === httpAuthScheme.schemeId);
@@ -57,6 +67,12 @@ export const getHttpAuthExtensionConfiguration = (
5767
credentials(): AwsCredentialIdentity | AwsCredentialIdentityProvider | undefined {
5868
return _credentials;
5969
},
70+
setToken(token: TokenIdentity | TokenIdentityProvider): void {
71+
_token = token;
72+
},
73+
token(): TokenIdentity | TokenIdentityProvider | undefined {
74+
return _token;
75+
},
6076
};
6177
};
6278

@@ -68,5 +84,6 @@ export const resolveHttpAuthRuntimeConfig = (config: HttpAuthExtensionConfigurat
6884
httpAuthSchemes: config.httpAuthSchemes(),
6985
httpAuthSchemeProvider: config.httpAuthSchemeProvider(),
7086
credentials: config.credentials(),
87+
token: config.token(),
7188
};
7289
};

clients/client-bedrock/src/auth/httpAuthSchemeProvider.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
AwsSdkSigV4PreviouslyResolved,
66
resolveAwsSdkSigV4Config,
77
} from "@aws-sdk/core";
8+
import { FromSsoInit } from "@aws-sdk/token-providers";
9+
import { doesIdentityRequireRefresh, isIdentityExpired, memoizeIdentityProvider } from "@smithy/core";
810
import {
911
HandlerExecutionContext,
1012
HttpAuthOption,
@@ -13,6 +15,8 @@ import {
1315
HttpAuthSchemeParametersProvider,
1416
HttpAuthSchemeProvider,
1517
Provider,
18+
TokenIdentity,
19+
TokenIdentityProvider,
1620
} from "@smithy/types";
1721
import { getSmithyContext, normalizeProvider } from "@smithy/util-middleware";
1822

@@ -73,6 +77,26 @@ function createAwsAuthSigv4HttpAuthOption(authParameters: BedrockHttpAuthSchemeP
7377
};
7478
}
7579

80+
function createSmithyApiHttpBearerAuthHttpAuthOption(authParameters: BedrockHttpAuthSchemeParameters): HttpAuthOption {
81+
return {
82+
schemeId: "smithy.api#httpBearerAuth",
83+
propertiesExtractor: <T>(
84+
{ profile, filepath, configFilepath, ignoreCache }: T & FromSsoInit,
85+
context: HandlerExecutionContext
86+
) => ({
87+
/**
88+
* @internal
89+
*/
90+
identityProperties: {
91+
profile,
92+
filepath,
93+
configFilepath,
94+
ignoreCache,
95+
},
96+
}),
97+
};
98+
}
99+
76100
/**
77101
* @internal
78102
*/
@@ -86,6 +110,7 @@ export const defaultBedrockHttpAuthSchemeProvider: BedrockHttpAuthSchemeProvider
86110
switch (authParameters.operation) {
87111
default: {
88112
options.push(createAwsAuthSigv4HttpAuthOption(authParameters));
113+
options.push(createSmithyApiHttpBearerAuthHttpAuthOption(authParameters));
89114
}
90115
}
91116
return options;
@@ -114,6 +139,11 @@ export interface HttpAuthSchemeInputConfig extends AwsSdkSigV4AuthInputConfig {
114139
* @internal
115140
*/
116141
httpAuthSchemeProvider?: BedrockHttpAuthSchemeProvider;
142+
143+
/**
144+
* The token used to authenticate requests.
145+
*/
146+
token?: TokenIdentity | TokenIdentityProvider;
117147
}
118148

119149
/**
@@ -139,6 +169,11 @@ export interface HttpAuthSchemeResolvedConfig extends AwsSdkSigV4AuthResolvedCon
139169
* @internal
140170
*/
141171
readonly httpAuthSchemeProvider: BedrockHttpAuthSchemeProvider;
172+
173+
/**
174+
* The token used to authenticate requests.
175+
*/
176+
readonly token?: TokenIdentityProvider;
142177
}
143178

144179
/**
@@ -147,8 +182,10 @@ export interface HttpAuthSchemeResolvedConfig extends AwsSdkSigV4AuthResolvedCon
147182
export const resolveHttpAuthSchemeConfig = <T>(
148183
config: T & HttpAuthSchemeInputConfig & AwsSdkSigV4PreviouslyResolved
149184
): T & HttpAuthSchemeResolvedConfig => {
185+
const token = memoizeIdentityProvider(config.token, isIdentityExpired, doesIdentityRequireRefresh);
150186
const config_0 = resolveAwsSdkSigV4Config(config);
151187
return Object.assign(config_0, {
152188
authSchemePreference: normalizeProvider(config.authSchemePreference ?? []),
189+
token,
153190
}) as T & HttpAuthSchemeResolvedConfig;
154191
};

clients/client-bedrock/src/commands/CreateEvaluationJobCommand.ts

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,43 @@ export interface CreateEvaluationJobCommandOutput extends CreateEvaluationJobRes
203203
* "<RetrievalFilter>",
204204
* ],
205205
* },
206+
* implicitFilterConfiguration: { // ImplicitFilterConfiguration
207+
* metadataAttributes: [ // MetadataAttributeSchemaList // required
208+
* { // MetadataAttributeSchema
209+
* key: "STRING_VALUE", // required
210+
* type: "STRING" || "NUMBER" || "BOOLEAN" || "STRING_LIST", // required
211+
* description: "STRING_VALUE", // required
212+
* },
213+
* ],
214+
* modelArn: "STRING_VALUE", // required
215+
* },
216+
* rerankingConfiguration: { // VectorSearchRerankingConfiguration
217+
* type: "BEDROCK_RERANKING_MODEL", // required
218+
* bedrockRerankingConfiguration: { // VectorSearchBedrockRerankingConfiguration
219+
* modelConfiguration: { // VectorSearchBedrockRerankingModelConfiguration
220+
* modelArn: "STRING_VALUE", // required
221+
* additionalModelRequestFields: { // AdditionalModelRequestFields
222+
* "<keys>": "DOCUMENT_VALUE",
223+
* },
224+
* },
225+
* numberOfRerankedResults: Number("int"),
226+
* metadataConfiguration: { // MetadataConfigurationForReranking
227+
* selectionMode: "SELECTIVE" || "ALL", // required
228+
* selectiveModeConfiguration: { // RerankingMetadataSelectiveModeConfiguration Union: only one key present
229+
* fieldsToInclude: [ // FieldsForReranking
230+
* { // FieldForReranking
231+
* fieldName: "STRING_VALUE", // required
232+
* },
233+
* ],
234+
* fieldsToExclude: [
235+
* {
236+
* fieldName: "STRING_VALUE", // required
237+
* },
238+
* ],
239+
* },
240+
* },
241+
* },
242+
* },
206243
* },
207244
* },
208245
* },
@@ -216,6 +253,43 @@ export interface CreateEvaluationJobCommandOutput extends CreateEvaluationJobRes
216253
* numberOfResults: Number("int"),
217254
* overrideSearchType: "HYBRID" || "SEMANTIC",
218255
* filter: "<RetrievalFilter>",
256+
* implicitFilterConfiguration: {
257+
* metadataAttributes: [ // required
258+
* {
259+
* key: "STRING_VALUE", // required
260+
* type: "STRING" || "NUMBER" || "BOOLEAN" || "STRING_LIST", // required
261+
* description: "STRING_VALUE", // required
262+
* },
263+
* ],
264+
* modelArn: "STRING_VALUE", // required
265+
* },
266+
* rerankingConfiguration: {
267+
* type: "BEDROCK_RERANKING_MODEL", // required
268+
* bedrockRerankingConfiguration: {
269+
* modelConfiguration: {
270+
* modelArn: "STRING_VALUE", // required
271+
* additionalModelRequestFields: {
272+
* "<keys>": "DOCUMENT_VALUE",
273+
* },
274+
* },
275+
* numberOfRerankedResults: Number("int"),
276+
* metadataConfiguration: {
277+
* selectionMode: "SELECTIVE" || "ALL", // required
278+
* selectiveModeConfiguration: {// Union: only one key present
279+
* fieldsToInclude: [
280+
* {
281+
* fieldName: "STRING_VALUE", // required
282+
* },
283+
* ],
284+
* fieldsToExclude: [
285+
* {
286+
* fieldName: "STRING_VALUE", // required
287+
* },
288+
* ],
289+
* },
290+
* },
291+
* },
292+
* },
219293
* },
220294
* },
221295
* generationConfiguration: { // GenerationConfiguration
@@ -236,9 +310,7 @@ export interface CreateEvaluationJobCommandOutput extends CreateEvaluationJobRes
236310
* ],
237311
* },
238312
* },
239-
* additionalModelRequestFields: { // AdditionalModelRequestFields
240-
* "<keys>": "DOCUMENT_VALUE",
241-
* },
313+
* additionalModelRequestFields: "<AdditionalModelRequestFields>",
242314
* },
243315
* orchestrationConfiguration: { // OrchestrationConfiguration
244316
* queryTransformationConfiguration: { // QueryTransformationConfiguration
@@ -279,9 +351,7 @@ export interface CreateEvaluationJobCommandOutput extends CreateEvaluationJobRes
279351
* ],
280352
* },
281353
* },
282-
* additionalModelRequestFields: {
283-
* "<keys>": "DOCUMENT_VALUE",
284-
* },
354+
* additionalModelRequestFields: "<AdditionalModelRequestFields>",
285355
* },
286356
* },
287357
* },

clients/client-bedrock/src/commands/GetEvaluationJobCommand.ts

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,43 @@ export interface GetEvaluationJobCommandOutput extends GetEvaluationJobResponse,
204204
* // "<RetrievalFilter>",
205205
* // ],
206206
* // },
207+
* // implicitFilterConfiguration: { // ImplicitFilterConfiguration
208+
* // metadataAttributes: [ // MetadataAttributeSchemaList // required
209+
* // { // MetadataAttributeSchema
210+
* // key: "STRING_VALUE", // required
211+
* // type: "STRING" || "NUMBER" || "BOOLEAN" || "STRING_LIST", // required
212+
* // description: "STRING_VALUE", // required
213+
* // },
214+
* // ],
215+
* // modelArn: "STRING_VALUE", // required
216+
* // },
217+
* // rerankingConfiguration: { // VectorSearchRerankingConfiguration
218+
* // type: "BEDROCK_RERANKING_MODEL", // required
219+
* // bedrockRerankingConfiguration: { // VectorSearchBedrockRerankingConfiguration
220+
* // modelConfiguration: { // VectorSearchBedrockRerankingModelConfiguration
221+
* // modelArn: "STRING_VALUE", // required
222+
* // additionalModelRequestFields: { // AdditionalModelRequestFields
223+
* // "<keys>": "DOCUMENT_VALUE",
224+
* // },
225+
* // },
226+
* // numberOfRerankedResults: Number("int"),
227+
* // metadataConfiguration: { // MetadataConfigurationForReranking
228+
* // selectionMode: "SELECTIVE" || "ALL", // required
229+
* // selectiveModeConfiguration: { // RerankingMetadataSelectiveModeConfiguration Union: only one key present
230+
* // fieldsToInclude: [ // FieldsForReranking
231+
* // { // FieldForReranking
232+
* // fieldName: "STRING_VALUE", // required
233+
* // },
234+
* // ],
235+
* // fieldsToExclude: [
236+
* // {
237+
* // fieldName: "STRING_VALUE", // required
238+
* // },
239+
* // ],
240+
* // },
241+
* // },
242+
* // },
243+
* // },
207244
* // },
208245
* // },
209246
* // },
@@ -217,6 +254,43 @@ export interface GetEvaluationJobCommandOutput extends GetEvaluationJobResponse,
217254
* // numberOfResults: Number("int"),
218255
* // overrideSearchType: "HYBRID" || "SEMANTIC",
219256
* // filter: "<RetrievalFilter>",
257+
* // implicitFilterConfiguration: {
258+
* // metadataAttributes: [ // required
259+
* // {
260+
* // key: "STRING_VALUE", // required
261+
* // type: "STRING" || "NUMBER" || "BOOLEAN" || "STRING_LIST", // required
262+
* // description: "STRING_VALUE", // required
263+
* // },
264+
* // ],
265+
* // modelArn: "STRING_VALUE", // required
266+
* // },
267+
* // rerankingConfiguration: {
268+
* // type: "BEDROCK_RERANKING_MODEL", // required
269+
* // bedrockRerankingConfiguration: {
270+
* // modelConfiguration: {
271+
* // modelArn: "STRING_VALUE", // required
272+
* // additionalModelRequestFields: {
273+
* // "<keys>": "DOCUMENT_VALUE",
274+
* // },
275+
* // },
276+
* // numberOfRerankedResults: Number("int"),
277+
* // metadataConfiguration: {
278+
* // selectionMode: "SELECTIVE" || "ALL", // required
279+
* // selectiveModeConfiguration: {// Union: only one key present
280+
* // fieldsToInclude: [
281+
* // {
282+
* // fieldName: "STRING_VALUE", // required
283+
* // },
284+
* // ],
285+
* // fieldsToExclude: [
286+
* // {
287+
* // fieldName: "STRING_VALUE", // required
288+
* // },
289+
* // ],
290+
* // },
291+
* // },
292+
* // },
293+
* // },
220294
* // },
221295
* // },
222296
* // generationConfiguration: { // GenerationConfiguration
@@ -237,9 +311,7 @@ export interface GetEvaluationJobCommandOutput extends GetEvaluationJobResponse,
237311
* // ],
238312
* // },
239313
* // },
240-
* // additionalModelRequestFields: { // AdditionalModelRequestFields
241-
* // "<keys>": "DOCUMENT_VALUE",
242-
* // },
314+
* // additionalModelRequestFields: "<AdditionalModelRequestFields>",
243315
* // },
244316
* // orchestrationConfiguration: { // OrchestrationConfiguration
245317
* // queryTransformationConfiguration: { // QueryTransformationConfiguration
@@ -280,9 +352,7 @@ export interface GetEvaluationJobCommandOutput extends GetEvaluationJobResponse,
280352
* // ],
281353
* // },
282354
* // },
283-
* // additionalModelRequestFields: {
284-
* // "<keys>": "DOCUMENT_VALUE",
285-
* // },
355+
* // additionalModelRequestFields: "<AdditionalModelRequestFields>",
286356
* // },
287357
* // },
288358
* // },

clients/client-bedrock/src/commands/GetFoundationModelAvailabilityCommand.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { MetadataBearer as __MetadataBearer } from "@smithy/types";
66

77
import { BedrockClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../BedrockClient";
88
import { commonParams } from "../endpoint/EndpointParameters";
9-
import { GetFoundationModelAvailabilityRequest, GetFoundationModelAvailabilityResponse } from "../models/models_0";
9+
import { GetFoundationModelAvailabilityRequest } from "../models/models_0";
10+
import { GetFoundationModelAvailabilityResponse } from "../models/models_1";
1011
import {
1112
de_GetFoundationModelAvailabilityCommand,
1213
se_GetFoundationModelAvailabilityCommand,

0 commit comments

Comments
 (0)