Class PromptTemplate

  • All Implemented Interfaces:

    
    public class 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.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      PromptTemplate(String template) Create a new PromptTemplate.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      String template()
      Prompt apply(Object value) Applies a value to a template containing a single variable.
      Prompt apply(Map<String, Object> variables) Applies multiple values to a template containing multiple variables.
      static PromptTemplate from(String template) Create a new PromptTemplate.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PromptTemplate

        PromptTemplate(String template)
        Create a new PromptTemplate.
        Parameters:
        template - the template string of the prompt.
    • Method Detail

      • apply

         Prompt apply(Object value)

        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

         Prompt apply(Map<String, Object> variables)

        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

         static PromptTemplate from(String template)

        Create a new PromptTemplate.

        Parameters:
        template - the template string of the prompt.
        Returns:

        the PromptTemplate.