GPT App Template
An Altostra template for a web application that let users send prompts to one of OpenAI textual models.
An Altostra template to create projects that can be deployed with a serverless web application that features a simple web UI for users to send prompts to a preselected OpenAI GPT model.
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 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 model.
There are two environment variables that can be changed to change the behavior of the web application:
- The GPT 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 model, first review what
OpenAI textual models are available.
You can also get a comprehensive list using
OpenAI API.
After selecting a model, copy its ID and follow these instructions to set it as the application model:
- Copy OpenAI model ID
- Open the project in VSCode.
- In the Altostra Cloud Designer, open the edit form of the lambda called
prompt
and change theGPT_MODEL
environment variable (located in the Environment Variables section of lambda edit form) value by pasting the selected OpenAI model ID. - Click Save.
- Create a new project version.
- Deploy a new project version by either creating a new stack or updating an existing stack.
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.
- Open the project's Global variables.
- 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.