Package nl.dannyj.mistral.builders
Class MessageListBuilder
java.lang.Object
nl.dannyj.mistral.builders.MessageListBuilder
A builder class for creating a list of
ChatMessage
objects for a chat completion request.
Provides convenience methods for adding messages with different roles and content types.-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor that initializes an empty list of ChatMessage objects.MessageListBuilder
(List<ChatMessage> messages) Constructor that initializes the list of ChatMessage objects with a provided list. -
Method Summary
Modifier and TypeMethodDescriptionAdds an assistant message with tool calls to the list.Adds an assistant message with text content to the list.build()
Returns the list of ChatMessage objects that have been added.message
(@NonNull ChatMessage message) Adds a pre-constructed ChatMessage object to the list.Adds a system message to the list with the provided content.Adds a tool message with text content to the list.Adds a user message with text content to the list.
-
Constructor Details
-
MessageListBuilder
public MessageListBuilder()Default constructor that initializes an empty list of ChatMessage objects. -
MessageListBuilder
Constructor that initializes the list of ChatMessage objects with a provided list.- Parameters:
messages
- The initial list of ChatMessage objects.
-
-
Method Details
-
system
Adds a system message to the list with the provided content.- Parameters:
content
- The text content of the system message. Cannot be null.- Returns:
- This builder instance.
-
assistant
Adds an assistant message with text content to the list.- Parameters:
content
- The text content of the assistant message. Cannot be null.- Returns:
- This builder instance.
-
assistant
Adds an assistant message with tool calls to the list.- Parameters:
toolCalls
- The list of tool calls. Cannot be null or empty.- Returns:
- This builder instance.
-
user
Adds a user message with text content to the list.- Parameters:
content
- The text content of the user message. Cannot be null.- Returns:
- This builder instance.
-
tool
Adds a tool message with text content to the list.- Parameters:
content
- The text content of the tool call. Cannot be null.toolCallId
- The ID of the tool call this message responds to. Can be null.- Returns:
- This builder instance.
-
message
Adds a pre-constructed ChatMessage object to the list. Useful for adding messages with complex content or specific configurations (e.g., AssistantMessage with both content and tool calls).- Parameters:
message
- The ChatMessage object to be added. Cannot be null.- Returns:
- This builder instance.
-
build
Returns the list of ChatMessage objects that have been added.- Returns:
- The list of ChatMessage objects.
-