はじめに
今回はWernerのキーノートで紹介されたGenerative AIに関するCDKのConstructをご紹介します。Constructとは、今回の文脈だとCDKのL3としてある程度の機能をまとめたり抽象化したものになります。以降はGenAI CDK Constructと略して記載します。
リポジトリなど
またConstruct自体は既にConstruct Hubでも共有されているので、すぐに試しに使うこともできます。
内容
重要そうな部分だけピックアップすると、バージョン管理、実装の構成が上げられます。
バージョン管理
AWS Generative AI CDK ConstructsはCDK自体のバージョンとは離れて管理され、特定のGenAI CDKのバージョンは、CDKの特定のバージョンをベースにのみ構築されます。これはCDKのバージョンアップ時に実装変更で後方互換性がなくなったときのことを考慮していそうです。ここは余談ですがConstructを作っていく指針として参考になりそうです。
実装の構成
TopのReadmeはあくまでGen AI CDK Construct全体の説明で、実装はいくつかのパターンを持っています。パターンごとの実装はsrc/patterns/gen-ai
ディレクトリに格納されており、実装の詳細は配下のディレクトリを見れば確認できます。現状は以下のような実装があります。右に簡単な紹介を記載します。
- Data ingestion pipeline(RAG用のデータ取り込みパイプライン)
- Question answering(RAGとClaude V2を使った質疑応答)
- Summarization(Claude V2による文書の要約)
- Lambda layer(GenAIに必要なレイヤー)
- SageMaker model deployment(Amazon SageMakerエンドポイントに基盤モデルをデプロイ)
一部紹介
例えばLambdaLayerでは以下のように、GenAIの実行に必要な依存関係だけをまとめたレイヤーを取得するコードがConstructとして提供されます。これは自前でレイヤーを構築する手間を省くことができ、propsによる自由な拡張もあるので非常に便利に使えそうです。
export class LangchainCommonLayer extends Construct {
/**
* Returns the instance of lambda.LayerVersion created by the construct
*/
public readonly layer: lambda.LayerVersion;
/**
* @summary Constructs a new instance of the LangchainCommonLayer class.
* @param {cdk.App} scope - represents the scope for all the resources.
* @param {string} id - this is a a scope-unique id.
* @param {LangchainLayerProps} props - user provided props for the construct.
* @since 0.0.0
* @access public
*/
constructor(scope: Construct, id: string, props: LangchainLayerProps) {
super(scope, id);
const layer = new lambda.LayerVersion(this, 'langchaincommonlayer', {
compatibleRuntimes: [props.runtime],
compatibleArchitectures: [props.architecture],
code: lambda.Code.fromAsset(path.join(__dirname, '../../../../layers/langchain-common-layer')),
description: 'Utilities to build gen ai applications with the langchain client',
});
this.layer = layer;
}
}
所感
一旦速報のみですが、キーノートでCDKの話が出て嬉しかったので記事にしました。自分もGenAI系のサービスを進める際はこちらのリポジトリを参考に構築、またはConstructとして利用させてもらうと思います。是非試してみて下さい!