Skip to main content
This example is only compatible with CLI v1.20 and later. Should you be making use of an older version of the CLI, please run pip install --upgrade cerebrium to upgrade it to the latest version.
This tutorial covers implementing streaming with Server-Sent Events (SSE) to return results as quickly as possible. To see the final implementation, you can view it here

Basic Setup

Developing on Cerebrium is similar to a virtual machine or Google Colab. Install the Cerebrium package and log in before proceeding. See the installation docs for details. First, create your project:
Add the following packages to the [cerebrium.dependencies.pip] section of your cerebrium.toml file:
Create a main.py file. This implementation fits in a single file. Start by defining the request object:
Pydantic handles data validation. The prompt parameter is required; others are optional with default values. A missing prompt triggers an automatic error message.

Falcon Implementation

Model Setup

The tokenizer and model instantiate outside the predict function, ensuring model weights load only once at startup.

Streaming Implementation

The stream function handles streaming results from the endpoint:
The function receives inputs from the request object and uses TextIteratorStreamer to stream model output. The yield keyword returns output as it generates.

Deploy

Configure your compute and environment settings in cerebrium.toml:
Deploy the model using this command:
After deployment, make this request:
The endpoint path should include stream since that is the function name.
The model outputs as Server-Sent Events (SSE). Here’s an example from Postman: Streaming