This page shows the most common first steps with the library.
1. Resolve a model path#
import com.llamatik.library.platform.LlamaBridge
val modelPath = LlamaBridge.getModelPath("tinyllama.gguf")On desktop this is often just a file path. On mobile you may resolve the file from app storage, assets, or a download location.
2. Load a generation model#
val ok = LlamaBridge.initGenerateModel(modelPath)
check(ok) { "Failed to init model at $modelPath" }3. Generate text#
val text = LlamaBridge.generate("Write a 2 sentence story about a llama.")
println(text)4. Stream text#
LlamaBridge.generateStream(
prompt = "Stream a short haiku.",
callback = object : GenStream {
override fun onDelta(text: String) = print(text)
override fun onComplete() = println("\nDone")
override fun onError(message: String) = println("Error: $message")
}
)5. Use embeddings#
val embedModelPath = LlamaBridge.getModelPath("nomic-embed-text.gguf")
val embedOk = LlamaBridge.initEmbedModel(embedModelPath)
check(embedOk) { "Failed to init embedding model" }
val vector: FloatArray = LlamaBridge.embed("hello embeddings")
println("dims = ${vector.size}")6. Continue a session#
LlamaBridge.initGenerateModel(modelPath)
val answer1 = LlamaBridge.generate("Explain Kotlin coroutines.")
val answer2 = LlamaBridge.generateContinue("Now show a very short example.")7. Save and restore a session#
val sessionPath = "/tmp/chat.session"
LlamaBridge.sessionSave(sessionPath)
LlamaBridge.sessionLoad(sessionPath)8. Generate an image#
import com.llamatik.library.platform.StableDiffusionBridge
val sdPath = StableDiffusionBridge.getModelPath("dreamshaper.safetensors")
check(StableDiffusionBridge.initModel(sdPath))
val rgba = StableDiffusionBridge.txt2img(
prompt = "A watercolor painting of a mountain village"
)
println("Generated bytes = ${rgba.size}")9. Transcribe audio#
import com.llamatik.library.platform.WhisperBridge
val whisperPath = WhisperBridge.getModelPath("ggml-base.en.bin")
check(WhisperBridge.initModel(whisperPath))
val textResult = WhisperBridge.transcribeWav("/path/to/audio.wav", language = "en")
println(textResult)From here, move on to the Guides section for more detailed patterns.