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
stringThe input text to be summarized.
cancellationToken
CancellationTokenAn 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 = new LMKit.Model.LM("api-model.gguf");
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
AttachmentThe image attachment to be summarized.
cancellationToken
CancellationTokenAn 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 = new LMKit.Model.LM("vision-model.gguf");
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.