Skip to content

timokoethe/CoreAIChat

Repository files navigation

CoreAIChat

License: MIT Framework Xcode macOS Apple

CoreAIChat is a minimal macOS demo app that shows how to build a local AI chat experience with SwiftUI and Apple’s Core AI framework. It is not tied to Gemma 3: you can use any compatible language model supported by Apple’s coreai-models repository. Gemma 3 and the included gemma_3_4b_it_4bit_dynamic folder serve only as an example.

⚠️ Disclaimer: This app is for demonstration purposes only and is not production-ready. Output generated by the local large language model may be inaccurate, incomplete, or misleading.

Beta notice: This project currently relies on beta versions of Apple's development tools and frameworks. Many components are still under active development, so APIs, behavior, and setup instructions may change.

Setup

Prepare the export tools

Install uv if it is not already available:

brew install uv

Alternatively, use the official installation script:

curl -LsSf https://astral.sh/uv/install.sh | sh

Clone Apple's coreai-models repository:

git clone https://github.com/apple/coreai-models.git && cd coreai-models

Choose and export a model

Choose a compatible language model from the recipes provided by coreai-models and follow its model-specific requirements and license terms. For example, Gemma 3 requires accepting its license terms and authenticating with Hugging Face:

brew install hf
hf auth login --token <YOUR_TOKEN>

To export Gemma 3 as an example, run the following from the coreai-models directory:

uv run coreai.llm.export google/gemma-3-4b-it

The command and prerequisites may differ for another model; use the corresponding recipe in coreai-models. Exporting may take a few minutes because the model may need to be downloaded before conversion to the Core AI format.

For the Gemma 3 example, the exported model is written to ./exports/gemma_3_4b_it_4bit_dynamic. This directory should contain the .aimodel package, metadata.json, and a tokenizer directory.

Add the model to Xcode

Open CoreAIChat.xcodeproj and add the complete contents of the exported model directory to the app target. The included gemma_3_4b_it_4bit_dynamic folder is the example resource currently referenced by the project and ViewModel.swift. When using another model, replace that resource and update the resource name in ViewModel.swift accordingly.

For the Gemma 3 example, the resulting directory should contain:

gemma_3_4b_it_4bit_dynamic/
├── gemma_3_4b_it_4bit_dynamic.aimodel/
├── metadata.json
└── tokenizer/

Run the app

Select the CoreAIChat scheme in Xcode and run the app. Loading the model may take a short while, especially on the first launch.

Run a Core AI Language Model

The following example uses the included Gemma 3 resource name. Substitute the directory name of your exported model when using another compatible language model.

import Foundation
import FoundationModels
import CoreAILanguageModels

func respond(to prompt: String) async throws -> String {
    guard let modelURL = Bundle.main.url(
        forResource: "gemma_3_4b_it_4bit_dynamic",
        withExtension: nil
    ) else {
        throw URLError(.fileDoesNotExist)
    }

    let model = try await CoreAILanguageModel(resourcesAt: modelURL)
    let session = LanguageModelSession(model: model)
    let response = try await session.respond(to: prompt)

    return response.content
}

print(try await respond(to: "Hello"))

License

CoreAIChat is available under the MIT License. See LICENSE for the full license text.

About

A modern SwiftUI showcase app for macOS 27, built to demonstrate Apple’s Core AI framework in action.

Topics

Resources

License

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Contributors

Languages