Class FewShotPromptTemplate
The FewShotPromptTemplate class allows developers to create prompts for natural language processing (NLP) models using few-shot learning techniques. This class takes in a prefix, examples, and suffix, and combines them with a separator to generate a prompt for the language model.
Inheritance
Implements
Inherited Members
Namespace: DotnetPrompt.Prompts
Assembly: DotnetPrompt.dll
Syntax
public class FewShotPromptTemplate : IPromptTemplate
Constructors
| Improve this Doc View SourceFewShotPromptTemplate(IPromptTemplate, IPromptTemplate, IPromptTemplate, IExampleSelector)
Constructor with example selector and prefix
Declaration
public FewShotPromptTemplate(IPromptTemplate prefixPromptTemplate, IPromptTemplate examplePromptTemplate, IPromptTemplate suffixPromptTemplate, IExampleSelector exampleSelector)
Parameters
Type | Name | Description |
---|---|---|
IPromptTemplate | prefixPromptTemplate | PromptTemplate to format prefix |
IPromptTemplate | examplePromptTemplate | PromptTemplate to format Example |
IPromptTemplate | suffixPromptTemplate | PromptTemplate to format suffix |
IExampleSelector | exampleSelector | Example selector that will select examples for prompt |
FewShotPromptTemplate(IPromptTemplate, IPromptTemplate, IPromptTemplate, IList<IDictionary<string, string>>)
Constructor with examples and prefix
Declaration
public FewShotPromptTemplate(IPromptTemplate prefixPromptTemplate, IPromptTemplate examplePromptTemplate, IPromptTemplate suffixPromptTemplate, IList<IDictionary<string, string>> examples)
Parameters
Type | Name | Description |
---|---|---|
IPromptTemplate | prefixPromptTemplate | PromptTemplate to format prefix |
IPromptTemplate | examplePromptTemplate | PromptTemplate to format Example |
IPromptTemplate | suffixPromptTemplate | PromptTemplate to format suffix |
IList<IDictionary<string, string>> | examples | List of Examples |
FewShotPromptTemplate(IPromptTemplate, IPromptTemplate, IExampleSelector)
Constructor with example selector
Declaration
public FewShotPromptTemplate(IPromptTemplate examplePromptTemplate, IPromptTemplate suffixPromptTemplate, IExampleSelector exampleSelector)
Parameters
Type | Name | Description |
---|---|---|
IPromptTemplate | examplePromptTemplate | PromptTemplate to format Example |
IPromptTemplate | suffixPromptTemplate | PromptTemplate to format suffix |
IExampleSelector | exampleSelector | Example selector that will select examples for prompt |
FewShotPromptTemplate(IPromptTemplate, IPromptTemplate, IList<IDictionary<string, string>>)
Constructor with examples
Declaration
public FewShotPromptTemplate(IPromptTemplate examplePromptTemplate, IPromptTemplate suffixPromptTemplate, IList<IDictionary<string, string>> examples)
Parameters
Type | Name | Description |
---|---|---|
IPromptTemplate | examplePromptTemplate | PromptTemplate to format Example |
IPromptTemplate | suffixPromptTemplate | PromptTemplate to format suffix |
IList<IDictionary<string, string>> | examples | List of Examples |
Properties
| Improve this Doc View SourceExamples
List of Examples, where each example is a Dictionary where key is Input Variable and value is Input Value
Declaration
public IList<IDictionary<string, string>>? Examples { get; init; }
Property Value
Type | Description |
---|---|
IList<IDictionary<string, string>> |
ExampleSeparator
Separator for examples, default value is "\n\n"
Declaration
public string ExampleSeparator { get; set; }
Property Value
Type | Description |
---|---|
string |
InputVariables
A list of the names of the variables the prompt template expects.
Declaration
public IList<string> InputVariables { get; init; }
Property Value
Type | Description |
---|---|
IList<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. |