From a92469108626e39b25133efff3328bc985a0b558 Mon Sep 17 00:00:00 2001 From: Oscar Caicedo Date: Tue, 18 Feb 2025 16:26:18 -0500 Subject: [PATCH] Update README.md Update auth method for aws bedrock --- README.md | 70 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 23b6efb..265c845 100644 --- a/README.md +++ b/README.md @@ -41,34 +41,82 @@ if you are using Genkit version `" }), - model: amazonNovaProV1, - ] + ], + model: amazonNovaProV1, }); ``` -You can also intialize the plugin in this way if you have set the `AWS_` environment variable: +If you have set the `AWS_` environment variables, you can initialize it like this: ```typescript import { genkit, z } from 'genkit'; -import {awsBedrock, amazonNovaProV1} from "genkitx-aws-bedrock"; +import { awsBedrock, amazonNovaProV1 } from "genkitx-aws-bedrock"; const ai = genkit({ plugins: [ awsBedrock(), - model: amazonNovaProV1, - ] + ], + model: amazonNovaProV1, +}); +``` + +#### Production Environment Authentication + +In production environments, it is often necessary to install an additional library to handle authentication. One approach is to use the `@aws-sdk/credential-providers` package: + +```typescript +import { fromEnv } from "@aws-sdk/credential-providers"; +const ai = genkit({ + plugins: [ + awsBedrock({ + region: "us-east-1", + credentials: fromEnv(), + }), + ], }); ``` +Ensure you have a `.env` file with the necessary AWS credentials. Remember that the .env file must be added to your .gitignore to prevent sensitive credentials from being exposed. + +``` +AWS_ACCESS_KEY_ID = +AWS_SECRET_ACCESS_KEY = +``` + +#### Local Environment Authentication + +For local development, you can directly supply the credentials: + +```typescript +const ai = genkit({ + plugins: [ + awsBedrock({ + region: "us-east-1", + credentials: { + accessKeyId: awsAccessKeyId.value(), + secretAccessKey: awsSecretAccessKey.value(), + }, + }), + ], +}); +``` + +Each approach allows you to manage authentication effectively based on your environment needs. + + ### Configuration with Inference Endpoint If you want to use a model that uses [Cross-region Inference Endpoints](https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-support.html), you can specify the region in the model configuration. Cross-region inference uses inference profiles to increase throughput and improve resiliency by routing your requests across multiple AWS Regions during peak utilization bursts: @@ -76,13 +124,13 @@ If you want to use a model that uses [Cross-region Inference Endpoints](https:// ```typescript import { genkit, z } from 'genkit'; -import {awsBedrock, amazonNovaProV1} from "genkitx-aws-bedrock"; +import {awsBedrock, amazonNovaProV1, anthropicClaude35SonnetV2} from "genkitx-aws-bedrock"; const ai = genkit({ plugins: [ awsBedrock(), - model: anthropicClaude3SonnetV1("us"), - ] + ], + model: anthropicClaude35SonnetV2("us"), }); ```