ImageSource

sealed interface ImageSource

Discriminated union for image origins.

Supports three types of image sources:

  • Url — An HTTP/HTTPS URL pointing to an image.

  • Bytes — Raw image bytes with a MIME type.

  • FilePath — A local file path with a MIME type.

Use fromString to parse a string into the appropriate variant:

  • Strings starting with http:// or https:// become Url.

  • Strings starting with data: with ;base64, become Bytes.

  • All other strings become FilePath (with file:// prefix stripped).

Throws

Samples

// Creating chat using dsl.
val chat = koryChat(
    // Model name: String(required)
    model = "gpt-5.6-sol"
) {
    // Messages
    user("Hello, what's your name?") // Message from user(text)

    assistant("Hello, i'm ChatGPT sol. How can I help?") // Message from assistant(text)

    // Message from user(parts)
    user {
        text("What do you see in the photo?") // Add Text(String)
        image(ImageSource.FilePath("path/to/photo.jpg")) // Add Image(ImageSource)
    }
}

Inheritors

Types

Link copied to clipboard
data class Bytes(val bytes: ByteArray, val mimeType: MimeType = MimeType.Image.Jpeg) : ImageSource

An image stored as raw bytes with a MIME type.

Link copied to clipboard
object Companion
Link copied to clipboard
data class FilePath(val path: String, val mimeType: MimeType = MimeType.tryDetect(path)) : ImageSource

An image referenced by local file path.

Link copied to clipboard
data class Url(val url: String) : ImageSource

An image referenced by HTTP/HTTPS URL.

Functions

Link copied to clipboard

Serializes this ImageSource to a string representation.