Class PromptTemplateFilters
- Namespace
- LMKit.TextGeneration.Prompts
- Assembly
- LM-Kit.NET.dll
Provides the built-in filter registry for template expressions.
Filters transform variable values using the pipe syntax: {{variable|filter}}.
public static class PromptTemplateFilters
- Inheritance
-
PromptTemplateFilters
- Inherited Members
Examples
Registering a custom global filter:
using LMKit.TextGeneration.Prompts;
PromptTemplateFilters.Register("shout", (value, args) => value.ToUpper() + "!!!");
var template = PromptTemplate.Parse("{{message|shout}}");
string result = template.Render(new PromptTemplateContext { ["message"] = "hello" });
// "HELLO!!!"
Remarks
Built-in filters:
upper: Convert to uppercase.lower: Convert to lowercase.trim: Remove leading and trailing whitespace.capitalize: Capitalize the first letter, lowercase the rest.title: Title Case each word.length: Return the character count as a string.reverse: Reverse the string.truncate:N: Truncate to N characters with ellipsis.replace:old:new: Replace all occurrences ofoldwithnew.default:value: Usevalueif the input is null or empty.json: Escape the value for safe JSON embedding.
Filters can be chained: {{name|trim|upper|truncate:20}}.
Methods
- Register(string, Func<string, string[], string>)
Registers a custom global filter available to all templates.
- Unregister(string)
Removes a previously registered custom filter.