LangChain Chatbot
This example demonstrates a Question Answering app, built using LangChain. Beam makes it easy to iterate on this code in a remote GPU environment, and you can deploy the app as a REST API with a single command when you’re finished.
How this app works
This app lets you ask questions about a list of URLs. For example, you could supply the URL for apple.com and ask what kinds of products does this company sell?
Setting up the environment
First, you’ll setup your compute environment. You’ll specify:
- Compute requirements
- Python packages to install in the runtime
For this example, you’ll need an OpenAI API Key saved in your Beam Secrets Manager, saved as OPENAI_API_KEY
.
Answering questions about URLs
This is the meat of our application — it retrieves the content from the URLs provided, loads them into a GPT model, and generates an answer based on the question you’ve provided.
Running Inference
Beam includes a live-reloading feature that allows you to run your code on the same environment you’ll be running in production.
By default, Beam will sync all the files in your working directory to the remote container. This allows you to use the files you have locally while developing. If you want to prevent some files from getting uploaded, you can create a .beamignore
.
In your shell, run beam serve app.py
. This will:
- Spin up a container
- Run it on a GPU
- Print a cURL request to invoke the API
- Stream the logs to your shell
You should keep this terminal window open while developing.
Now, head back to your IDE, and change a line of code. Hit save.
If you look closely at the shell running beam serve
, you’ll notice the server reloading with your code changes.
You’ll use this workflow anytime you’re developing an app on Beam. Trust us — it makes the development process uniquely fast and painless.
Deployment
You might want to deploy this as a persistent REST API. It’s simple to do so. Just run beam deploy
:
Your Beam Dashboard will open in a browser window, and you can monitor the deployment status in the web UI.
Calling the API
You’ll call the API by pasting in the cURL command displayed in the browser window.
The API will return an answer, like so:
Was this page helpful?