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.
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.
Install uv if it is not already available:
brew install uvAlternatively, use the official installation script:
curl -LsSf https://astral.sh/uv/install.sh | shClone Apple's coreai-models repository:
git clone https://github.com/apple/coreai-models.git && cd coreai-modelsChoose 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-itThe 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.
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/
Select the CoreAIChat scheme in Xcode and run the app. Loading the model may take a short while, especially on the first launch.
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"))CoreAIChat is available under the MIT License. See LICENSE for the full license text.