Skip to content

[FirebaseAI] Change Participant.system case to Participant.model case #1738

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions firebaseai/ChatExample/Models/ChatMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import FirebaseAI
import Foundation

enum Participant {
case system
case model
case user
}

Expand All @@ -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:
Expand All @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions firebaseai/ChatExample/ViewModels/ConversationViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: .system)
messages.append(systemMessage)
let modelMessage = ChatMessage.pending(participant: .model)
messages.append(modelMessage)

do {
let responseStream = try chat.sendMessageStream(text)
Expand Down Expand Up @@ -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: .system)
messages.append(systemMessage)
let modelMessage = ChatMessage.pending(participant: .model)
messages.append(modelMessage)

do {
var response: GenerateContentResponse?
Expand Down
10 changes: 5 additions & 5 deletions firebaseai/ChatExample/Views/MessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: .system)
messages.append(systemMessage)
let modelMessage = ChatMessage.pending(participant: .model)
messages.append(modelMessage)

print(messages)
do {
Expand Down Expand Up @@ -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)
}
}

Expand Down