Class AbstractMessage
java.lang.Object
org.springframework.ai.chat.messages.AbstractMessage
- Direct Known Subclasses:
AssistantMessage,SystemMessage,ToolResponseMessage,UserMessage
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe key for the message type in the metadata.protected final MessageTypeThe message type of the message.Additional options for the message to influence the response, not a generative map.protected final @Nullable StringDeprecated, for removal: This API element is subject to removal in a future version. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractMessage(MessageType messageType, @Nullable String textContent, Map<String, Object> metadata) Create a new AbstractMessage with the given message type, text content, and metadata.protectedAbstractMessage(MessageType messageType, List<MessagePart> parts, Map<String, Object> metadata) Create a new AbstractMessage from an ordered list of parts. -
Method Summary
Modifier and TypeMethodDescriptionbooleanGet the message type of the message.Get the metadata of the message.getParts()The ordered content parts of this message.@Nullable StringgetText()Get the content of the message.inthashCode()protected static List<MessagePart>legacyParts(@Nullable String textContent) protected <P extends MessagePart>
Stream<P>
-
Field Details
-
MESSAGE_TYPE
The key for the message type in the metadata.- See Also:
-
messageType
The message type of the message. -
textContent
Deprecated, for removal: This API element is subject to removal in a future version.since 2.1.0 in favor ofgetText(); kept so existing subclasses that read the field keep compiling. Will be removed in a future release.The text content of this message, derived from itsTextParts. -
metadata
Additional options for the message to influence the response, not a generative map.
-
-
Constructor Details
-
AbstractMessage
protected AbstractMessage(MessageType messageType, @Nullable String textContent, Map<String, Object> metadata) Create a new AbstractMessage with the given message type, text content, and metadata.- Parameters:
messageType- the message typetextContent- the text contentmetadata- the metadata
-
AbstractMessage
protected AbstractMessage(MessageType messageType, List<MessagePart> parts, Map<String, Object> metadata) Create a new AbstractMessage from an ordered list of parts. The text content is derived by joining theTextParts in the list, without a separator.- Parameters:
messageType- the message typeparts- the parts, in ordermetadata- the metadata- Since:
- 2.1.0
-
-
Method Details
-
legacyParts
-
select
-
getParts
The ordered content parts of this message.- Returns:
- an unmodifiable list of parts
- Since:
- 2.1.0
-
getText
Get the content of the message. -
getMetadata
Get the metadata of the message.- Specified by:
getMetadatain interfaceContent- Returns:
- the metadata of the message
-
getMessageType
Get the message type of the message.- Specified by:
getMessageTypein interfaceMessage- Returns:
- the message type of the message
-
equals
-
hashCode
public int hashCode()
-
getText(); kept so existing subclasses that read the field keep compiling.