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 {
45
45
}
46
46
}
47
47
48
+ private func appendHistory( _ newElement: ModelContent ) {
49
+ historyLock. withLock {
50
+ _history. append ( newElement)
51
+ }
52
+ }
53
+
48
54
/// Sends a message using the existing history of this chat as context. If successful, the message
49
55
/// and response will be added to the history. If unsuccessful, history will remain unchanged.
50
56
/// - Parameter parts: The new content to send as a single chat message.
@@ -82,7 +88,7 @@ public final class Chat: Sendable {
82
88
83
89
// Append the request and successful result to history, then return the value.
84
90
appendHistory ( contentsOf: newContent)
85
- history . append ( toAdd)
91
+ appendHistory ( toAdd)
86
92
return result
87
93
}
88
94
@@ -134,7 +140,7 @@ public final class Chat: Sendable {
134
140
135
141
// Aggregate the content to add it to the history before we finish.
136
142
let aggregated = self . aggregatedChunks ( aggregatedContent)
137
- self . history . append ( aggregated)
143
+ self . appendHistory ( aggregated)
138
144
continuation. finish ( )
139
145
}
140
146
}
You can’t perform that action at this time.
0 commit comments