Skip to content

ondeinference/onde-swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Onde Inference

Onde Inference

On-device LLM inference for Swift — optimized for Apple silicon.

crates.io Swift Package Index pub.dev Website App Store

Rust SDK · Flutter SDK · Website

Compatibility


Installation

In Xcode: File → Add Package Dependencies and enter:

https://github.com/ondeinference/onde-swift

Or add it to your Package.swift:

dependencies: [
    .package(url: "https://github.com/ondeinference/onde-swift", from: "0.1.0")
],
targets: [
    .target(name: "MyApp", dependencies: [
        .product(name: "Onde", package: "onde-swift")
    ])
]

Platforms

Platform Minimum GPU Backend
iOS 15.0 Metal
macOS 11.0 Metal
tvOS 15.0 Metal

Quick Start

import Onde

let engine = OndeChatEngine()

// Load the platform-appropriate default model:
//   iOS / tvOS → Qwen 2.5 1.5B (~941 MB)
//   macOS      → Qwen 2.5 3B   (~1.93 GB)
let elapsed = try await engine.loadDefaultModel(
    systemPrompt: "You are a helpful assistant.",
    sampling: nil
)

let result = try await engine.sendMessage(message: "Hello!")
print(result.text)

Streaming

import Onde

class StreamHandler: StreamChunkListener {
    func onChunk(chunk: StreamChunk) -> Bool {
        print(chunk.delta, terminator: "")
        return !chunk.done
    }
}

try await streamChatMessage(
    engine: engine,
    message: "Tell me a story.",
    listener: StreamHandler()
)

One-Shot Generation

Run inference without modifying conversation history:

let result = try await engine.generate(
    messages: [userMessage(content: "Expand: a cat in space")],
    sampling: deterministicSamplingConfig()
)

Sandboxed App Setup

On iOS and App Store macOS, the default ~/.cache/huggingface is outside the app sandbox. This helper seeds HF_HOME inside the App Group shared container (group.com.ondeinference.apps) so all Onde-powered apps share downloaded models. Call once at app launch before creating an OndeChatEngine.

import Foundation

func setupInferenceEnvironment() {
    guard let container = FileManager.default.containerURL(
        forSecurityApplicationGroupIdentifier: "group.com.ondeinference.apps"
    ) else {
        // Fall back to app-private Application Support if App Group is unavailable.
        let appSupport = FileManager.default
            .urls(for: .applicationSupportDirectory, in: .userDomainMask)[0]
        setupHfCache(at: appSupport)
        return
    }
    setupHfCache(at: container)
}

private func setupHfCache(at base: URL) {
    let hfHome = base.appendingPathComponent("models")
    let hfHub  = hfHome.appendingPathComponent("hub")
    try? FileManager.default.createDirectory(at: hfHub, withIntermediateDirectories: true)

    setenv("HF_HOME",      hfHome.path, 1)
    setenv("HF_HUB_CACHE", hfHub.path,  1)

    let tmp = base.appendingPathComponent("tmp")
    try? FileManager.default.createDirectory(at: tmp, withIntermediateDirectories: true)
    setenv("TMPDIR", tmp.path, 1)
}

Documentation

License

Onde is dual-licensed under MIT and Apache 2.0. You may use it under either license at your option.

© 2026 Splitfire AB


© 2026 Onde Inference