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
templatestringThe template string to parse.
resultPromptTemplateWhen this method returns true, contains the compiled template.
errorsIReadOnlyList<string>When this method returns false, contains the list of syntax errors.
optionsPromptTemplateOptionsOptional parsing and rendering options.
Returns
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);
}