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.app.py
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.run.py
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.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
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 runbeam deploy: