Class AbstractMessage

java.lang.Object
org.springframework.ai.chat.messages.AbstractMessage
All Implemented Interfaces:
Message, Content
Direct Known Subclasses:
AssistantMessage, SystemMessage, ToolResponseMessage, UserMessage

public abstract class AbstractMessage extends Object implements Message
The AbstractMessage class is an abstract implementation of the Message interface. It provides a base implementation for message content, media attachments, metadata, and message type.
See Also:
  • Field Details

    • MESSAGE_TYPE

      public static final String MESSAGE_TYPE
      The key for the message type in the metadata.
      See Also:
    • messageType

      protected final MessageType messageType
      The message type of the message.
    • textContent

      protected final String textContent
      The content of the message.
    • metadata

      protected final Map<String,Object> metadata
      Additional options for the message to influence the response, not a generative map.
  • Constructor Details

    • AbstractMessage

      protected AbstractMessage(MessageType messageType, String textContent, Map<String,Object> metadata)
      Create a new AbstractMessage with the given message type, text content, and metadata.
      Parameters:
      messageType - the message type
      textContent - the text content
      metadata - the metadata
    • AbstractMessage

      protected AbstractMessage(MessageType messageType, org.springframework.core.io.Resource resource, Map<String,Object> metadata)
      Create a new AbstractMessage with the given message type, resource, and metadata.
      Parameters:
      messageType - the message type
      resource - the resource
      metadata - the metadata
  • Method Details

    • getContent

      public String getContent()
      Get the content of the message.
      Specified by:
      getContent in interface Content
      Returns:
      the content of the message
    • getMetadata

      public Map<String,Object> getMetadata()
      Get the metadata of the message.
      Specified by:
      getMetadata in interface Content
      Returns:
      the metadata of the message
    • getMessageType

      public MessageType getMessageType()
      Get the message type of the message.
      Specified by:
      getMessageType in interface Message
      Returns:
      the message type of the message
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object