Skip to content

fly-apps/hello-fly-langchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LangChain Running on Fly.io

Illustration by Annie Ruygt Deploying a minimal Flask + LangChain application on Fly.io.

You can find the complete guide in this Blog Post.

App: Best places to eat

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:

Country

  • Norway: https://<your-app-name>.fly.dev/norway

City

  • Prague: https://<your-app-name>.fly.dev/prague

Local Development ⚒️

Create and Activate a Virtual Environment

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

Install Dependencies from requirements.txt

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:

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.

Run the project

flask run

Deploying to Fly.io 🚀

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.

Launching Our App

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 Environment Variables

Set the OPENAI_API_KEY environment variable:

fly secrets set OPENAI_API_KEY=<your-openai-api-secret-key>

Deploy to Fly.io

fly deploy

More details on fly deploy can be found here.

Visit Your App

fly open

For detailed documentation on how to deploy a Flask application on Fly.io, check Run a Python App.