Skip to content

Latest commit

 

History

History
107 lines (80 loc) · 2.53 KB

File metadata and controls

107 lines (80 loc) · 2.53 KB

Phidata Bedrock Agent Serverless API

  • A basic serverless API for interacting with the Phidata Agent using AWS Bedrock
  • The conversation gets stored in a DynamoDB table
  • AWS Bedrock as the LLM Provider
  • AWS Lambda to run the Phidata Agent
  • AWS API Gateway to expose the API

Prerequisites

Steps

  1. Change directory to phidata-agent-serverless-api-bedrock
cd phidata-agent-serverless-api-bedrock
  1. Add .env file from .env-template and add your OpenAI API Key
cp .env-template .env
  1. Install dependencies
npm install
  1. Bootstrap the stack
cdk bootstrap
  1. Deploy the stack
cdk deploy

Once you've completed testing, you can remove the deployed resources by destroying the stack

cdk destroy

Test the API

  1. Get the API URL from the output of the cdk deploy command
PhidataBedrockAgentServerlessApiStack.HttpAPIUrl = https://1djpu9.execute-api.us-east-1.amazonaws.com/
  1. Change directory to phidata-agent-serverless-api-bedrock/test
cd test
  1. Create a test/.env file from test/.env-template
cp .env-template .env
  1. Paste the URL into the test/.env file
AWS_API_GATEWAY_URL=https://1djpu9.execute-api.us-east-1.amazonaws.com
  1. Create a virtual environment and install dependencies
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
  1. Run the test
python test.py

Useful CDK commands

The cdk.json file tells the CDK Toolkit how to execute your app.

  • npm run build compile typescript to js
  • npm run watch watch for changes and compile
  • npm run test perform the jest unit tests
  • npx cdk deploy deploy this stack to your default AWS account/region
  • npx cdk diff compare deployed stack with current state
  • npx cdk synth emits the synthesized CloudFormation template