Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 86
feat(eval): ab-test target-based run (create)#2135
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -76,6 +76,7 @@ import { | ||
| type EvaluationReferenceInput, | ||
| type EvaluationResultContent, | ||
| type EvaluationTarget, | ||
| type CreateABTestRequest, | ||
| type CreateABTestResponse, | ||
| type GetABTestResponse, | ||
| type ListABTestsResponse, | ||
| @@ -123,6 +124,7 @@ import type { | ||
| CoreEvalClient, | ||
| CreateConfigurationBundleInput, | ||
| CreateConfigBundleABTestInput, | ||
| CreateTargetBasedABTestInput, | ||
| CreateDatasetInput, | ||
| CreateOnlineEvalInput, | ||
| CreateOnlineInsightInput, | ||
| @@ -481,65 +483,38 @@ export class EvalClient implements CoreEvalClient { | ||
| .send(new DeleteABTestCommand({ abTestId: id })); | ||
| } | ||
| async createConfigBundleABTest( | ||
| input: CreateConfigBundleABTestInput, | ||
| private async createABTest( | ||
| name: string, | ||
| gateway: string, | ||
| callerRoleArn: string | undefined, | ||
| build: (context: { | ||
| gatewayArn: string; | ||
| accountId: string; | ||
| roleArn: string; | ||
| }) => CreateABTestRequest, | ||
| options: CoreOptions, | ||
| ): Promise<CreateABTestResponse> { | ||
| const control = this.clients.control(toClientConfig(options)); | ||
| const gateway = await control.send(new GetGatewayCommand({ gatewayIdentifier: input.gateway })); | ||
| const gatewayArn = gateway.gatewayArn!; | ||
| const gatewayArn = (await control.send(new GetGatewayCommand({ gatewayIdentifier: gateway }))) | ||
| .gatewayArn!; | ||
| const accountId = accountIdFromArn(gatewayArn); | ||
| const controlBundleArn = `arn:aws:bedrock-agentcore:${options.region}:${accountId}:configuration-bundle/${input.control.configBundle}`; | ||
| const treatmentBundleArn = `arn:aws:bedrock-agentcore:${options.region}:${accountId}:configuration-bundle/${input.treatment.configBundle}`; | ||
| const onlineEvaluationConfigArn = `arn:aws:bedrock-agentcore:${options.region}:${accountId}:online-evaluation-config/${input.onlineEval}`; | ||
| const treatmentWeight = input.treatmentWeight ?? 50; | ||
| const variants = [ | ||
| { | ||
| name: "C", | ||
| weight: 100 - treatmentWeight, | ||
| variantConfiguration: { | ||
| configurationBundle: { | ||
| bundleArn: controlBundleArn, | ||
| bundleVersion: input.control.bundleVersion, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "T1", | ||
| weight: treatmentWeight, | ||
| variantConfiguration: { | ||
| configurationBundle: { | ||
| bundleArn: treatmentBundleArn, | ||
| bundleVersion: input.treatment.bundleVersion, | ||
| }, | ||
| }, | ||
| }, | ||
| ]; | ||
| let roleArn = input.roleArn; | ||
| let roleArn = callerRoleArn; | ||
| let provisionedRoleArn: string | undefined; | ||
| if (!roleArn) { | ||
| const iam = this.clients.iam({ region: options.region }); | ||
| const provisioned = await provisionAbTestRole(iam, input.name, gatewayArn, options.region); | ||
| const provisioned = await provisionAbTestRole( | ||
| this.clients.iam({ region: options.region }), | ||
| name, | ||
| gatewayArn, | ||
| options.region, | ||
| ); | ||
| roleArn = provisioned.roleArn; | ||
| if (provisioned.created) provisionedRoleArn = provisioned.roleArn; | ||
| } | ||
| const command = new CreateABTestCommand({ | ||
| name: input.name, | ||
| gatewayArn, | ||
| variants, | ||
| evaluationConfig: { onlineEvaluationConfigArn }, | ||
| roleArn, | ||
| gatewayFilter: input.gatewayFilter, | ||
| enableOnCreate: input.enableOnCreate ?? true, | ||
| clientToken: randomUUID(), | ||
| }); | ||
| const command = new CreateABTestCommand(build({ gatewayArn, accountId, roleArn })); | ||
| try { | ||
| return input.roleArn | ||
| return callerRoleArn | ||
| ? await this.clients.data(toClientConfig(options)).send(command) | ||
| : await retryWhileRolePropagates(() => | ||
| this.clients.data(toClientConfig(options)).send(command), | ||
| @@ -556,6 +531,99 @@ export class EvalClient implements CoreEvalClient { | ||
| } | ||
| } | ||
| async createConfigBundleABTest( | ||
| input: CreateConfigBundleABTestInput, | ||
| options: CoreOptions, | ||
| ): Promise<CreateABTestResponse> { | ||
| const treatmentWeight = input.treatmentWeight ?? 50; | ||
| return this.createABTest( | ||
| input.name, | ||
| input.gateway, | ||
| input.roleArn, | ||
| ({ gatewayArn, accountId, roleArn }) => { | ||
| const bundleArn = (id: string) => | ||
| `arn:aws:bedrock-agentcore:${options.region}:${accountId}:configuration-bundle/${id}`; | ||
| return { | ||
| name: input.name, | ||
| gatewayArn, | ||
| variants: [ | ||
| { | ||
| name: "C", | ||
| weight: 100 - treatmentWeight, | ||
| variantConfiguration: { | ||
| configurationBundle: { | ||
| bundleArn: bundleArn(input.control.configBundle), | ||
| bundleVersion: input.control.bundleVersion, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "T1", | ||
| weight: treatmentWeight, | ||
| variantConfiguration: { | ||
| configurationBundle: { | ||
| bundleArn: bundleArn(input.treatment.configBundle), | ||
| bundleVersion: input.treatment.bundleVersion, | ||
| }, | ||
| }, | ||
| }, | ||
| ], | ||
| evaluationConfig: { | ||
| onlineEvaluationConfigArn: `arn:aws:bedrock-agentcore:${options.region}:${accountId}:online-evaluation-config/${input.onlineEval}`, | ||
| }, | ||
| roleArn, | ||
| gatewayFilter: input.gatewayFilter, | ||
| enableOnCreate: input.enableOnCreate ?? true, | ||
| clientToken: randomUUID(), | ||
| }; | ||
| }, | ||
| options, | ||
| ); | ||
| } | ||
| async createTargetBasedABTest( | ||
| input: CreateTargetBasedABTestInput, | ||
| options: CoreOptions, | ||
| ): Promise<CreateABTestResponse> { | ||
| const treatmentWeight = input.treatmentWeight ?? 50; | ||
| return this.createABTest( | ||
| input.name, | ||
| input.gateway, | ||
| input.roleArn, | ||
| ({ gatewayArn, accountId, roleArn }) => { | ||
| const evalArn = (id: string) => | ||
| `arn:aws:bedrock-agentcore:${options.region}:${accountId}:online-evaluation-config/${id}`; | ||
| return { | ||
| name: input.name, | ||
| gatewayArn, | ||
| variants: [ | ||
| { | ||
| name: "C", | ||
| weight: 100 - treatmentWeight, | ||
| variantConfiguration: { target: { name: input.control.gatewayTarget } }, | ||
| }, | ||
| { | ||
| name: "T1", | ||
| weight: treatmentWeight, | ||
| variantConfiguration: { target: { name: input.treatment.gatewayTarget } }, | ||
Contributor 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. same question as above | ||
| }, | ||
| ], | ||
| evaluationConfig: { | ||
| perVariantOnlineEvaluationConfig: [ | ||
| { name: "C", onlineEvaluationConfigArn: evalArn(input.control.onlineEval) }, | ||
| { name: "T1", onlineEvaluationConfigArn: evalArn(input.treatment.onlineEval) }, | ||
| ], | ||
| }, | ||
| roleArn, | ||
| gatewayFilter: input.gatewayFilter, | ||
| enableOnCreate: input.enableOnCreate ?? true, | ||
| clientToken: randomUUID(), | ||
| }; | ||
| }, | ||
| options, | ||
| ); | ||
| } | ||
| async listBatchInsights( | ||
| nextToken: string | undefined, | ||
| maxResults: number | undefined, | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { Router } from "../../../../router"; | ||
| import type { AppIO } from "../../../../io"; | ||
| import type { Core } from "../../../types"; | ||
| import { createTargetBasedRunHandler } from "./run"; | ||
| export function createTargetBasedAbTestHandler(core: Core, io: AppIO): Router { | ||
| return new Router("target-based", "target-based A/B tests").handler( | ||
| createTargetBasedRunHandler(core, io), | ||
| ); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.
Is target expecting a name or id here?
src/handlers/eval/ab-test/target-based/run/index.tsx#L21documents gateway-target as<id>; I'd expectinput.control.gatewayTargetis then the target ID. But this field looks to expect target name?