-
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
Open
jariy17
wants to merge
1
commit into
feat/eval-ab-test-config-bundle-run
from
feat/eval-ab-test-target-based
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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), | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?