Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
82 changes: 47 additions & 35 deletions firebaseai/FirebaseAIExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
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 */; };
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 */; };
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 +32,12 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
88151ADC2EC9345700775CFB /* MarkdownUI in Frameworks */,
88779D932EC8AC460080D023 /* FirebaseAILogic in Frameworks */,
88779D902EC8AA920080D023 /* ConversationKit 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 */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -74,9 +80,12 @@
);
name = FirebaseAIExample;
packageProductDependencies = (
88779D8F2EC8AA920080D023 /* ConversationKit */,
88779D922EC8AC460080D023 /* FirebaseAILogic */,
88151ADB2EC9345700775CFB /* MarkdownUI */,
88862D5E2FD7C19F003702C7 /* FirebaseAILogic */,
88862D602FD7C19F003702C7 /* FirebaseAppCheck */,
88862D622FD7C19F003702C7 /* FirebaseCore */,
88AAB45F2FF0077E001B143E /* FirebaseAppCheck */,
88AAB4612FF0077E001B143E /* FirebaseCore */,
88AAB4642FF007DD001B143E /* ConversationKit */,
);
productName = FirebaseAIExample;
productReference = 88779D352EC8A9CF0080D023 /* FirebaseAIExample.app */;
Expand Down Expand Up @@ -107,9 +116,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 /* XCRemoteSwiftPackageReference "ConversationKit" */,
);
preferredProjectObjectVersion = 77;
productRefGroup = 88779D362EC8A9CF0080D023 /* Products */;
Expand Down Expand Up @@ -353,47 +361,51 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
88151ADA2EC9345700775CFB /* XCRemoteSwiftPackageReference "swift-markdown-ui" */ = {
88AAB45C2FF0077E001B143E /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/gonzalezreal/swift-markdown-ui";
repositoryURL = "https://github.com/firebase/firebase-ios-sdk/";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 2.4.1;
branch = "wwdc26-preview";
kind = branch;
};
};
88779D8E2EC8AA920080D023 /* XCRemoteSwiftPackageReference "ConversationKit" */ = {
88AAB4632FF007DD001B143E /* XCRemoteSwiftPackageReference "ConversationKit" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/peterfriese/ConversationKit";
requirement = {
kind = exactVersion;
version = 0.0.4;
};
};
88779D912EC8AC460080D023 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/firebase/firebase-ios-sdk";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 12.15.0;
minimumVersion = 0.0.4;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
88151ADB2EC9345700775CFB /* MarkdownUI */ = {
88862D5E2FD7C19F003702C7 /* FirebaseAILogic */ = {
isa = XCSwiftPackageProductDependency;
package = 88151ADA2EC9345700775CFB /* XCRemoteSwiftPackageReference "swift-markdown-ui" */;
productName = MarkdownUI;
productName = FirebaseAILogic;
};
88779D8F2EC8AA920080D023 /* ConversationKit */ = {
88862D602FD7C19F003702C7 /* FirebaseAppCheck */ = {
isa = XCSwiftPackageProductDependency;
package = 88779D8E2EC8AA920080D023 /* XCRemoteSwiftPackageReference "ConversationKit" */;
productName = ConversationKit;
productName = FirebaseAppCheck;
};
88779D922EC8AC460080D023 /* FirebaseAILogic */ = {
88862D622FD7C19F003702C7 /* FirebaseCore */ = {
isa = XCSwiftPackageProductDependency;
package = 88779D912EC8AC460080D023 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */;
productName = FirebaseAILogic;
productName = FirebaseCore;
};
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;
package = 88AAB4632FF007DD001B143E /* XCRemoteSwiftPackageReference "ConversationKit" */;
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
struct IdentifiedObject: Equatable, Codable {
@Guide(description: "The name of the primary object or landmark detected.")
let name: String

@Guide(
description: "The category of the object (e.g. Landmark, Plant, Food, Animal, Device, Clothing)."
)
let category: String

@Guide(description: "A short, 2-sentence description of the object and interesting facts.")
let description: String
}

@available(iOS 26.0, *)
@Generable
struct TextSummary: Equatable, Codable {
@Guide(description: "A list of exactly 2 key summary points.")
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

enum ModelPreference: String, CaseIterable, Identifiable {
case auto = "Auto (Local First)"
case cloud = "Cloud Only"

var id: String { rawValue }
}

@available(iOS 27.0, *)
@MainActor
class FoundationModelsBaseViewModel: ObservableObject {
@Published var inProgress = false
@Published var error: Error?
@Published var modelPreference: ModelPreference = .auto
@Published var isUsingLocalModel: Bool = false

internal var activeTask: Task<Void, Never>?
let backendType: BackendOption

init(backendType: BackendOption) {
self.backendType = backendType
}

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
Loading