Skip to content
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

feat(bedrock): add application inference profile #800

Merged
merged 29 commits into from
Nov 20, 2024

Conversation

krokoko
Copy link
Collaborator

@krokoko krokoko commented Nov 12, 2024

Fixes #683

Co-developed with @aws-rafams

  • Add the new application profile released in cdk v2.166.0
  • Upgrades cdk v2.166.0 and fix related changes (prompt topK removed, property required)
  • Update documentation
  • Update agents and prompts to support CRIS through system defined inference profiles
  • At this moment, Application Inference Profiles are not supported for Agents/Prompts by the services
  • Add support to load cdk bedrock models as BedrockFoundationModel
  • Support for CRIS in Knowledge Bases will be done separately

Created 3 application inference profiles through CDK:

// Create an application inference profile for one Region
new bedrock.ApplicationInferenceProfile(this, 'TestAIP', {
      inferenceProfileName: 'TestAIP',
      description: 'This is a test application inf profile',
      modelSource: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0.asArn(this),
      tags: [{key: 'test', value: 'test'}]
    });

// Create an application inference profile across regions
  const aip = new bedrock.ApplicationInferenceProfile(this, 'myapplicationprofile2', {
    inferenceProfileName: 'claude 35 sonnet v2',
    modelSource: 'arn:aws:bedrock:us-west-2::foundation-model/anthropic.claude-3-5-sonnet-20241022-v2:0'
  });

new cdk.CfnOutput(this, 'InferenceProfileArn', {value: aip.inferenceProfileArn});
new cdk.CfnOutput(this, 'InferenceProfileId', {value: aip.inferenceProfileId});
new cdk.CfnOutput(this, 'InferenceProfileIdentifier', {value: aip.inferenceProfileIdentifier});
new cdk.CfnOutput(this, 'Status', {value: aip.status});
new cdk.CfnOutput(this, 'Createdat', {value: aip1.createdAt});
new cdk.CfnOutput(this, 'Updatedat', {value: aip1.updatedAt});

// Import an aip created through the L1 cfn construct
const cfnapp = new CfnApplicationInferenceProfile(this, 'mytestaip3', {
      inferenceProfileName: 'mytest',
      modelSource: {
        copyFrom: 'arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0',
      },
});

const aip3 = bedrock.ApplicationInferenceProfile.fromCfnApplicationInferenceProfile(cfnapp);

Example of CDK outputs:

BedrockAgentStack.InferenceProfileArn = arn:aws:bedrock:us-east-1:XXXXX:application-inference-profile/cew2pa5r8hog
BedrockAgentStack.inferenceProfileId = cew2pa5r8hog
BedrockAgentStack.inferenceProfileIdentifier = arn:aws:bedrock:us-east-1:XXXXX:application-inference-profile/cew2pa5r8hog
BedrockAgentStack.status = ACTIVE
BedrockAgentStack.Updatedat = 2024-11-13T22:42:40.608335958Z
BedrockAgentStack.Createdat = 2024-11-13T22:42:40.608335958Z

Listed the available profiles through boto3:

'inferenceProfileSummaries': [
    {'inferenceProfileName': 'claude 35 sonnet v2', 'createdAt': datetime.datetime(2024, 11, 12, 22, 11, 43, 869820, tzinfo=tzutc()), 'updatedAt': datetime.datetime(2024, 11, 12, 22, 11, 43, 869820, tzinfo=tzutc()), 'inferenceProfileArn': 'arn:aws:bedrock:us-east-1:XXXXX:application-inference-profile/cew2pa5r8hog', 'models': [{'modelArn': 'arn:aws:bedrock:us-west-2::foundation-model/anthropic.claude-3-5-sonnet-20241022-v2:0'}], 'inferenceProfileId': 'cew2pa5r8hog', 'status': 'ACTIVE', 'type': 'APPLICATION'}, 
    {'inferenceProfileName': 'TestAIP', 'description': 'This is a test application inf profile', 'createdAt': datetime.datetime(2024, 11, 12, 22, 11, 48, 358568, tzinfo=tzutc()), 'updatedAt': datetime.datetime(2024, 11, 12, 22, 11, 48, 358568, tzinfo=tzutc()), 'inferenceProfileArn': 'arn:aws:bedrock:us-east-1:XXXXXXXX:application-inference-profile/63ntfzxa78ze', 'models': [{'modelArn': 'arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0'}], 'inferenceProfileId': '63ntfzxa78ze', 'status': 'ACTIVE', 'type': 'APPLICATION'}
]

Then used Converse API in Python to test the 3 created application inference profiles with modelId=inf_profile_arn

Tested also with the Bedrock agent sample, by deploying the app with the existing model, and by using CRIS to ensure no regressions and support of the new features.
Tested to create prompts and test them through the console with CRIS

Remaining tasks:

  • Fix all tests and documentation, then ready for review

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.

@krokoko krokoko marked this pull request as ready for review November 13, 2024 23:07
@krokoko krokoko requested a review from a team as a code owner November 13, 2024 23:07
Copy link
Collaborator

@scottschreckengaust scottschreckengaust left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

CHANGELOG.md Outdated Show resolved Hide resolved
@krokoko krokoko marked this pull request as draft November 18, 2024 16:41
@krokoko
Copy link
Collaborator Author

krokoko commented Nov 18, 2024

Putting back to draft mode as other changes are done in a separate branch

@krokoko krokoko marked this pull request as ready for review November 20, 2024 01:56
@krokoko krokoko merged commit 48daf18 into awslabs:main Nov 20, 2024
14 of 16 checks passed
@krokoko krokoko deleted the inference_profile branch November 21, 2024 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(bedrock): add inference profiles / cross-region inference
6 participants