Skip to content

Commit 42a4c8d

Browse files
committed
Setup a truncation limit
1 parent 335642f commit 42a4c8d

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

Tool/Sources/OpenAIService/Memory/TemplateChatGPTMemory.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ public actor TemplateChatGPTMemory: ChatGPTMemory {
4444
return tokenCount <= configuration.maxTokens - configuration.minimumReplyTokens
4545
}
4646

47+
var truncationTimes = 500
4748
while !(await checkTokenCount()) {
4849
do {
50+
truncationTimes -= 1
51+
if truncationTimes <= 0 {
52+
throw CancellationError()
53+
}
4954
try Task.checkCancellation()
5055
try await memoryTemplate.truncate()
5156
} catch {

0 commit comments

Comments
 (0)