Method Summarize
- Namespace
- LMKit.TextGeneration
- Assembly
- LM-Kit.NET.dll
Summarize(string, CancellationToken)
Generates a summary from the provided text content synchronously.
public Summarizer.SummarizerResult Summarize(string content, CancellationToken cancellationToken = default)
Parameters
contentstringThe input text to be summarized.
cancellationTokenCancellationTokenAn optional cancellation token for the operation.
Returns
- Summarizer.SummarizerResult
An instance of Summarizer.SummarizerResult containing the title and/or content summary.
Examples
// Summarizing user input from the console.
var model = LM.LoadFromModelID("lmkit-tasks:4b-preview");
var summarizer = new LMKit.TextGeneration.Summarizer(model)
{
GenerateTitle = true,
GenerateContent = true
};
Console.WriteLine("Please enter text to summarize:");
string userInput = Console.ReadLine();
var summaryResult = summarizer.Summarize(userInput);
Console.WriteLine("Title: " + summaryResult.Title);
Console.WriteLine("Summary: " + summaryResult.Content);
Exceptions
- ArgumentException
Thrown if the provided content is
nullor empty.- Exception
Propagates any exceptions that occur during summarization.
Summarize(Attachment, CancellationToken)
Generates a summary from an Attachment synchronously.
public Summarizer.SummarizerResult Summarize(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 for the operation.
Returns
- Summarizer.SummarizerResult
An instance of Summarizer.SummarizerResult containing the generated title and/or summary content derived from the attachment.
Examples
// Synchronously 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 = summarizer.Summarize(imageAttachment);
Console.WriteLine("Image Summary: " + summaryResult.Content);
// Synchronously summarize a PDF document.
var model = LM.LoadFromModelID("lmkit-tasks:4b-preview");
var summarizer = new LMKit.TextGeneration.Summarizer(model);
var pdfAttachment = new Attachment("path/to/document.pdf");
var summaryResult = summarizer.Summarize(pdfAttachment);
Console.WriteLine("PDF 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.
Summarize(ImageBuffer, CancellationToken)
Synchronously generates a summary from the specified image.
public Summarizer.SummarizerResult Summarize(ImageBuffer content, CancellationToken cancellationToken = default)
Parameters
contentImageBufferThe ImageBuffer representing the image to summarize; cannot be
null.cancellationTokenCancellationTokenA CancellationToken used to cancel the operation.
Returns
- Summarizer.SummarizerResult
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 = summarizer.Summarize(buffer);
Console.WriteLine("Summary: " + result.Content);
Exceptions
- ArgumentException
Thrown if
contentisnull.- InvalidModelException
Thrown if the underlying model does not support vision input.