Table of Contents

Class PromptTemplateContext

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

Provides variable values, objects, and custom helpers for template rendering.

public sealed class PromptTemplateContext
Inheritance
PromptTemplateContext
Inherited Members

Examples

Setting variables and helpers:

using LMKit.TextGeneration.Prompts;

var context = new PromptTemplateContext
{
    ["name"] = "Alice",
    ["items"] = new[] { "one", "two", "three" },
    ["user"] = new { Name = "Bob", Age = 30 }
};

// Fluent API
context.Set("language", "English")
       .Set("verbose", true);

// Custom helper
context.RegisterHelper("date", args =>
{
    string format = args.Length > 0 ? args[0]?.ToString() : "yyyy-MM-dd";
    return DateTime.Now.ToString(format);
});

Remarks

Variables can be any .NET object: strings, numbers, booleans, arrays, lists, dictionaries, or anonymous types. Dot-notation in templates resolves nested properties via reflection (e.g., {{user.name}}).

Properties

this[string]

Gets or sets a variable value by name.

Methods

RegisterHelper(string, PromptTemplateHelper)

Registers a custom helper function callable from the template.

Set(string, object)

Sets a variable and returns this context for method chaining.