Streaming in Muna is designed to be highly intuitive to use. We fully separate how a prediction function
is implemented (i.e. eager vs generator functions) from how the function might be consumed
(i.e. creating vs. streaming). Consider these two predictors:
Copy
def predict(): return "hello from Muna"
You can choose how to consume a prediction function depending on what works best for your user experience.
You donβt have to care about the underlying function!
Here are the reuslts of creating vs. streaming each function at runtime:
Creating Predictions with eager.py
In this case, the single prediction is returned:
Copy
// Create a prediction with the eager predictorconst prediction = await muna.predictions.create({ tag: "@muna/eager", inputs: { }});// Display the resultsconsole.log(prediction.results[0]);// Outputs:// "hello from Muna"
Creating Predictions with generator.py
In this case, the Muna client will consume all partial predictions yielded
by the predictor then return the very last one:
Copy
// Create a prediction with the streaming predictorconst prediction = await muna.predictions.create({ tag: "@muna/generator", inputs: { }});// Display the resultsconsole.log(prediction.results[0]);// Outputs:// "hello from Muna"
Streaming Predictions with eager.py
In this case, the Muna client will return a prediction stream with the single prediction returned by the predictor:
Copy
// Create a prediction stream with the eager predictorconst stream = await muna.predictions.stream({ tag: "@muna/eager", inputs: { }});// Display the resultsfor await (const prediction of stream) console.log(prediction.results[0]);// Outputs:// "hello from Muna"
Streaming Predictions with generator.py
In this case, the Muna client will provide a prediction stream containing all
partial predictions yielded by the predictor:
Copy
// Create a prediction stream with the generator predictorconst stream = await muna.predictions.stream({ tag: "@muna/generator", inputs: { }});// Display the resultsfor await (const prediction of stream) console.log(prediction.results[0]);// Outputs:// "hello"// "hello from"// "hello from Muna"