Table of Contents

Class CompletionFilterContext

Namespace
LMKit.TextGeneration.Filters
Assembly
LM-Kit.NET.dll

Provides contextual information to ICompletionFilter implementations.

public sealed class CompletionFilterContext
Inheritance
CompletionFilterContext
Inherited Members

Examples

Transforming the completion result:

public async Task OnCompletionAsync(
    CompletionFilterContext context,
    Func<CompletionFilterContext, Task> next)
{
    await next(context);

    // Log the completion text
    Console.WriteLine($"[Completion] {context.Result.Completion}");
    Console.WriteLine($"[Tokens] {context.Result.GeneratedTokenCount}");
}

Remarks

The context is created after inference completes and flows through every registered completion filter. Filters can inspect, transform, or replace Result before it is returned to the caller.

The Properties dictionary is shared with the PromptFilterContext from the same submission, enabling cross-filter communication (e.g., a prompt filter stores metadata that a completion filter uses for caching or telemetry).

Properties

CancellationToken

Gets the cancellation token for this operation.

ChatHistory

Gets the full conversation history.

IsToolResponse

Gets a value indicating whether this completion was triggered by tool results rather than a fresh user message.

Prompt

Gets the original user prompt that was submitted (after any rewriting by prompt filters).

Properties

Gets the properties dictionary shared with the prompt filter context.

Result

Gets or sets the inference result.