madewithlaya

Catalog / Tools & apps

0060GitHub

Laya MLX Swift: run Laya inside a macOS app with no Python or helper process

Native Swift library on Apple MLX. Call prepare once to download ~804 MiB of weights, then predict with choice questions straight from your app.

Open source ↗ github.comcostfree, localtime-
MstyAI/laya-mlx-swiftREADME ↗
# Laya MLX Swift

Run [Laya](https://github.com/NandhaKishorM/laya) directly inside a macOS app with Apple MLX.

- Native Swift library
- Runs locally on Apple silicon
- No Python, ONNX, helper process, or local server
- Downloads the model only when your app calls `prepare`

## Add the package

In Xcode, add:

```text
https://github.com/MstyAI/laya-mlx-swift
```

Then add `LayaMLX` to your target.

## Prepare once

Call this from a button or setup screen. The download is about 804 MiB.

```swift
import LayaMLX

let modelDirectory = try await LayaModel.prepare { progress in
    print("Downloaded \(Int(progress.fractionCompleted * 100))%")
}
```

`prepare` does nothing when the model is already present. Inference never starts a download.

## Make a decision

```swift
let laya = try await LayaAgent(modelDirectory: modelDirectory)

let result = try await laya.predict(LayaRequest(
    state: "The payment was declined twice and the customer is angry.",
    questions: [
        "route": .choice(
            instructions: "Choose the best destination.",
            options: [
                LayaOption("billing", description: "Payment and invoice problems"),
                LayaOption("technical", description: "Product bugs and outages"),
                LayaOption("sales", description: "Purchasing questions"),
            ]
        ),
        "urgent": .boolean(
            instructions: "This needs urgent human attention."
        ),
    ]
)))

print(result.answers["route"]?.choice ?? "unknown")
print(result.answers["urgent"]?.booleanProbability ?? 0)
```

Laya supports three question types:

| Type | Use it for | Result |
|---|---|---|
| `choice` | Routing or selecting an action | Winning label and probabilities |
| `boolean` | Checking whether a statement holds | Probabili

Also filed under Tools & apps

  1. 0005

    laya-mlx plays Snake at 60 decisions per second

    介绍比Jev快50倍,在你设备上跑的laya-mlx! 只在你的设备上占用最高1G内存 Laya是一个开源的类似于Jev的,基于文本输出概率的分类系统 我将其移植到MLX,并且做了一些性能优化! 视频中就是这个模型在我的本地M3Max上玩贪吃蛇 这个模型能够以每秒决策60次的速度玩贪吃蛇! https://t.co/31KGUiNunb

    @mizorewww · Tools & apps · free, local · 60 decisions/s

  2. 0112

    Laya on Axera AX650 and AX8850 edge NPUs, under 70 ms

    AXERA-TECH's conversion of all three Laya checkpoints for its edge AI chips, reported at latency under 70 ms per decision on AX650/AX8850.

    AXERA-TECH · Tools & apps · free, on-device · < 70 ms on AX650 / AX8850

  3. 0099

    laya-mcp (PerryLink): a warm sidecar that fixes Laya's silent truncation and constant noul

    MCP server plus HTTP sidecar: token-budget preflight that reports what would be cut, a persisted calibration store, structured errors, and a noul fix (P(true) 0.5 → 1.0).

    @PerryLink · Tools & apps · free, local

  4. 0097

    Gomoku against Laya-MLX: you play black, the model picks white's move from six candidates

    Local 15x15 Gomoku on Apple Silicon. Rules in Python, board in the browser, every AI move one real Laya choice over up to six candidates, probabilities shown. No Gomoku training.

    smile-magic · Tools & apps · free, local