The infrastructure is managed using Amazon Web Services (AWS) and includes:
- Amazon CloudFront for distributing the website content globally with low latency and high transfer speeds.
- Amazon S3 bucket to store the static website content.
- Amazon REST API Gateway to create an HTTP API.
- Three AWS Lambda functions to handle requests to the REST API:
- One to handle the API requests to send prompts to the OpenAI GPT-3 model.
- One to store an OpenAI API key in the AWS Systems Manager (SSM) Parameter Store as a SecureString.
- One to check the existence of the API key in the AWS Systems Manager (SSM) Parameter Store.
The website served by the CloudFront distribution first checks the existence of an OpenAI API key.
If the API key does not exist, the web application requests an API key from the user and stores it using the API Gateway and corresponding Lambda function.
Once the API key exists, the web application lets the user enter a prompt and send it through the API Gateway to the corresponding Lambda function that sends it to the OpenAI GPT-3 model.
There are two environment variables that can be changed to change the behavior of the web application:
- The GPT-3 model that is being used (defaults to
text-davinci-003
). - The name of the AWS Systems Manager (SSM) parameter that stores the OpenAI API key
(defaults to
gpt-api-key
).
To change either option, edit the project using VSCode with the
Altostra extension.
Follow the provided instructions and then create a new version and deploy it
(the following snippet assumes a stack named my-stack
):
alto deploy my-stack --push --env production
To change the GPT-3 model, follow these instructions:
- Open the project in VSCode.
- Click on the icon of the
prompt
lambda. - Expand the
Environment Variables
section. - Change the value of the variable named
GPT_MODEL
. - Click on Save.
Multiple deployments of the project in the same region will use the same OpenAI API key.
In order to support more than one API key in the same region - you can change the name
of the AWS Systems Manager (SSM) parameter that stores the OpenAI API key, and
create a version
that when deployed, uses another API key.
To change AWS Systems Manager (SSM) parameter that stores the OpenAI API key, follow these instructions:
- Open the project in VSCode.
- Click on the 3 dots in the upper right corner of the designer and then on
Globals
submenu. - Change the value of the variable named
GPT_API_KEY_PARAM
. - Click on Save.
- Click on the icon of the
api-key-params
SSM Parameters resource. - Change the name of the sole parameter to match exactly the name you have typed for the
GPT_API_KEY_PARAM
global environment variable. - Click on Save.