Skip to content
Merged
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
10 changes: 8 additions & 2 deletions FirebaseAI/Sources/Chat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public final class Chat: Sendable {
}
}

private func appendHistory(_ newElement: ModelContent) {
historyLock.withLock {
_history.append(newElement)
}
}

/// Sends a message using the existing history of this chat as context. If successful, the message
/// and response will be added to the history. If unsuccessful, history will remain unchanged.
/// - Parameter parts: The new content to send as a single chat message.
Expand Down Expand Up @@ -82,7 +88,7 @@ public final class Chat: Sendable {

// Append the request and successful result to history, then return the value.
appendHistory(contentsOf: newContent)
history.append(toAdd)
appendHistory(toAdd)
return result
}

Expand Down Expand Up @@ -134,7 +140,7 @@ public final class Chat: Sendable {

// Aggregate the content to add it to the history before we finish.
let aggregated = self.aggregatedChunks(aggregatedContent)
self.history.append(aggregated)
self.appendHistory(aggregated)
continuation.finish()
}
}
Expand Down
Loading