bindings/ios/README.md
Nexa SDK enables on-device AI inference on iPhone / iPad / macOS (on supported platforms). It covers a wide range of capabilities including Large Language Models (LLM), Vision-Language Models (VLM), Text Embeddings (Embedder), Automatic Speech Recognition (ASR), Reranking (Reranker), and more.
The SDK supports accelerated inference using Apple Neural Engine (ANE), Metal GPU, and CPU, making it easy to integrate offline or edge AI capabilities into iOS and macOS applications.
For more detailed documentation, please refer to the official docs
Download and prepare models according to the SDK documentation or the model repository instructions. Optional example models include:
Place model files in a location accessible by the app:
Below are Swift examples for common use cases
import NexaSdk
import Foundation
let repoDir: URL = URL(string: "...")!
let asr = try Asr()
try await asr.load(from: repoDir)
print(asr.supportedLanguages())
let audioPath = Bundle.main.path(forResource: "test", ofType: "wav")!
let result = try await asr.transcribe(options: .init(audioPath: audioPath))
print(result.asrResult)
import NexaSdk
import Foundation
let repoDir: URL = URL(string: "...")!
let embedder = try Embedder(from: repoDir)
let texts = [
"Hello world", "Good morning",
"Machine learning is fascinating",
"Natural language processing"
]
let result = try embedder.embed(
texts: texts,
config: .init(batchSize: Int32(texts.count))
)
print(result.embeddings.prefix(10))
import NexaSdk
import Foundation
let llm = try LLM()
let repoDir: URL = URL(string: "...")!
try await llm.load(from: repoDir)
var messages: [ChatMessage] = [
ChatMessage(role: .user, content: "Hello, tell me a story")
]
let prompt = try await llm.applyChatTemplate(messages: messages)
let stream = await llm.generateAsyncStream(prompt: prompt)
var response = ""
for try await token in stream {
print(token, terminator: "")
response += token
}
For more examples, please refer to the API Reference.
// Set log levels
NexaAI.install([.error, .trace, .debug])
// Print SDK version
print(NexaAI.version)
NexaSdk.xcframework is correctly set to Embed & Sign in your target settings.