iOS 26 On-Device LLM Demo Implementation – Chatbot
This project demonstrates a local large language model (LLM) chat interface built using iOS 26 system-level LLM APIs (e.g., SystemLanguageModel, LanguageModelSession). Users can interact with a local AI model directly on their device without cloud dependency.
❗️ All conditions must be met:
- Device: US-market iPhone (confirmed to work)
- OS: iOS 26 system (not compatible with older versions)
- Xcode: Version 26
- A working chat interface that communicates with the local LLM engine
- Demonstration of iOS 26's
LanguageModelSessionandSystemLanguageModelcapabilities - Foundation for building advanced on-device AI applications
download the video, see how it works
🚩ChatViewModel.swift :
Purpose: Core component for managing LLM conversation sessions
Key Properties: Initializes on-device model session - Uses LanguageModelSession to create a local model session - Configures generation parameters via GenerationOptions
Manages conversation message list - Maintains the state of chat history and response data
Processes user input - Accepts user input text (inputText) as model input parameter
Generates model responses - Invokes respond() method to retrieve model-generated replies - Handles asynchronous response streaming and completion
🚩ChatMessage.swift: Purpose: Defines the core data structure for chat messages Key Properties: content: Stores the actual text of the message sender: Enum type distinguishing user input vs AI response timestamp: Records when the message was created
🚩ChatView.swift Functionality: Implements the visual layout for chat interface Binds to ChatViewModel for data flow Contains input field and send button components Displays chat history via MessageBubble views