-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(apple-ai): support Apple's Foundation Models framework with local-first and cloud Gemini fallback #1855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
04efb3a
9ad90c8
7cd57d2
cfb49d8
784a95a
0de49f0
48bafcb
424d6d8
11bfbe5
8e6da5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,9 +7,14 @@ | |
| objects = { | ||
|
|
||
| /* Begin PBXBuildFile section */ | ||
| 88151ADC2EC9345700775CFB /* MarkdownUI in Frameworks */ = {isa = PBXBuildFile; productRef = 88151ADB2EC9345700775CFB /* MarkdownUI */; }; | ||
| 88779D902EC8AA920080D023 /* ConversationKit in Frameworks */ = {isa = PBXBuildFile; productRef = 88779D8F2EC8AA920080D023 /* ConversationKit */; }; | ||
| 88779D932EC8AC460080D023 /* FirebaseAILogic in Frameworks */ = {isa = PBXBuildFile; productRef = 88779D922EC8AC460080D023 /* FirebaseAILogic */; }; | ||
| 88862D5D2FD7C19F003702C7 /* FirebaseAI in Frameworks */ = {isa = PBXBuildFile; productRef = 88862D5C2FD7C19F003702C7 /* FirebaseAI */; }; | ||
| 88862D5F2FD7C19F003702C7 /* FirebaseAILogic in Frameworks */ = {isa = PBXBuildFile; productRef = 88862D5E2FD7C19F003702C7 /* FirebaseAILogic */; }; | ||
| 88862D612FD7C19F003702C7 /* FirebaseAppCheck in Frameworks */ = {isa = PBXBuildFile; productRef = 88862D602FD7C19F003702C7 /* FirebaseAppCheck */; }; | ||
| 88862D632FD7C19F003702C7 /* FirebaseCore in Frameworks */ = {isa = PBXBuildFile; productRef = 88862D622FD7C19F003702C7 /* FirebaseCore */; }; | ||
| 88AAB45E2FF0077E001B143E /* FirebaseAI in Frameworks */ = {isa = PBXBuildFile; productRef = 88AAB45D2FF0077E001B143E /* FirebaseAI */; }; | ||
| 88AAB4602FF0077E001B143E /* FirebaseAppCheck in Frameworks */ = {isa = PBXBuildFile; productRef = 88AAB45F2FF0077E001B143E /* FirebaseAppCheck */; }; | ||
| 88AAB4622FF0077E001B143E /* FirebaseCore in Frameworks */ = {isa = PBXBuildFile; productRef = 88AAB4612FF0077E001B143E /* FirebaseCore */; }; | ||
| 88AAB4652FF007DD001B143E /* ConversationKit in Frameworks */ = {isa = PBXBuildFile; productRef = 88AAB4642FF007DD001B143E /* ConversationKit */; }; | ||
| /* End PBXBuildFile section */ | ||
|
|
||
| /* Begin PBXFileReference section */ | ||
|
|
@@ -29,9 +34,14 @@ | |
| isa = PBXFrameworksBuildPhase; | ||
| buildActionMask = 2147483647; | ||
| files = ( | ||
| 88151ADC2EC9345700775CFB /* MarkdownUI in Frameworks */, | ||
| 88779D932EC8AC460080D023 /* FirebaseAILogic in Frameworks */, | ||
| 88779D902EC8AA920080D023 /* ConversationKit in Frameworks */, | ||
| 88AAB45E2FF0077E001B143E /* FirebaseAI in Frameworks */, | ||
| 88862D5F2FD7C19F003702C7 /* FirebaseAILogic in Frameworks */, | ||
| 88AAB4652FF007DD001B143E /* ConversationKit in Frameworks */, | ||
| 88862D612FD7C19F003702C7 /* FirebaseAppCheck in Frameworks */, | ||
| 88862D632FD7C19F003702C7 /* FirebaseCore in Frameworks */, | ||
| 88AAB4622FF0077E001B143E /* FirebaseCore in Frameworks */, | ||
| 88AAB4602FF0077E001B143E /* FirebaseAppCheck in Frameworks */, | ||
| 88862D5D2FD7C19F003702C7 /* FirebaseAI in Frameworks */, | ||
| ); | ||
| runOnlyForDeploymentPostprocessing = 0; | ||
| }; | ||
|
|
@@ -74,9 +84,14 @@ | |
| ); | ||
| name = FirebaseAIExample; | ||
| packageProductDependencies = ( | ||
| 88779D8F2EC8AA920080D023 /* ConversationKit */, | ||
| 88779D922EC8AC460080D023 /* FirebaseAILogic */, | ||
| 88151ADB2EC9345700775CFB /* MarkdownUI */, | ||
| 88862D5C2FD7C19F003702C7 /* FirebaseAI */, | ||
| 88862D5E2FD7C19F003702C7 /* FirebaseAILogic */, | ||
| 88862D602FD7C19F003702C7 /* FirebaseAppCheck */, | ||
| 88862D622FD7C19F003702C7 /* FirebaseCore */, | ||
| 88AAB45D2FF0077E001B143E /* FirebaseAI */, | ||
| 88AAB45F2FF0077E001B143E /* FirebaseAppCheck */, | ||
| 88AAB4612FF0077E001B143E /* FirebaseCore */, | ||
| 88AAB4642FF007DD001B143E /* ConversationKit */, | ||
| ); | ||
| productName = FirebaseAIExample; | ||
| productReference = 88779D352EC8A9CF0080D023 /* FirebaseAIExample.app */; | ||
|
|
@@ -107,9 +122,8 @@ | |
| mainGroup = 88779D2C2EC8A9CF0080D023; | ||
| minimizedProjectReferenceProxies = 1; | ||
| packageReferences = ( | ||
| 88779D8E2EC8AA920080D023 /* XCRemoteSwiftPackageReference "ConversationKit" */, | ||
| 88779D912EC8AC460080D023 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */, | ||
| 88151ADA2EC9345700775CFB /* XCRemoteSwiftPackageReference "swift-markdown-ui" */, | ||
| 88AAB45C2FF0077E001B143E /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */, | ||
| 88AAB4632FF007DD001B143E /* XCLocalSwiftPackageReference "../../../../ConversationKit/ConversationKit" */, | ||
| ); | ||
| preferredProjectObjectVersion = 77; | ||
| productRefGroup = 88779D362EC8A9CF0080D023 /* Products */; | ||
|
|
@@ -268,7 +282,7 @@ | |
| ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; | ||
| CODE_SIGN_STYLE = Automatic; | ||
| CURRENT_PROJECT_VERSION = 1; | ||
| DEVELOPMENT_TEAM = ""; | ||
| DEVELOPMENT_TEAM = YGAZHQXHH4; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: revert |
||
| ENABLE_PREVIEWS = YES; | ||
| GENERATE_INFOPLIST_FILE = YES; | ||
| INFOPLIST_KEY_NSMicrophoneUsageDescription = "The app needs access to your microphone to enable live voice conversations with Gemini."; | ||
|
|
@@ -302,7 +316,7 @@ | |
| ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; | ||
| CODE_SIGN_STYLE = Automatic; | ||
| CURRENT_PROJECT_VERSION = 1; | ||
| DEVELOPMENT_TEAM = ""; | ||
| DEVELOPMENT_TEAM = YGAZHQXHH4; | ||
| ENABLE_PREVIEWS = YES; | ||
| GENERATE_INFOPLIST_FILE = YES; | ||
| INFOPLIST_KEY_NSMicrophoneUsageDescription = "The app needs access to your microphone to enable live voice conversations with Gemini."; | ||
|
|
@@ -352,48 +366,59 @@ | |
| }; | ||
| /* End XCConfigurationList section */ | ||
|
|
||
| /* Begin XCRemoteSwiftPackageReference section */ | ||
| 88151ADA2EC9345700775CFB /* XCRemoteSwiftPackageReference "swift-markdown-ui" */ = { | ||
| isa = XCRemoteSwiftPackageReference; | ||
| repositoryURL = "https://github.com/gonzalezreal/swift-markdown-ui"; | ||
| requirement = { | ||
| kind = upToNextMajorVersion; | ||
| minimumVersion = 2.4.1; | ||
| }; | ||
| }; | ||
| 88779D8E2EC8AA920080D023 /* XCRemoteSwiftPackageReference "ConversationKit" */ = { | ||
| isa = XCRemoteSwiftPackageReference; | ||
| repositoryURL = "https://github.com/peterfriese/ConversationKit"; | ||
| requirement = { | ||
| kind = exactVersion; | ||
| version = 0.0.4; | ||
| }; | ||
| /* Begin XCLocalSwiftPackageReference section */ | ||
| 88AAB4632FF007DD001B143E /* XCLocalSwiftPackageReference "../../../../ConversationKit/ConversationKit" */ = { | ||
| isa = XCLocalSwiftPackageReference; | ||
| relativePath = ../../../../ConversationKit/ConversationKit; | ||
| }; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should switch this one back to |
||
| 88779D912EC8AC460080D023 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */ = { | ||
| /* End XCLocalSwiftPackageReference section */ | ||
|
|
||
| /* Begin XCRemoteSwiftPackageReference section */ | ||
| 88AAB45C2FF0077E001B143E /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */ = { | ||
| isa = XCRemoteSwiftPackageReference; | ||
| repositoryURL = "https://github.com/firebase/firebase-ios-sdk"; | ||
| repositoryURL = "https://github.com/firebase/firebase-ios-sdk/"; | ||
| requirement = { | ||
| kind = upToNextMajorVersion; | ||
| minimumVersion = 12.15.0; | ||
| branch = "wwdc26-preview"; | ||
| kind = branch; | ||
| }; | ||
| }; | ||
| /* End XCRemoteSwiftPackageReference section */ | ||
|
|
||
| /* Begin XCSwiftPackageProductDependency section */ | ||
| 88151ADB2EC9345700775CFB /* MarkdownUI */ = { | ||
| 88862D5C2FD7C19F003702C7 /* FirebaseAI */ = { | ||
| isa = XCSwiftPackageProductDependency; | ||
| package = 88151ADA2EC9345700775CFB /* XCRemoteSwiftPackageReference "swift-markdown-ui" */; | ||
| productName = MarkdownUI; | ||
| productName = FirebaseAI; | ||
| }; | ||
| 88779D8F2EC8AA920080D023 /* ConversationKit */ = { | ||
| 88862D5E2FD7C19F003702C7 /* FirebaseAILogic */ = { | ||
| isa = XCSwiftPackageProductDependency; | ||
| package = 88779D8E2EC8AA920080D023 /* XCRemoteSwiftPackageReference "ConversationKit" */; | ||
| productName = ConversationKit; | ||
| productName = FirebaseAILogic; | ||
| }; | ||
| 88779D922EC8AC460080D023 /* FirebaseAILogic */ = { | ||
| 88862D602FD7C19F003702C7 /* FirebaseAppCheck */ = { | ||
| isa = XCSwiftPackageProductDependency; | ||
| package = 88779D912EC8AC460080D023 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */; | ||
| productName = FirebaseAILogic; | ||
| productName = FirebaseAppCheck; | ||
| }; | ||
| 88862D622FD7C19F003702C7 /* FirebaseCore */ = { | ||
| isa = XCSwiftPackageProductDependency; | ||
| productName = FirebaseCore; | ||
| }; | ||
| 88AAB45D2FF0077E001B143E /* FirebaseAI */ = { | ||
| isa = XCSwiftPackageProductDependency; | ||
| package = 88AAB45C2FF0077E001B143E /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */; | ||
| productName = FirebaseAI; | ||
| }; | ||
| 88AAB45F2FF0077E001B143E /* FirebaseAppCheck */ = { | ||
| isa = XCSwiftPackageProductDependency; | ||
| package = 88AAB45C2FF0077E001B143E /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */; | ||
| productName = FirebaseAppCheck; | ||
| }; | ||
| 88AAB4612FF0077E001B143E /* FirebaseCore */ = { | ||
| isa = XCSwiftPackageProductDependency; | ||
| package = 88AAB45C2FF0077E001B143E /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */; | ||
| productName = FirebaseCore; | ||
| }; | ||
| 88AAB4642FF007DD001B143E /* ConversationKit */ = { | ||
| isa = XCSwiftPackageProductDependency; | ||
| productName = ConversationKit; | ||
| }; | ||
| /* End XCSwiftPackageProductDependency section */ | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| import Foundation | ||
| import FoundationModels | ||
|
|
||
| @available(iOS 26.0, *) | ||
|
peterfriese marked this conversation as resolved.
|
||
| @Generable | ||
| public struct IdentifiedObject: Equatable, Codable { | ||
| @Guide(description: "The name of the primary object or landmark detected.") | ||
| public let name: String | ||
|
|
||
| @Guide( | ||
| description: "The category of the object (e.g. Landmark, Plant, Food, Animal, Device, Clothing)." | ||
| ) | ||
| public let category: String | ||
|
|
||
| @Guide(description: "A short, 2-sentence description of the object and interesting facts.") | ||
| public let description: String | ||
| } | ||
|
|
||
| @available(iOS 26.0, *) | ||
| @Generable | ||
| public struct TextSummary: Equatable, Codable { | ||
| @Guide(description: "A list of exactly 2 key summary points.") | ||
| public let summaryPoints: [String] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| import SwiftUI | ||
|
|
||
| @available(iOS 27.0, *) | ||
| struct HybridAIScreen: View { | ||
| @StateObject private var viewModel: HybridAIViewModel | ||
|
|
||
| init(backendType: BackendOption) { | ||
| _viewModel = StateObject(wrappedValue: HybridAIViewModel(backendType: backendType)) | ||
| } | ||
|
|
||
| var body: some View { | ||
| FoundationModelsContainer(viewModel: viewModel, title: "Hybrid AI") { vm in | ||
| HybridAIView(viewModel: vm) | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| import SwiftUI | ||
| import PhotosUI | ||
|
|
||
| @available(iOS 27.0, *) | ||
| struct VisionIDScreen: View { | ||
| @StateObject private var viewModel: VisionIDViewModel | ||
| @State private var photosPickerItem: PhotosPickerItem? = nil | ||
|
|
||
| init(backendType: BackendOption) { | ||
| _viewModel = StateObject(wrappedValue: VisionIDViewModel(backendType: backendType)) | ||
| } | ||
|
|
||
| var body: some View { | ||
| FoundationModelsContainer(viewModel: viewModel, title: "Vision ID") { vm in | ||
| VisionIDView(viewModel: vm, photosPickerItem: $photosPickerItem) | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,58 @@ | ||||||
| // Copyright 2026 Google LLC | ||||||
| // | ||||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
| // you may not use this file except in compliance with the License. | ||||||
| // You may obtain a copy of the License at | ||||||
| // | ||||||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||||||
| // | ||||||
| // Unless required by applicable law or agreed to in writing, software | ||||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
| // See the License for the specific language governing permissions and | ||||||
| // limitations under the License. | ||||||
|
|
||||||
| import Foundation | ||||||
| import SwiftUI | ||||||
| import Combine | ||||||
| import FoundationModels | ||||||
| import FirebaseAILogic | ||||||
|
|
||||||
| public enum ModelPreference: String, CaseIterable, Identifiable { | ||||||
| case auto = "Auto (Local First)" | ||||||
| case cloud = "Cloud Only" | ||||||
|
|
||||||
| public var id: String { rawValue } | ||||||
| } | ||||||
|
|
||||||
| @available(iOS 27.0, *) | ||||||
| @MainActor | ||||||
| public class FoundationModelsBaseViewModel: ObservableObject { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| @Published public var inProgress = false | ||||||
| @Published public var error: Error? | ||||||
| @Published public var modelPreference: ModelPreference = .auto | ||||||
| @Published public var isUsingLocalModel: Bool = false | ||||||
|
|
||||||
| internal var activeTask: Task<Void, Never>? | ||||||
| public let backendType: BackendOption | ||||||
|
|
||||||
| public init(backendType: BackendOption) { | ||||||
| self.backendType = backendType | ||||||
| } | ||||||
|
|
||||||
| public func stopActiveTask() { | ||||||
| activeTask?.cancel() | ||||||
| activeTask = nil | ||||||
| inProgress = false | ||||||
| } | ||||||
|
|
||||||
| internal func getFirebaseAI() -> FirebaseAI { | ||||||
| switch backendType { | ||||||
| case .googleAI: | ||||||
| return FirebaseAI.firebaseAI(backend: .googleAI()) | ||||||
| case .vertexAI: | ||||||
| // Using "global" as location for Foundation Models fallback compatibility | ||||||
| return FirebaseAI.firebaseAI(backend: .vertexAI(location: "global")) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid adding the
FirebaseAIframework so LLMs learn to just includeFirebaseAILogic(plan to finally removeFirebaseAIin the next breaking change).