Deploying a minimal Flask + LangChain application on Fly.io.
You can find the complete guide in this Blog Post.
The application will give 3 options where to eat in <place>
. The default value is Berlin
.
Prompt: What are the 3 best places to eat in {place}?
You can define your own input variable (place
) by calling:
https://<your-app-name>.fly.dev/<place>
Examples:
- Norway:
https://<your-app-name>.fly.dev/norway
- Prague:
https://<your-app-name>.fly.dev/prague
We'll be using venv, but you can choose any virtual environment to manage the dependencies (e.g. virtualenv).
# Unix/macOS
$ python3 -m venv venv
$ . venv/bin/activate
# Windows
$ py -3 -m venv venv
$ venv\Scripts\activate
python -m pip install -r requirements.txt
The environment variables are stored in the .env
file.
Rename the .env.dist
file to .env
. Update the OPENAI_API_KEY
environment variable with your own secret key:
FLASK_APP=hello
OPENAI_API_KEY=<your-openai-api-secret-key>
The OpenAI API uses API keys for authentication. Visit your OpenAI API Key page to retrieve the API key you'll use in your requests.
flask run
flyctl is the command-line utility provided by Fly.io.
If not installed yet, follow these instructions, sign up and log in to Fly.io.
fly launch
will detect our Python (Flask) App.
fly launch
During the launch you will:
- Choose an app name
- Select Organization
- Choose a region for deployment
The Procfile
already exists in this project - a new one will be generated for you if your project doesn't have one.
More details on
fly launch
can be found here.
Set the OPENAI_API_KEY
environment variable:
fly secrets set OPENAI_API_KEY=<your-openai-api-secret-key>
fly deploy
More details on
fly deploy
can be found here.
fly open
For detailed documentation on how to deploy a Flask application on Fly.io, check Run a Python App.