Table of Contents

Method ExtractKeywordsAsync

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

ExtractKeywordsAsync(string, CancellationToken)

Asynchronously extracts a set of keywords from the provided text content.

public Task<List<KeywordExtraction.KeywordItem>> ExtractKeywordsAsync(string content, CancellationToken cancellationToken = default)

Parameters

content string

The text content from which to extract keywords.

cancellationToken CancellationToken

A token to cancel the operation if needed.

Returns

Task<List<KeywordExtraction.KeywordItem>>

A task representing the asynchronous extraction operation that returns a list of extracted KeywordExtraction.KeywordItem instances upon completion.

Examples

using LMKit.Model;
using LMKit.TextAnalysis;
using System;
using System.Threading.Tasks;

async Task ExtractKeywordsExample()
{
    LM model = LM.LoadFromModelID("lmkit-tasks:4b-preview");
    KeywordExtraction extractor = new KeywordExtraction(model);

    var keywords = await extractor.ExtractKeywordsAsync("Renewable energy sources like solar and wind power are essential for sustainable development.");

    Console.WriteLine("Extracted keywords:");
    foreach (var keyword in keywords)
    {
        Console.WriteLine($"  - {keyword.Value}");
    }
}

Exceptions

ArgumentNullException

Thrown when the content is null or empty.

ExtractKeywordsAsync(Attachment, CancellationToken)

Asynchronously extracts a set of keywords from an image provided as an Attachment.

public Task<List<KeywordExtraction.KeywordItem>> ExtractKeywordsAsync(Attachment content, CancellationToken cancellationToken = default)

Parameters

content Attachment

The attachment representing the image from which to extract keywords.

cancellationToken CancellationToken

A token to cancel the operation if needed.

Returns

Task<List<KeywordExtraction.KeywordItem>>

A task representing the asynchronous extraction operation that returns a list of extracted KeywordExtraction.KeywordItem instances upon completion.

Examples

using LMKit.Model;
using LMKit.TextAnalysis;
using LMKit.Data;
using System;
using System.Threading.Tasks;

async Task ExtractFromImageAsync()
{
    LM model = LM.LoadFromModelID("lmkit-tasks:4b-preview");
    KeywordExtraction extractor = new KeywordExtraction(model);

    var imageAttachment = new Attachment("diagram.png");
    var keywords = await extractor.ExtractKeywordsAsync(imageAttachment);

    Console.WriteLine("Keywords from image:");
    foreach (var keyword in keywords)
    {
        Console.WriteLine($"  - {keyword.Value}");
    }
}

Exceptions

ArgumentNullException

Thrown when the attachment is null.

InvalidModelException

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