Class PromptBuilder
java.lang.Object
io.github.amithkoujalgi.ollama4j.core.utils.PromptBuilder
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAppends the specified text to the prompt.Appends the specified text followed by a newline character to the prompt.Appends a separator line to the prompt.build()
Builds and returns the final prompt as a string.
-
Constructor Details
-
PromptBuilder
public PromptBuilder()Constructs a newPromptBuilder
with an empty prompt.
-
-
Method Details
-
add
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
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
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
Builds and returns the final prompt as a string.- Returns:
- the final prompt as a string
-