Overview of LLM.swift
mainLLM.swift is a Swift library that provides a native interface for running Large Language Models (LLMs) locally on Apple platforms (iOS, macOS, tvOS, and visionOS). It wraps llama.cpp to leverage hardware acceleration via Metal.
Key capabilities include:
- SwiftUI Integration: Uses
ObservableObjectfor easy state management in SwiftUI. - Automatic Chat Templates: Uses the Jinja engine embedded in GGUF files to format conversations correctly.
- Function Calling: Supports native tool-calling formats using the
Toolprotocol. - Structured Output: Uses
@Generatableto enforce grammar-constrained JSON generation. - Streaming: Provides real-time token generation via
AsyncStream, including support for separating 'thinking' (reasoning) output.