Table of Contents

Method SummarizeAsync

Namespace
LMKit.TextGeneration
Assembly
LM-Kit.NET.dll

SummarizeAsync(string, CancellationToken)

Asynchronously generates a summary from the provided content.

public Task<Summarizer.SummarizerResult> SummarizeAsync(string content, CancellationToken cancellationToken = default)

Parameters

content string

The input text to be summarized.

cancellationToken CancellationToken

An optional cancellation token that can be used to cancel the operation.

Returns

Task<Summarizer.SummarizerResult>

A task that represents the asynchronous operation, containing a Summarizer.SummarizerResult with the summary.

Examples

// Summarizing text retrieved from a web API asynchronously.
var model = LM.LoadFromModelID("gemma3:4b");
var summarizer = new LMKit.TextGeneration.Summarizer(model)
{
    MaxTitleWords = 8,
    MaxContentWords = 250
};

// Assume FetchArticleAsync fetches text from a remote source
string articleContent = await FetchArticleAsync("https://example.com/article");

var result = await summarizer.SummarizeAsync(articleContent);
Console.WriteLine("Generated Title: " + result.Title);
Console.WriteLine("Generated Summary: " + result.Content);

Exceptions

ArgumentException

Thrown if the provided content is null or empty.

SummarizeAsync(Attachment, CancellationToken)

Asynchronously generates a summary from an image provided as an Attachment.

public Task<Summarizer.SummarizerResult> SummarizeAsync(Attachment content, CancellationToken cancellationToken = default)

Parameters

content Attachment

The image attachment to be summarized.

cancellationToken CancellationToken

An optional cancellation token that can be used to cancel the operation.

Returns

Task<Summarizer.SummarizerResult>

A task representing the asynchronous operation, containing a Summarizer.SummarizerResult with the generated title and/or summary content derived from the image.

Examples

// Asynchronously summarize an image.
var model = LM.LoadFromModelID("gemma3:4b");
var summarizer = new LMKit.TextGeneration.Summarizer(model);
var imageAttachment = new Attachment("path/to/image.jpg");
var summaryResult = await summarizer.SummarizeAsync(imageAttachment);
Console.WriteLine("Image Summary: " + summaryResult.Content);

Exceptions

ArgumentException

Thrown if the provided image attachment is null.

InvalidModelException

Thrown when the underlying language model does not support vision input, which is required for analyzing image attachments.

SummarizeAsync(ImageBuffer, CancellationToken)

Asynchronously generates a summary from the specified image.

public Task<Summarizer.SummarizerResult> SummarizeAsync(ImageBuffer content, CancellationToken cancellationToken = default)

Parameters

content ImageBuffer

The ImageBuffer representing the image to summarize; cannot be null.

cancellationToken CancellationToken

A CancellationToken used to cancel the operation.

Returns

Task<Summarizer.SummarizerResult>

A Task<TResult> that resolves to a Summarizer.SummarizerResult containing the generated title and/or summary derived from the image.

Examples

var model = LM.LoadFromModelID("gemma3:4b");
var summarizer = new LMKit.TextGeneration.Summarizer(model);
var buffer = ImageBuffer.LoadAsRGB("path/to/image.jpg");
SummarizerResult result = await summarizer.SummarizeAsync(buffer);
Console.WriteLine("Summary: " + result.Content);

Exceptions

ArgumentException

Thrown if content is null.

InvalidModelException

Thrown if the underlying model does not support vision input.