ContentPart

@Serializable
sealed interface ContentPart

An individual part within a Content.Parts container.

Content parts allow mixing different media types in a single message.

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}")
    }
}

Inheritors

Types

Link copied to clipboard
@SerialName(value = "image")
@Serializable
data class Image(val source: ImageSource) : ContentPart

An image content part.

Link copied to clipboard
@SerialName(value = "text")
@Serializable
data class Text(val value: String) : ContentPart

A text content part.