Attachment

@Serializable
sealed interface Attachment

A file that goes to a model with a message, such as the photo of a receipt or a contract as a PDF.

Create one from the bytes of the file with Attachment.of, or from an address that the model's API downloads itself with Attachment.url, and send it with a ChatMessage.User:

val question = ChatMessage.User(
"What does this letter ask me to do?",
attachments = listOf(Attachment.of(photo, "image/jpeg")),
)

A tool returns one with attach.

The model classes send images (image/jpeg, image/png, image/gif and image/webp) and PDFs (application/pdf); each says which of them it takes from an address. A file of another type fails before the request, with a ChatModelException.

An attachment is part of its message, so a checkpoint of a state that holds the message holds the file too, after every step. For a large file, keep its path or its address in the state and attach it in the node that calls the model.

Inheritors

Types

Link copied to clipboard
object Companion

Creates attachments.

Link copied to clipboard
@Serializable
@SerialName(value = "data")
data class Data(val base64: String, val mediaType: String) : Attachment

The file itself.

Link copied to clipboard
@Serializable
@SerialName(value = "url")
data class Url(val url: String, val mediaType: String) : Attachment

A file that the model's API downloads from url.

Properties

Link copied to clipboard
abstract val mediaType: String

the media type of the file, such as image/png or application/pdf.