Class ChatMessage
java.lang.Object
com.codename1.ai.ChatMessage
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 Summary
ConstructorsConstructorDescriptionChatMessage(Role role, List<MessagePart> parts) Creates a message with no assistant tool calls or provider name.ChatMessage(Role role, List<MessagePart> parts, List<ToolCall> toolCalls, String name, String toolCallId) Creates a fully specified normalized message. -
Method Summary
Modifier and TypeMethodDescriptionstatic ChatMessagegetName()getParts()getRole()getText()Convenience: concatenates the text of everyTextPart.static ChatMessagestatic ChatMessagetoolResult(String toolCallId, String resultJson) Builds a TOOL message wrapping the result of a previous tool call.static ChatMessagestatic ChatMessageuserWithImage(String text, ImagePart image) Builds a USER message containing both a text and image part -- the common multi-modal pattern.
-
Constructor Details
-
ChatMessage
Creates a message with no assistant tool calls or provider name.- Parameters:
role- speaker role; requiredparts- ordered multimodal content;nullbecomes empty
-
ChatMessage
public ChatMessage(Role role, List<MessagePart> parts, List<ToolCall> toolCalls, String name, String toolCallId) Creates a fully specified normalized message.- Parameters:
role- speaker role; requiredparts- ordered content parts;nullbecomes emptytoolCalls- assistant tool calls;nullbecomes emptyname- optional provider-visible participant nametoolCallId- tool call answered by aRole.TOOLmessage
-
-
Method Details
-
system
- Parameters:
text- system instruction text- Returns:
- a single-part system message
-
user
- Parameters:
text- user input text- Returns:
- a single-part user message
-
assistant
- Parameters:
text- assistant output text- Returns:
- a single-part assistant message
-
userWithImage
Builds a USER message containing both a text and image part -- the common multi-modal pattern.- Parameters:
text- optional text accompanying the imageimage- image content sent to the model- Returns:
- multimodal user message
-
toolResult
Builds a TOOL message wrapping the result of a previous tool call.- Parameters:
toolCallId- provider id of the answered tool callresultJson- application result encoded as JSON- Returns:
- tool-role result message
-
getRole
- Returns:
- speaker role
-
getParts
- Returns:
- immutable content parts in message order
-
getToolCalls
-
getName
- Returns:
- optional participant name, or
null
-
getToolCallId
- Returns:
- answered tool-call id for tool messages, or
null
-
getText
-