Table of Contents

Method ExtractKeywords

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

ExtractKeywords(string, CancellationToken)

Extracts a set of keywords synchronously from the given text content.

public List<KeywordExtraction.KeywordItem> ExtractKeywords(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

List<KeywordExtraction.KeywordItem>

A list of extracted KeywordExtraction.KeywordItem instances.

Examples

using LMKit.Model;
using LMKit.TextAnalysis;
using System;

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

var keywords = extractor.ExtractKeywords("Artificial intelligence is revolutionizing the automotive industry with self-driving cars.");
foreach (var keyword in keywords)
{
    Console.WriteLine(keyword.Value);
}

Exceptions

ArgumentNullException

Thrown when the content is null or empty.

ExtractKeywords(Attachment, CancellationToken)

Extracts a set of keywords synchronously from an image provided as an Attachment.

public List<KeywordExtraction.KeywordItem> ExtractKeywords(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

List<KeywordExtraction.KeywordItem>

A list of extracted KeywordExtraction.KeywordItem instances.

Examples

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

// Load a vision-capable model
LM model = LM.LoadFromModelID("lmkit-tasks:4b-preview");
KeywordExtraction extractor = new KeywordExtraction(model);

// Extract keywords from an image
var imageAttachment = new Attachment("product_photo.jpg");
var keywords = extractor.ExtractKeywords(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.