Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions firebaseai/ChatExample/ViewModels/ConversationViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
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,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)
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