Back to directory

OnDeviceAI

A minimal Compose Multiplatform sample showing how to call on-device generative AI from shared Kotlin code, using Apple's Foundation Models framework on iOS and Google's ML Kit Prompt API on Android.

OnDeviceAI

The sample defines a small PromptApi Kotlin interface shared across platforms, implemented by a Swift class on iOS that calls Apple's on-device LanguageModelSession, and by a Kotlin class on Android that calls ML Kit's on-device generation client. The shared Compose Multiplatform UI code calls this interface without knowing which platform implementation is behind it.

The project is split into a shared composeApp module holding the UI and the interface plus the Android implementation, an androidApp module for the Android application shell, and an iosApp Xcode project holding the Swift implementation, a structure required because the Android Gradle Plugin's application plugin is incompatible with the Kotlin Multiplatform plugin inside the same module.

More in Inference

See all 770
  • OpenDecision

    deepanwadhwa.github.io

    An open-source Python package that answers typed questions about application state or documents using a local natural-language-inference model, returning structured choice, score, yes/no or evidence-relation values instead of free text.

  • Lifeboat

    iterate.ai

    A local inference server that puts an OpenAI- and Anthropic-compatible API in front of open-weight language models running on hardware you control, from a laptop to a GPU cluster.

  • Claude S40

    github.com

    An unofficial Claude chat client for 2007-era Nokia Series 40 phones, built as a Java ME app plus a small Go relay server, with web search, reading mode and saved chats.