Table of Contents

Class StructuredStreamRun<T>

Namespace
Mythosia.AI.Models.Streaming
Assembly
Mythosia.AI.dll

Represents a running streaming request whose final response will be deserialized to T.

The stream starts eagerly in the background on construction. Call Stream(CancellationToken) to observe text chunks in real-time (optional). Await Result to get the deserialized object after the stream completes (with auto-repair retries if the JSON is invalid).

Usage:

var run = service.BeginStream(prompt)
    .WithStructuredOutput(new StructuredOutputPolicy { MaxRepairAttempts = 2 })
    .As<MyDto>();

await foreach (var chunk in run.Stream(ct)) Console.Write(chunk);

MyDto dto = await run.Result;

public sealed class StructuredStreamRun<T> where T : class

Type Parameters

T

The POCO type to deserialize the LLM response into.

Inheritance
StructuredStreamRun<T>
Inherited Members

Properties

Result

Awaitable result that completes after the stream finishes and the response has been deserialized (with auto-repair retries if needed).

Safe to access before, during, or after Stream(CancellationToken) enumeration. If Stream(CancellationToken) was never called, the buffer is still accumulated internally and the result is produced normally.

public Task<T> Result { get; }

Property Value

Task<T>

Methods

Stream(CancellationToken)

Enumerate streaming text chunks as they arrive from the LLM.

Can only be called once; a second call throws InvalidOperationException. Calling this method is optional โ€” Result works without it.

public IAsyncEnumerable<string> Stream(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

IAsyncEnumerable<string>