Record Class Message

java.lang.Object
java.lang.Record
dev.dokimos.core.conversation.Message
Record Components:
role - the role of the message sender
content - the message content
metadata - additional metadata about the message

public record Message(Message.Role role, String content, Map<String,Object> metadata) extends Record
Represents a single message in a conversation.

Each message has a role (USER, ASSISTANT, or SYSTEM), content, and optional metadata.

  • Constructor Details

  • Method Details

    • of

      public static Message of(Message.Role role, String content)
      Creates a message with just role and content.
      Parameters:
      role - the message role
      content - the message content
      Returns:
      a new message
    • user

      public static Message user(String content)
      Creates a user message.
      Parameters:
      content - the message content
      Returns:
      a new user message
    • assistant

      public static Message assistant(String content)
      Creates an assistant message.
      Parameters:
      content - the message content
      Returns:
      a new assistant message
    • system

      public static Message system(String content)
      Creates a system message.
      Parameters:
      content - the message content
      Returns:
      a new system message
    • isUser

      public boolean isUser()
      Checks if this message is from a user.
      Returns:
      true if the role is USER
    • isAssistant

      public boolean isAssistant()
      Checks if this message is from an assistant.
      Returns:
      true if the role is ASSISTANT
    • isSystem

      public boolean isSystem()
      Checks if this message is a system message.
      Returns:
      true if the role is SYSTEM
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • role

      public Message.Role role()
      Returns the value of the role record component.
      Returns:
      the value of the role record component
    • content

      public String content()
      Returns the value of the content record component.
      Returns:
      the value of the content record component
    • metadata

      public Map<String,Object> metadata()
      Returns the value of the metadata record component.
      Returns:
      the value of the metadata record component