Class ChatMessage

java.lang.Object
com.codename1.ai.ChatMessage

public final class ChatMessage extends Object
A single turn in a chat conversation. Holds a Role, one or more MessageParts, and (for assistant turns) any ToolCalls the model produced. Construct via the static helpers (user(String), system(String), etc.) for the common case, or pass parts directly for multi-modal messages.
  • Constructor Details

  • Method Details

    • system

      public static ChatMessage system(String text)
    • user

      public static ChatMessage user(String text)
    • assistant

      public static ChatMessage assistant(String text)
    • userWithImage

      public static ChatMessage userWithImage(String text, ImagePart image)
      Builds a USER message containing both a text and image part -- the common multi-modal pattern.
    • toolResult

      public static ChatMessage toolResult(String toolCallId, String resultJson)
      Builds a TOOL message wrapping the result of a previous tool call.
    • getRole

      public Role getRole()
    • getParts

      public List<MessagePart> getParts()
    • getToolCalls

      public List<ToolCall> getToolCalls()
    • getName

      public String getName()
    • getToolCallId

      public String getToolCallId()
    • getText

      public String getText()
      Convenience: concatenates the text of every TextPart. Image and tool-result parts are skipped. Useful for ChatView rendering when you don't care about multi-modal content.