From 17ac743d8de5c0e81a9ba2cc053c4cdad817e591 Mon Sep 17 00:00:00 2001 From: haibo Date: Mon, 28 Jul 2025 18:47:13 -0700 Subject: [PATCH 1/2] change ChatMessage Participant system case to model case --- firebaseai/ChatExample/Models/ChatMessage.swift | 6 +++--- .../ChatExample/ViewModels/ConversationViewModel.swift | 4 ++-- firebaseai/ChatExample/Views/MessageView.swift | 10 +++++----- .../ViewModels/FunctionCallingViewModel.swift | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/firebaseai/ChatExample/Models/ChatMessage.swift b/firebaseai/ChatExample/Models/ChatMessage.swift index 345337937..b17e910f7 100644 --- a/firebaseai/ChatExample/Models/ChatMessage.swift +++ b/firebaseai/ChatExample/Models/ChatMessage.swift @@ -16,7 +16,7 @@ import FirebaseAI import Foundation enum Participant { - case system + case model case user } @@ -40,7 +40,7 @@ struct ChatMessage: Identifiable, Equatable { extension ChatMessage { static var samples: [ChatMessage] = [ - .init(message: "Hello. What can I do for you today?", participant: .system), + .init(message: "Hello. What can I do for you today?", participant: .model), .init(message: "Show me a simple loop in Swift.", participant: .user), .init(message: """ Sure, here is a simple loop in Swift: @@ -65,7 +65,7 @@ extension ChatMessage { ``` This loop calculates the sum of the numbers from 1 to 100. The variable sum is initialized to 0, and then the for loop iterates over the range of numbers from 1 to 100. The variable i is assigned each number in the range, and the value of i is added to the sum variable. After the loop has finished executing, the value of sum is printed to the console. - """, participant: .system), + """, participant: .model), ] static var sample = samples[0] diff --git a/firebaseai/ChatExample/ViewModels/ConversationViewModel.swift b/firebaseai/ChatExample/ViewModels/ConversationViewModel.swift index 98a237ec3..e5db8d802 100644 --- a/firebaseai/ChatExample/ViewModels/ConversationViewModel.swift +++ b/firebaseai/ChatExample/ViewModels/ConversationViewModel.swift @@ -81,7 +81,7 @@ class ConversationViewModel: ObservableObject { messages.append(userMessage) // add a pending message while we're waiting for a response from the backend - let systemMessage = ChatMessage.pending(participant: .system) + let systemMessage = ChatMessage.pending(participant: .model) messages.append(systemMessage) do { @@ -121,7 +121,7 @@ class ConversationViewModel: ObservableObject { messages.append(userMessage) // add a pending message while we're waiting for a response from the backend - let systemMessage = ChatMessage.pending(participant: .system) + let systemMessage = ChatMessage.pending(participant: .model) messages.append(systemMessage) do { diff --git a/firebaseai/ChatExample/Views/MessageView.swift b/firebaseai/ChatExample/Views/MessageView.swift index b11c903e5..06092b4c6 100644 --- a/firebaseai/ChatExample/Views/MessageView.swift +++ b/firebaseai/ChatExample/Views/MessageView.swift @@ -62,7 +62,7 @@ struct ResponseTextView: View { .markdownTextStyle { FontFamilyVariant(.normal) FontSize(.em(0.85)) - ForegroundColor(message.participant == .system ? Color(UIColor.label) : .white) + ForegroundColor(message.participant == .model ? Color(UIColor.label) : .white) } .markdownBlockStyle(\.codeBlock) { configuration in configuration.label @@ -90,16 +90,16 @@ struct MessageView: View { } MessageContentView(message: message) .padding(10) - .background(message.participant == .system + .background(message.participant == .model ? Color(UIColor.systemFill) : Color(UIColor.systemBlue)) .roundedCorner(10, corners: [ .topLeft, .topRight, - message.participant == .system ? .bottomRight : .bottomLeft, + message.participant == .model ? .bottomRight : .bottomLeft, ]) - if message.participant == .system { + if message.participant == .model { Spacer() } } @@ -114,7 +114,7 @@ struct MessageView_Previews: PreviewProvider { MessageView(message: ChatMessage.samples[0]) MessageView(message: ChatMessage.samples[1]) MessageView(message: ChatMessage.samples[2]) - MessageView(message: ChatMessage(message: "Hello!", participant: .system, pending: true)) + MessageView(message: ChatMessage(message: "Hello!", participant: .model, pending: true)) } .listStyle(.plain) .navigationTitle("Chat example") diff --git a/firebaseai/FunctionCallingExample/ViewModels/FunctionCallingViewModel.swift b/firebaseai/FunctionCallingExample/ViewModels/FunctionCallingViewModel.swift index 8bd7f90ef..7129dd332 100644 --- a/firebaseai/FunctionCallingExample/ViewModels/FunctionCallingViewModel.swift +++ b/firebaseai/FunctionCallingExample/ViewModels/FunctionCallingViewModel.swift @@ -75,7 +75,7 @@ class FunctionCallingViewModel: ObservableObject { messages.append(userMessage) // add a pending message while we're waiting for a response from the backend - let systemMessage = ChatMessage.pending(participant: .system) + let systemMessage = ChatMessage.pending(participant: .model) messages.append(systemMessage) print(messages) @@ -224,7 +224,7 @@ private extension FunctionCallPart { } let messageText = "Function call requested by model:\n```\n\(json)\n```" - return ChatMessage(message: messageText, participant: .system) + return ChatMessage(message: messageText, participant: .model) } } From bae64f70d5c54d586fbcf02324f800964566f823 Mon Sep 17 00:00:00 2001 From: haibo Date: Mon, 28 Jul 2025 18:57:05 -0700 Subject: [PATCH 2/2] change systemMessage to modelMessage --- .../ChatExample/ViewModels/ConversationViewModel.swift | 8 ++++---- .../ViewModels/FunctionCallingViewModel.swift | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/firebaseai/ChatExample/ViewModels/ConversationViewModel.swift b/firebaseai/ChatExample/ViewModels/ConversationViewModel.swift index e5db8d802..5bb890cf7 100644 --- a/firebaseai/ChatExample/ViewModels/ConversationViewModel.swift +++ b/firebaseai/ChatExample/ViewModels/ConversationViewModel.swift @@ -81,8 +81,8 @@ class ConversationViewModel: ObservableObject { messages.append(userMessage) // add a pending message while we're waiting for a response from the backend - let systemMessage = ChatMessage.pending(participant: .model) - messages.append(systemMessage) + let modelMessage = ChatMessage.pending(participant: .model) + messages.append(modelMessage) do { let responseStream = try chat.sendMessageStream(text) @@ -121,8 +121,8 @@ class ConversationViewModel: ObservableObject { messages.append(userMessage) // add a pending message while we're waiting for a response from the backend - let systemMessage = ChatMessage.pending(participant: .model) - messages.append(systemMessage) + let modelMessage = ChatMessage.pending(participant: .model) + messages.append(modelMessage) do { var response: GenerateContentResponse? diff --git a/firebaseai/FunctionCallingExample/ViewModels/FunctionCallingViewModel.swift b/firebaseai/FunctionCallingExample/ViewModels/FunctionCallingViewModel.swift index 7129dd332..3b1cf99d5 100644 --- a/firebaseai/FunctionCallingExample/ViewModels/FunctionCallingViewModel.swift +++ b/firebaseai/FunctionCallingExample/ViewModels/FunctionCallingViewModel.swift @@ -75,8 +75,8 @@ class FunctionCallingViewModel: ObservableObject { messages.append(userMessage) // add a pending message while we're waiting for a response from the backend - let systemMessage = ChatMessage.pending(participant: .model) - messages.append(systemMessage) + let modelMessage = ChatMessage.pending(participant: .model) + messages.append(modelMessage) print(messages) do {