Ollama4j
A Java library (wrapper/binding) for Ollama server.
Loading...
Searching...
No Matches
io.github.ollama4j.utils.PromptBuilder Class Reference

Public Member Functions

 PromptBuilder ()
 
PromptBuilder add (String text)
 
PromptBuilder addLine (String text)
 
PromptBuilder addSeparator ()
 
String build ()
 

Detailed Description

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);

Definition at line 19 of file PromptBuilder.java.

Constructor & Destructor Documentation

◆ PromptBuilder()

io.github.ollama4j.utils.PromptBuilder.PromptBuilder ( )

Constructs a new PromptBuilder with an empty prompt.

Definition at line 24 of file PromptBuilder.java.

Member Function Documentation

◆ add()

PromptBuilder io.github.ollama4j.utils.PromptBuilder.add ( String text)

Appends the specified text to the prompt.

Parameters
textthe text to be added to the prompt
Returns
a reference to this PromptBuilder instance for method chaining

Definition at line 34 of file PromptBuilder.java.

◆ addLine()

PromptBuilder io.github.ollama4j.utils.PromptBuilder.addLine ( String text)

Appends the specified text followed by a newline character to the prompt.

Parameters
textthe text to be added as a line to the prompt
Returns
a reference to this PromptBuilder instance for method chaining

Definition at line 45 of file PromptBuilder.java.

◆ addSeparator()

PromptBuilder io.github.ollama4j.utils.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

Definition at line 56 of file PromptBuilder.java.

◆ build()

String io.github.ollama4j.utils.PromptBuilder.build ( )

Builds and returns the final prompt as a string.

Returns
the final prompt as a string

Definition at line 66 of file PromptBuilder.java.


The documentation for this class was generated from the following file: