https://github.com/fly-apps/hello-fly-langchain
A minimal example of how to deploy LangChain to Fly.io using Flask
https://github.com/fly-apps/hello-fly-langchain
deployment flask flyio langchain llms python
Last synced: 6 months ago
JSON representation
A minimal example of how to deploy LangChain to Fly.io using Flask
- Host: GitHub
- URL: https://github.com/fly-apps/hello-fly-langchain
- Owner: fly-apps
- Created: 2023-04-26T09:45:34.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-06-08T09:01:41.000Z (over 2 years ago)
- Last Synced: 2025-03-29T19:11:12.259Z (6 months ago)
- Topics: deployment, flask, flyio, langchain, llms, python
- Language: Python
- Homepage: https://fly.io/blog/deploying-langchain-to-fly-io/
- Size: 11.7 KB
- Stars: 23
- Watchers: 10
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# LangChain Running on Fly.io

Deploying a minimal Flask + [LangChain](https://github.com/hwchase17/langchain) application on Fly.io.> You can find the complete guide in this [Blog Post](https://fly.io/blog/deploying-langchain-to-fly-io/).
## App: Best places to eat
The application will give 3 options where to eat in ``. 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://.fly.dev/
```Examples:
#### Country
- Norway: `https://.fly.dev/norway`#### City
- Prague: `https://.fly.dev/prague`## Local Development ⚒️
### Create and Activate a Virtual Environment
We'll be using [venv](https://flask.palletsprojects.com/en/2.3.x/installation/#create-an-environment), but you can choose any virtual environment to manage the dependencies (e.g. virtualenv).
```shell
# Unix/macOS
$ python3 -m venv venv
$ . venv/bin/activate# Windows
$ py -3 -m venv venv
$ venv\Scripts\activate
```### Install Dependencies from `requirements.txt`
```shell
python -m pip install -r requirements.txt
```### Set Up `.env` file
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:
```dotenv
FLASK_APP=hello
OPENAI_API_KEY=
```The OpenAI API uses API keys for authentication.
Visit your [OpenAI API Key](https://platform.openai.com/account/api-keys) page to retrieve the API key you'll use in your requests.### Run the project
```shell
flask run
```## Deploying to Fly.io 🚀
[flyctl](https://fly.io/docs/hands-on/install-flyctl/) is the command-line utility provided by Fly.io.
If not installed yet, follow these [instructions](https://fly.io/docs/hands-on/install-flyctl/), [sign up](https://fly.io/docs/hands-on/sign-up/) and [log in](https://fly.io/docs/hands-on/sign-in/) to Fly.io.
### Launching Our App
`fly launch` will detect our Python (Flask) App.
```shell
fly launch
```During the launch you will:
- Choose an app name
- Select Organization
- Choose a region for deploymentThe `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](https://fly.io/docs/languages-and-frameworks/python/#configure-the-app-for-fly).
### Set Environment Variables
Set the `OPENAI_API_KEY` environment variable:
```shell
fly secrets set OPENAI_API_KEY=
```### Deploy to Fly.io
```shell
fly deploy
```> More details on `fly deploy` can be found [here](https://fly.io/docs/languages-and-frameworks/python/#deploying-to-fly).
### Visit Your App
```shell
fly open
```For detailed documentation on how to deploy a Flask application on [Fly.io](https://fly.io/), check [Run a Python App](https://fly.io/docs/languages-and-frameworks/python/).