Enum MessageRole

java.lang.Object
java.lang.Enum<MessageRole>
uno.anahata.ai.MessageRole
All Implemented Interfaces:
Serializable, Comparable<MessageRole>, java.lang.constant.Constable

public enum MessageRole extends Enum<MessageRole>
A type-safe enum representing the role of the author of a ChatMessage.

This enum maps to the roles recognized by the Gemini API ("user", "model") and includes a "tool" role for function responses.

  • Enum Constant Details

    • USER

      public static final MessageRole USER
      The user who is interacting with the model.
    • MODEL

      public static final MessageRole MODEL
      The model that is generating responses.
    • TOOL

      public static final MessageRole TOOL
      The tool that is providing function responses.
  • Method Details

    • values

      public static MessageRole[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static MessageRole valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • fromString

      public static MessageRole fromString(String value)
      Parses a string role value into the corresponding enum constant.

      This method is case-insensitive. If the provided value does not match any known role, it defaults to USER.

      Parameters:
      value - The string value (e.g., "user", "model").
      Returns:
      The matching MessageRole enum.