This is a Django chatbot that uses OpenAI's GPT-3.5 to generate responses. The chatbot is deployed to AWS Lambda using the AWS CDK.
- Django
- OpenAI
- HTMX
- AWS Lambda
- AWS CDK
- Python 3.12
- Poetry
- AWS CLI
To install the required packages, you can use the following command:
make init
You need to create a .env
file with the following variables:
OPENAI_API_KEY=your-api-key
AWS_ACCESS_KEY_ID=your-access-key-id
AWS_SECRET_ACCESS_KEY=your-secret-access-key
You can copy the .env.example
file and replace the values with your own.
cp .env.example .env
To run the Django server locally, you can use the following commands:
make run-server
The server will be running at http://localhost:8000
.
You can also use docker. Make sure to source the .env
file and build the docker image:
make docker-build
make docker-run
The server will be running at http://localhost:9000
.
You need to set the openai api key in the AWS Parameter Store.
aws ssm put-parameter --name /django-chatbot/openai-api-key --value your-api-key --type String
You also need to generate and set a secret key for Django.
python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'
Then, set the secret key in the AWS Parameter Store.
aws ssm put-parameter --name /django-chatbot/secret-key --value your-secret-key --type String
Bootstrap the CDK toolkit.
cdk bootstrap
Check potential warnings from django.
make check-deploy
Synthetize the CloudFormation template.
cdk synth
Deploy the CloudFormation template.
cdk deploy