Method SummarizeAsync
- Namespace
- LMKit.TextGeneration
- Assembly
- LM-Kit.NET.dll
SummarizeAsync(string, CancellationToken)
Asynchronously generates a summary from the provided text content.
public Task<Summarizer.SummarizerResult> SummarizeAsync(string content, CancellationToken cancellationToken = default)
Parameters
contentstringThe input text to be summarized.
cancellationTokenCancellationTokenAn 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("lmkit-tasks:4b-preview");
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
nullor empty.
SummarizeAsync(Attachment, CancellationToken)
Asynchronously generates a summary from an Attachment.
public Task<Summarizer.SummarizerResult> SummarizeAsync(Attachment content, CancellationToken cancellationToken = default)
Parameters
contentAttachmentThe attachment to be summarized. Supports various file formats including images, PDF documents, HTML files, and Microsoft Office formats. See Attachment for the complete list of supported formats.
cancellationTokenCancellationTokenAn 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 attachment.
Examples
// Asynchronously summarize an image.
var model = LM.LoadFromModelID("lmkit-tasks:4b-preview");
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);
// Asynchronously summarize a Word document.
var model = LM.LoadFromModelID("lmkit-tasks:4b-preview");
var summarizer = new LMKit.TextGeneration.Summarizer(model);
var docxAttachment = new Attachment("path/to/report.docx");
var summaryResult = await summarizer.SummarizeAsync(docxAttachment);
Console.WriteLine("Document Title: " + summaryResult.Title);
Console.WriteLine("Document Summary: " + summaryResult.Content);
Exceptions
- ArgumentException
Thrown if the provided attachment is
null.- InvalidModelException
Thrown when the attachment contains visual content requiring vision input but the underlying language model does not support vision.
SummarizeAsync(ImageBuffer, CancellationToken)
Asynchronously generates a summary from the specified image.
public Task<Summarizer.SummarizerResult> SummarizeAsync(ImageBuffer content, CancellationToken cancellationToken = default)
Parameters
contentImageBufferThe ImageBuffer representing the image to summarize; cannot be
null.cancellationTokenCancellationTokenA 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("lmkit-tasks:4b-preview");
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
contentisnull.- InvalidModelException
Thrown if the underlying model does not support vision input.