Table of Contents

Method TryParse

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

TryParse(string, out PromptTemplate, out IReadOnlyList<string>, PromptTemplateOptions)

Tries to parse a template string, returning false on syntax errors instead of throwing an exception.

public static bool TryParse(string template, out PromptTemplate result, out IReadOnlyList<string> errors, PromptTemplateOptions options = null)

Parameters

template string

The template string to parse.

result PromptTemplate

When this method returns true, contains the compiled template.

errors IReadOnlyList<string>

When this method returns false, contains the list of syntax errors.

options PromptTemplateOptions

Optional parsing and rendering options.

Returns

bool

true if parsing succeeded; otherwise, false.

Examples

if (PromptTemplate.TryParse(input, out var template, out var errors))
{
    string rendered = template.Render(context);
}
else
{
    foreach (string error in errors)
        Console.WriteLine(error);
}