Parts

@SerialName(value = "parts")
@Serializable
data class Parts(val parts: List<ContentPart>) : Content, Content.Request, Content.Response

Multi-part content containing a list of ContentPart items.

Used for messages with mixed content (e.g. text + images). Implements both Request and Response.

Samples

// Create a Content.parts
val imagePartsContent = Content.Parts(
    parts = listOf(
        ContentPart.Image(ImageSource.FilePath("path/to/file.png", mimeType = MimeType.Image.Png)),
        ContentPart.Text("What do you see in the photo?")
    )
)

val message = Message(
    role = Role.User,
    content = imagePartsContent
)

// Send message to API.
for (part in contentParts.parts) { // contentParts is Content.Parts
    when (part) {
        is ContentPart.Image -> println("Part is image: ${part.source}")
        is ContentPart.Text -> println("Part is text: ${part.value}")
    }
}

Constructors

Link copied to clipboard
constructor(parts: List<ContentPart>)

Properties

Link copied to clipboard

The ordered list of content parts.

Functions

Link copied to clipboard

Wraps this request content as an assistant Message.

Link copied to clipboard

Attempts to cast this response content to a request-compatible content type.