yield data, which is sent downstream via the text/event-stream Content-Type.
You can send data in JSON format and decode it on the client side.
A minimal example:
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Stream live model output from a Cerebrium endpoint over server-sent events by yielding results from a Python generator or iterator function.
yield data, which is sent downstream via the text/event-stream Content-Type.
You can send data in JSON format and decode it on the client side.
A minimal example:
import time
def run(upper_range: int):
for i in range(upper_range):
yield f"Number {i} "
time.sleep(1)
curl -X POST 'https://api.cerebrium.ai/v4/p-xxxxxxxx/2-streaming-endpoint/run' \
-H 'Content-Type: application/json' \
-H 'Accept: text/event-stream' \
-H 'Authorization: Bearer <YOUR-JWT-TOKEN>' \
--data '{"upper_range": 3}'
HTTP/1.1 200 OK
cache-control: no-cache
content-encoding: gzip
content-type: text/event-stream; charset=utf-8
date: Tue, 28 May 2024 21:12:46 GMT
server: envoy
transfer-encoding: chunked
vary: Accept-Encoding
x-envoy-upstream-service-time: 198995
x-request-id: e6b55132-32af-96d7-a064-8915c4a42452
data: Number 0
...
...
data: Number 1
data: Number 2