Skip to content

Commit d4d1edd

Browse files
committed
Add function calling tip
1 parent b20448c commit d4d1edd

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

firebaseai/FirebaseAIExample.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
0E5E76732EB2B47400E6B3CF /* TipView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E5E76722EB2B47000E6B3CF /* TipView.swift */; };
11+
0E5E76742EB2B47400E6B3CF /* TipView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E5E76722EB2B47000E6B3CF /* TipView.swift */; };
1012
0ECE3A982EB286120072EC6A /* Color+Hex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ECE3A972EB2860C0072EC6A /* Color+Hex.swift */; };
1113
0ECE3A992EB286120072EC6A /* Color+Hex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ECE3A972EB2860C0072EC6A /* Color+Hex.swift */; };
1214
0ECE3A9B2EB286B90072EC6A /* ApplicationError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ECE3A9A2EB286AD0072EC6A /* ApplicationError.swift */; };
@@ -125,6 +127,7 @@
125127
/* End PBXCopyFilesBuildPhase section */
126128

127129
/* Begin PBXFileReference section */
130+
0E5E76722EB2B47000E6B3CF /* TipView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TipView.swift; sourceTree = "<group>"; };
128131
0ECE3A972EB2860C0072EC6A /* Color+Hex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Color+Hex.swift"; sourceTree = "<group>"; };
129132
0ECE3A9A2EB286AD0072EC6A /* ApplicationError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationError.swift; sourceTree = "<group>"; };
130133
0EE94F112E9599B800CEFD69 /* AudioBufferHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioBufferHelpers.swift; sourceTree = "<group>"; };
@@ -250,6 +253,7 @@
250253
0EE94F222E9599B800CEFD69 /* Views */ = {
251254
isa = PBXGroup;
252255
children = (
256+
0E5E76722EB2B47000E6B3CF /* TipView.swift */,
253257
0EE94F1D2E9599B800CEFD69 /* ConnectButton.swift */,
254258
0EE94F1E2E9599B800CEFD69 /* LiveErrorDetailsView.swift */,
255259
0EE94F1F2E9599B800CEFD69 /* LiveErrorView.swift */,
@@ -644,6 +648,7 @@
644648
0EE94F2D2E9599B800CEFD69 /* LiveErrorView.swift in Sources */,
645649
0EE94F2E2E9599B800CEFD69 /* Microphone.swift in Sources */,
646650
0EE94F2F2E9599B800CEFD69 /* LiveErrorDetailsView.swift in Sources */,
651+
0E5E76742EB2B47400E6B3CF /* TipView.swift in Sources */,
647652
0EE94F302E9599B800CEFD69 /* AudioController.swift in Sources */,
648653
0EE94F312E9599B800CEFD69 /* AudioBufferHelpers.swift in Sources */,
649654
86BB55F02E8B2D6D0054B8B5 /* GenerateContentScreen.swift in Sources */,
@@ -685,6 +690,7 @@
685690
0EE94F3C2E9599B800CEFD69 /* LiveErrorView.swift in Sources */,
686691
0EE94F3D2E9599B800CEFD69 /* Microphone.swift in Sources */,
687692
0EE94F3E2E9599B800CEFD69 /* LiveErrorDetailsView.swift in Sources */,
693+
0E5E76732EB2B47400E6B3CF /* TipView.swift in Sources */,
688694
0EE94F3F2E9599B800CEFD69 /* AudioController.swift in Sources */,
689695
0EE94F402E9599B800CEFD69 /* AudioBufferHelpers.swift in Sources */,
690696
886F95D52B17BA010036F07A /* GenerateContentScreen.swift in Sources */,

firebaseai/LiveAudioExample/Screens/LiveAudioScreen.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ struct LiveAudioScreen: View {
3939
if let error = viewModel.error {
4040
LiveErrorView(error: error)
4141
}
42+
if !viewModel.hasTranscripts {
43+
TipView(text: "Try asking the model to change the background color")
44+
}
4245
ConnectButton(
4346
state: viewModel.state,
4447
onConnect: viewModel.connect,

firebaseai/LiveAudioExample/ViewModels/LiveViewModel.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class LiveViewModel: ObservableObject {
4141
@Published
4242
var backgroundColor: Color? = nil
4343

44+
@Published
45+
var hasTranscripts: Bool = false
46+
4447
private var model: LiveGenerativeModel?
4548
private var liveSession: LiveSession?
4649

@@ -91,6 +94,7 @@ class LiveViewModel: ObservableObject {
9194

9295
state = .connecting
9396
transcriptViewModel.restart()
97+
hasTranscripts = false
9498

9599
do {
96100
liveSession = try await model.connect()
@@ -234,6 +238,7 @@ class LiveViewModel: ObservableObject {
234238
}
235239

236240
private func appendAudioTranscript(_ transcript: String) {
241+
hasTranscripts = true
237242
transcriptViewModel.appendTranscript(transcript)
238243
}
239244

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import SwiftUI
16+
17+
struct TipView: View {
18+
let text: String
19+
20+
var body: some View {
21+
VStack(alignment: .leading, spacing: 5) {
22+
Label("Tip", systemImage: "info.circle").bold().foregroundStyle(.blue)
23+
Text(text)
24+
.font(.caption).italic()
25+
}
26+
}
27+
}
28+
29+
#Preview {
30+
TipView(text: "Try asking the model to change the background color")
31+
}

0 commit comments

Comments
 (0)