Class PromptBuilder
- java.lang.Object
-
- io.github.amithkoujalgi.ollama4j.core.utils.PromptBuilder
-
public class PromptBuilder extends Object
ThePromptBuilderclass 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 Summary
Constructors Constructor Description PromptBuilder()Constructs a newPromptBuilderwith an empty prompt.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PromptBuilderadd(String text)Appends the specified text to the prompt.PromptBuilderaddLine(String text)Appends the specified text followed by a newline character to the prompt.PromptBuilderaddSeparator()Appends a separator line to the prompt.Stringbuild()Builds and returns the final prompt as a string.
-
-
-
Method Detail
-
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
PromptBuilderinstance 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
PromptBuilderinstance 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
PromptBuilderinstance for method chaining
-
build
public String build()
Builds and returns the final prompt as a string.- Returns:
- the final prompt as a string
-
-