loading
Warning:
Chromium only, model downloaded on first use Same shape as every built-in AI API: probe Availability, Create from a user gesture (the first creation downloads the model), summarize, and dispose the session. See LanguageModel for the whole story.

Support and availability

IsSupported / Availability

Availability answers whether these particular options can be served - the summary type, format, length and languages you intend to ask for.

C#
@inject Bit.Butil.Summarizer summarizer

var availability = await summarizer.Availability(
    new SummarizerOptions { Type = "key-points", Length = "short" });
Live sample
availability output
Results will appear here when you interact with the samples.

Create a summarizer

Create

Type is what kind of summary (key-points, tldr, teaser, headline), Length how long (short, medium, long), Format markdown or plain-text, and SharedContext what every document in this session is - which is the option that most improves the result.

C#
_session = await summarizer.Create(new SummarizerOptions
{
    Type = "key-points",
    Length = "short",
    Format = "plain-text",
    SharedContext = "Release notes for a .NET library, summarised for developers."
});
Live sample
session output
Results will appear here when you interact with the samples.

Summarize

SummarizerSession.Summarize / SummarizeStreaming

Summarize waits for the whole result; SummarizeStreaming reports it as it is produced, which is what a UI should use for anything longer than a paragraph. The per-call context argument describes this one document, on top of the session's shared context.

Razor
<p>@_summary</p>

@code {
    private string _summary = "";
    private SummarizerSession? _session;   // from Create

    private async Task Run(string article)
    {
        var summary = await _session!.Summarize(article, context: "A conference talk abstract.");

        // or, streaming - the first words arrive long before the last:
        _summary = "";
        await _session.SummarizeStreaming(article, chunk =>
        {
            _summary += chunk;
            InvokeAsync(StateHasChanged);
        });
    }
}
Live sample
Text to summarize
summarize output
Results will appear here when you interact with the samples.

API reference

Member
Signature
Description
IsSupported
ValueTask<bool> IsSupported()
True when the runtime exposes the Summarizer API.
Availability
ValueTask<AiAvailability> Availability() / Availability(SummarizerOptions options)
Whether a session can be created right now, and whether that means downloading the model first.
Create
ValueTask<SummarizerSession?> Create(SummarizerOptions? options = null, Action<double>? onDownloadProgress = null)
Creates a summarizer. Call from a user gesture; the first creation downloads the model.
Session.Summarize
ValueTask<string?> Summarize(string input, string? context = null)
Summarizes a piece of text and waits for the whole result.
Session.SummarizeStreaming
Task<string> SummarizeStreaming(string input, Action<string>? onChunk = null, string? context = null)
Summarizes a piece of text, reporting the summary as it is generated.
Session.DisposeAsync
ValueTask DisposeAsync()
Destroys the model instance and frees what it holds. Always dispose.
An unhandled error has occurred. Reload 🗙