loading
Warning:
Chromium only, model downloaded on first use Probe Availability, Create from a user gesture, and dispose the session. See LanguageModel for the whole story.
Note:
Labels and explanations are the runtime's to give A correction carries Types ("spelling", "grammar", and so on) and an Explanation when the runtime supplies them, and both are empty when it doesn't - Chromium currently labels nothing. The explainer's includeCorrectionTypes and includeCorrectionExplanations switches are not exposed, because no implementation honours them.

Support and availability

IsSupported / Availability

Availability answers whether a proofreader with these options can be created - Available, Downloadable, Downloading or Unavailable.

C#
@inject Bit.Butil.Proofreader proofreader

var availability = await proofreader.Availability();
Live sample
availability output
Results will appear here when you interact with the samples.

Create and proofread

Create / ProofreaderSession.Proofread

The result carries the whole corrected text plus each change located in the original by StartIndex and EndIndex - which is what lets you highlight the span rather than diffing two strings.

C#
await using var session = await proofreader.Create(new ProofreaderOptions
{
    ExpectedInputLanguages = ["en"]
});

var result = session is null ? null : await session.Proofread(text);

foreach (var correction in result?.Corrections ?? [])
{
    Highlight(correction.StartIndex, correction.EndIndex, correction.Correction, correction.Types);
}
Live sample
Text to proofread
proofread 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 Proofreader API.
Availability
ValueTask<AiAvailability> Availability() / Availability(ProofreaderOptions options)
Whether a proofreader can be created right now, and whether that means a download first.
Create
ValueTask<ProofreaderSession?> Create(ProofreaderOptions? options = null, Action<double>? onDownloadProgress = null)
Creates a proofreader. Call from a user gesture; the first creation downloads the model.
Session.Proofread
ValueTask<ProofreadResult?> Proofread(string input)
Corrects a piece of text and reports each change positioned in the original.
Session.DisposeAsync
ValueTask DisposeAsync()
Destroys the model instance and frees what it holds. Always dispose.
An unhandled error has occurred. Reload 🗙