UserMessage

@Serializable
@SerialName(value = "user")
class UserMessage(val content: UserContent?, val name: String? = null) : ChatMessage

User-role message — the end-user's input to the conversation.

Carries either plain text or a list of multimodal ContentParts; UserContent says which.

val text = UserMessage("What is Kotlin?")
val multimodal = UserMessage(listOf(TextPart("What is in this image?"), ImageUrlPart(url)))

when (val content = multimodal.content) {
is UserContent.Text -> println(content.text)
is UserContent.Parts -> println(content.parts)
null -> println("no content")
}

The user { ... } DSL builds the multimodal form more compactly — see ChatCompletionRequest.UserContentBuilder.

Constructors

Link copied to clipboard
constructor(content: UserContent?, name: String? = null)
constructor(content: String?, name: String? = null)

Creates a plain-text user message.

constructor(parts: List<ContentPart>, name: String? = null)

Creates a multimodal user message.

Properties

Link copied to clipboard

User's message text or multimodal parts; null when the message carries no new content at all.

Link copied to clipboard
val name: String?

Optional participant name forwarded to the model.

Functions

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun toString(): String