Class MessageListBuilder

java.lang.Object
nl.dannyj.mistral.builders.MessageListBuilder

public class MessageListBuilder extends Object
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 Details

    • MessageListBuilder

      public MessageListBuilder()
      Default constructor that initializes an empty list of ChatMessage objects.
    • MessageListBuilder

      public MessageListBuilder(List<ChatMessage> messages)
      Constructor that initializes the list of ChatMessage objects with a provided list.
      Parameters:
      messages - The initial list of ChatMessage objects.
  • Method Details

    • system

      public MessageListBuilder system(@NonNull @NonNull String content)
      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

      public MessageListBuilder assistant(@NonNull @NonNull String content)
      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

      public MessageListBuilder assistant(@NonNull @NotEmpty @NonNull @NotEmpty List<ToolCall> toolCalls)
      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

      public MessageListBuilder user(@NonNull @NonNull String content)
      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

      public MessageListBuilder tool(@NonNull @NonNull String content, @Nullable String toolCallId)
      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

      public MessageListBuilder message(@NonNull @NonNull ChatMessage 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

      public List<ChatMessage> build()
      Returns the list of ChatMessage objects that have been added.
      Returns:
      The list of ChatMessage objects.