Contents

Loader

A protocol for types that supply a dataset for evaluation.

Declaration

protocol Loader<Sample> : Sendable

Overview

Use one of the built-in concrete types — ArrayLoader, JSONLoader, or StreamLoader — or implement this protocol directly for custom data sources.

var dataset: any Loader<ModelSample<String>> {
    ArrayLoader(samples: [
        ModelSample(prompt: "One plus one is...", expected: "Two."),
        ModelSample(prompt: "Swift is...", expected: "A powerful language."),
    ])
}
var dataset: any Loader<ModelSample<String>> {
    JSONLoader(url: Bundle.main.url(forResource: "prompts", withExtension: "jsonl")!)
}
var dataset: any Loader<ModelSample<String>> {
    StreamLoader(stream: AsyncThrowingStream<ModelSample<String>, Error> { continuation in
        Task {
            let prompts = ["One plus one is...", "Swift is..."]
            for prompt in prompts {
                continuation.yield(ModelSample(prompt: prompt, expected: ""))
            }
            continuation.finish()
        }
    })
}

Topics

Loaders

Associated Types

Instance Properties

See Also

Datasets