File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,12 @@ public final class Chat: Sendable {
4545 }
4646 }
4747
48+ private func appendHistory( _ newElement: ModelContent ) {
49+ historyLock. withLock {
50+ _history. append ( newElement)
51+ }
52+ }
53+
4854 /// Sends a message using the existing history of this chat as context. If successful, the message
4955 /// and response will be added to the history. If unsuccessful, history will remain unchanged.
5056 /// - Parameter parts: The new content to send as a single chat message.
@@ -82,7 +88,7 @@ public final class Chat: Sendable {
8288
8389 // Append the request and successful result to history, then return the value.
8490 appendHistory ( contentsOf: newContent)
85- history . append ( toAdd)
91+ appendHistory ( toAdd)
8692 return result
8793 }
8894
@@ -134,7 +140,7 @@ public final class Chat: Sendable {
134140
135141 // Aggregate the content to add it to the history before we finish.
136142 let aggregated = self . aggregatedChunks ( aggregatedContent)
137- self . history . append ( aggregated)
143+ self . appendHistory ( aggregated)
138144 continuation. finish ( )
139145 }
140146 }
You can’t perform that action at this time.
0 commit comments