Skip to main content
Ray Serve is a scalable model serving library for building online inference APIs. Serve is particularly well suited for system composition, enabling you to build a complex inference service consisting of multiple chains and business logic all in Python code.

Goal of this notebook

This notebook shows a simple example of how to deploy an OpenAI chain into production. You can extend it to deploy your own self-hosted models where you can easily define amount of hardware resources (GPUs and CPUs) needed to run your model in production efficiently. Read more about available options including autoscaling in the Ray Serve documentation.

Setup ray serve

Install ray with pip install ray[serve].

General skeleton

The general skeleton for deploying a service is the following:

Example of deploying and OpenAI chain with custom prompts

Get an OpenAI API key from the OpenAI API keys page. By running the following code, you will be asked to provide your API key.
Now we can bind the deployment.
We can assign the port number and host when we want to run the deployment.
Now that service is deployed on port localhost:8282 we can send a post request to get the results back.