Package dev.langchain4j.model.input
Class PromptTemplate
java.lang.Object
dev.langchain4j.model.input.PromptTemplate
Represents a template of a prompt that can be reused multiple times.
A template typically contains one or more variables (placeholders) defined as {{variable_name}} that are
replaced with actual values to produce a Prompt.
Special variables {{current_date}}, {{current_time}}, and {{current_date_time}} are automatically
filled with LocalDate.now(), LocalTime.now(), and LocalDateTime.now() respectively.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionApplies a value to a template containing a single variable.Applies multiple values to a template containing multiple variables.static PromptTemplate
Create a new PromptTemplate.template()
-
Constructor Details
-
PromptTemplate
Create a new PromptTemplate.The
Clock
will be the system clock.- Parameters:
template
- the template string of the prompt.
-
-
Method Details
-
template
- Returns:
- A prompt template string.
-
apply
Applies a value to a template containing a single variable. The single variable should have the name {{it}}.- Parameters:
value
- The value that will be injected in place of the {{it}} placeholder in the template.- Returns:
- A Prompt object where the {{it}} placeholder in the template has been replaced by the provided value.
-
apply
Applies multiple values to a template containing multiple variables.- Parameters:
variables
- A map of variable names to values that will be injected in place of the corresponding placeholders in the template.- Returns:
- A Prompt object where the placeholders in the template have been replaced by the provided values.
-
from
Create a new PromptTemplate.- Parameters:
template
- the template string of the prompt.- Returns:
- the PromptTemplate.
-