Bedrock を利用したアプリケーションのプロトタイピングを行うための最低限の実装です。 Streamlit 単体でもセッション(履歴)管理することは可能ですが、本実装する際のことを考慮しデフォルトで DynamoDB を利用するようにしています。
devcontainer を利用することで DynamoDB Local をバックグラウンドで自動起動することができます。
devcontainer を利用しないが DynamoDB Local を利用したい場合は、下記コマンドで手動で DynamoDB Local を起動してください。
※ この場合、endpoint_url
は http://localhost:8000
になります。(devcontainer 利用時は http://dynamodb-local:8000
)
docker-compose -f .devcontainer/docker-compose.yml up dynamodb-local
Bedrock API を利用するため、ローカル開発時も AWS の認証情報が必要です。
下記コマンドで IAM Identity Center から認証情報を取得してください。
aws configure sso --profile default
aws sso login # 初回以降
下記コマンドで Access Key 等を設定してください。
aws configure --profile default
サンプルコードは AWS SDK (boto3) を利用したものと、Langchain を利用したものの2つを用意しています。
どちらもチャットの一時記憶領域に DynamoDB を使用しています。
streamlit run main.py # use AWS SDK (boto3)
streamlit run chain.py # use Langchain