Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 68 additions & 43 deletions firebaseai/FirebaseAIExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };

Copy link
Copy Markdown
Contributor

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 FirebaseAI framework so LLMs learn to just include FirebaseAILogic (plan to finally remove FirebaseAI in the next breaking change).

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 */
Expand All @@ -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;
};
Expand Down Expand Up @@ -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 */;
Expand Down Expand Up @@ -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 */;
Expand Down Expand Up @@ -268,7 +282,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = YGAZHQXHH4;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.";
Expand Down Expand Up @@ -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.";
Expand Down Expand Up @@ -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;
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should switch this one back to https://github.com/peterfriese/ConversationKit.

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 */
};
Expand Down
33 changes: 31 additions & 2 deletions firebaseai/FirebaseAIExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,25 @@ struct ContentView: View {
.padding(.horizontal)

LazyVGrid(columns: columns, spacing: 20) {
ForEach(filteredSamples) { sample in
NavigationLink(destination: destinationView(for: sample)) {
ForEach(filteredSamples.filter { !$0.isFoundationModel }) { sample in
NavigationLink(destination: destinationView(for: sample).id(selectedBackend)) {
SampleCardView(sample: sample)
}
.buttonStyle(PlainButtonStyle())
}
}
.padding(.horizontal)
}

// Foundation Models
VStack(alignment: .leading) {
Text("Foundation Models")
.font(.system(size: 20, weight: .bold))
.padding(.horizontal)

LazyVGrid(columns: columns, spacing: 20) {
ForEach(filteredSamples.filter { $0.isFoundationModel }) { sample in
NavigationLink(destination: destinationView(for: sample).id(selectedBackend)) {
SampleCardView(sample: sample)
}
.buttonStyle(PlainButtonStyle())
Expand Down Expand Up @@ -112,6 +129,18 @@ struct ContentView: View {
GroundingScreen(backendType: selectedBackend, sample: sample)
case "LiveScreen":
LiveScreen(backendType: selectedBackend, sample: sample)
case "FoundationModelsHybrid":
if #available(iOS 27.0, *) {
HybridAIScreen(backendType: selectedBackend)
} else {
Text("Foundation Models are only available on iOS 27 or newer.")
}
case "FoundationModelsVisionID":
if #available(iOS 27.0, *) {
Comment thread
peterfriese marked this conversation as resolved.
VisionIDScreen(backendType: selectedBackend)
} else {
Text("Foundation Models are only available on iOS 27 or newer.")
}
default:
EmptyView()
}
Expand Down
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, *)
Comment thread
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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public class FoundationModelsBaseViewModel: ObservableObject {
class FoundationModelsBaseViewModel: ObservableObject {

@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"))
}
}
}
Loading