Class ChatMessage

java.lang.Object
nl.dannyj.mistral.models.completion.message.ChatMessage
Direct Known Subclasses:
AssistantMessage, SystemMessage, ToolMessage, UserMessage

public abstract class ChatMessage extends Object
Represents a single message in a chat conversation, serving as the base for different message types (system, user, assistant, tool). This class uses Jackson polymorphism based on the 'role' property found in the JSON.
  • Field Details

    • content

      @Nullable protected List<ContentChunk> content
      The content of the message. Can be null or a list of content chunks.
  • Constructor Details

    • ChatMessage

      protected ChatMessage()
  • Method Details

    • getRole

      public abstract MessageRole getRole()
      Gets the role of the message sender (e.g., system, user, assistant). Subclasses must implement this to provide their specific role.
      Returns:
      The role of the message.
    • getTextContent

      @Nullable public String getTextContent()
      Gets the text content of the message. This is a convenience method that extracts the text from all TextChunks, ignoring other types of content.
      Returns:
      The concatenated text content of the message, or null if no text content is present.
    • getContent

      @Nullable public List<ContentChunk> getContent()
      The content of the message. Can be null or a list of content chunks.
      Returns:
      The list of content chunks, or null.