Class PromptTemplate
Schema to represent a prompt for an LLM based on formatted string
Inheritance
Implements
Inherited Members
Namespace: DotnetPrompt.Prompts
Assembly: DotnetPrompt.dll
Syntax
public class PromptTemplate : IPromptTemplate
Constructors
| Improve this Doc View SourcePromptTemplate(string, IList<string>)
Build PromptTemplate Schema from template string and inputVariables
Declaration
public PromptTemplate(string template, IList<string> inputVariables)
Parameters
Type | Name | Description |
---|---|---|
string | template | Template string |
IList<string> | inputVariables | List of input variables |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Throws when list of input variables is invalid |
PromptTemplate(string)
Build PromptTemplate Schema from template string
Declaration
public PromptTemplate(string template)
Parameters
Type | Name | Description |
---|---|---|
string | template |
Properties
| Improve this Doc View SourceInputVariables
A list of the names of the variables the prompt template expects.
Declaration
public IList<string> InputVariables { get; set; }
Property Value
Type | Description |
---|---|
IList<string> |
Template
The prompt template.
Declaration
public string Template { get; set; }
Property Value
Type | Description |
---|---|
string |
Methods
| Improve this Doc View SourceFormat(IDictionary<string, string>?)
Build a prompt from current template and a list of values.
Declaration
public string Format(IDictionary<string, string>? values = null)
Parameters
Type | Name | Description |
---|---|---|
IDictionary<string, string> | values | Key-Value list of values to use to build prompt. |
Returns
Type | Description |
---|---|
string | String prompt |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Throws when provided list of keys does not match InputVariables. |
Format((string, string)[])
Build a prompt from current template and a list of value tuples.
Declaration
public string Format((string, string)[] values)
Parameters
Type | Name | Description |
---|---|---|
(string, string)[] | values | Tuple of key - value |
Returns
Type | Description |
---|---|
string |
FromExamples(List<string>, string, List<string>, string, string)
Take examples in list format with prefix and suffix to create a prompt. Intended be used as a way to dynamically create a prompt from examples
Declaration
public static PromptTemplate FromExamples(List<string> examples, string suffix, List<string> inputVariables, string prefix = "", string exampleSeparator = "\n\n")
Parameters
Type | Name | Description |
---|---|---|
List<string> | examples | List of examples to use in the prompt. |
string | suffix | String to go after the list of examples. Should generally set up the user's input. |
List<string> | inputVariables | A list of variable names the final prompt template will expect. |
string | prefix | String that should go before any examples. Generally includes examples. Default to an empty string |
string | exampleSeparator | The separator to use in between examples. Defaults to two new line characters. |
Returns
Type | Description |
---|---|
PromptTemplate | The final prompt generated. |
Remarks
Verbatum string on windows will produce \r\n
and that need to be handled somehow (todo).
FromFile(string, string[])
Load a prompt from a file.
Declaration
public static PromptTemplate FromFile(string templateFile, string[] inputVariables)
Parameters
Type | Name | Description |
---|---|---|
string | templateFile | The path to the file containing the prompt template. |
string[] | inputVariables | A list of variable names the final prompt template will expect. |
Returns
Type | Description |
---|---|
PromptTemplate | The prompt loaded from the file. |