Last updated
Last updated
The PromptTemplate
class is part of the ai.knowly.langtoch.prompt.template
package. It represents a string template with variables that can be replaced with specified values. The template uses the format {{$var}}
for variables, where variables must be one or more word characters (letters, digits, or underscores).
To create an instance of the PromptTemplate
, use the builder()
method to create a new Builder
object. Use the builder's methods to set the template, examples, example header, and variables as needed, then call build()
to create the PromptTemplate
.
The format()
method replaces the variables in the template with their corresponding values and returns the formatted string. If an optional example header and examples are provided, they are included in the formatted string.
The Builder
class is an inner class of PromptTemplate
. It is used to create instances of the PromptTemplate
class. The following methods are available:
Sets the template string containing variables in the form of {{$var}}
.
Sets a list of strings to be used as examples for few-shot prompting.
Sets an optional string that can be used to describe the examples.
Adds a variable name-value pair to the variables map.
Adds all variable name-value pairs from the provided map to the variables map.
Creates and returns a new instance of the PromptTemplate
class with the specified values.