Class PromptBuilder

java.lang.Object
io.github.amithkoujalgi.ollama4j.core.utils.PromptBuilder

public class PromptBuilder extends Object
The PromptBuilder class is used to construct prompt texts for language models (LLMs). It provides methods for adding text, adding lines, adding separators, and building the final prompt.

Example usage:


 PromptBuilder promptBuilder = new PromptBuilder();
 promptBuilder.add("This is a sample prompt for language models.")
              .addLine("You can add lines to provide context.")
              .addSeparator()
              .add("Feel free to customize as needed.");
 String finalPrompt = promptBuilder.build();
 System.out.println(finalPrompt);
 
  • Constructor Details

    • PromptBuilder

      public PromptBuilder()
      Constructs a new PromptBuilder with an empty prompt.
  • Method Details

    • add

      public PromptBuilder add(String text)
      Appends the specified text to the prompt.
      Parameters:
      text - the text to be added to the prompt
      Returns:
      a reference to this PromptBuilder instance for method chaining
    • addLine

      public PromptBuilder addLine(String text)
      Appends the specified text followed by a newline character to the prompt.
      Parameters:
      text - the text to be added as a line to the prompt
      Returns:
      a reference to this PromptBuilder instance for method chaining
    • addSeparator

      public PromptBuilder addSeparator()
      Appends a separator line to the prompt. The separator is a newline followed by a line of dashes.
      Returns:
      a reference to this PromptBuilder instance for method chaining
    • build

      public String build()
      Builds and returns the final prompt as a string.
      Returns:
      the final prompt as a string