runStream method
Stream<SyniRuntimeStreamChunk>
runStream(
- SyniRuntimeRequest request, {
- SyniPreset preset = SyniPreset.chat,
- int seed = 0,
Run inference and stream token chunks as they are generated.
Returns a Stream of SyniRuntimeStreamChunk:
- Zero or more SyniRuntimeStreamDelta events as tokens arrive.
- Exactly one SyniRuntimeStreamFinal at the end carrying the schema-validated final JSON.
- On failure: a stream error.
V1 does not support mid-stream cancellation — let the stream complete or close it on the consumer side and ignore further deltas.
Implementation
Stream<SyniRuntimeStreamChunk> runStream(
SyniRuntimeRequest request, {
SyniPreset preset = SyniPreset.chat,
int seed = 0,
}) async* {
await initialize();
if (_modelPath == null) {
throw SyniRuntimeError(
'Model not loaded. Call loadModel() or downloadModel() first.',
);
}
yield* _worker!.runStream(
preset.value,
seed,
jsonEncode(request.toJson()),
);
}