Class Message

java.lang.Object
com.google.genkit.ai.Message

public class Message extends Object
Message represents a message in a conversation with a generative AI model.
  • Constructor Details

    • Message

      public Message()
      Default constructor.
    • Message

      public Message(Role role, List<Part> content)
      Creates a message with the given role and content.
      Parameters:
      role - the message role
      content - the content parts
  • Method Details

    • user

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

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

      public static Message model(String text)
      Creates a model message with text content.
      Parameters:
      text - the text content
      Returns:
      a new model message
    • tool

      public static Message tool(List<Part> content)
      Creates a tool message with content.
      Parameters:
      content - the content parts
      Returns:
      a new tool message
    • getText

      public String getText()
      Returns the text content from all text parts.
      Returns:
      the concatenated text
    • getRole

      public Role getRole()
    • setRole

      public void setRole(Role role)
    • getContent

      public List<Part> getContent()
    • setContent

      public void setContent(List<Part> content)
    • getMetadata

      public Map<String,Object> getMetadata()
    • setMetadata

      public void setMetadata(Map<String,Object> metadata)
    • addPart

      public Message addPart(Part part)
      Adds a part to the message content.
      Parameters:
      part - the part to add
      Returns:
      this message for chaining
    • builder

      public static Message.Builder builder()
      Creates a builder for Message.
      Returns:
      a new builder