Skip to content

Commit

Permalink
fix history removal error
Browse files Browse the repository at this point in the history
  • Loading branch information
eastriverlee committed Jan 27, 2024
1 parent 94ca511 commit e27f19c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Sources/LLM/LLM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ open class LLM: ObservableObject {
output.yield("Input is too long.")
return false
} else {
history.removeFirst(2)
history.removeFirst(min(2, history.count))
tokens = encode(preProcess(self.input, history))
initialCount = tokens.count
currentCount = Int32(initialCount)
Expand Down Expand Up @@ -282,8 +282,9 @@ open class LLM: ObservableObject {
let response = getResponse(from: processedInput)
let output = await makeOutputFrom(response)
history += [(.user, input), (.bot, output)]
if historyLimit < history.count {
history.removeFirst(2)
let historyCount = history.count
if historyLimit < historyCount {
history.removeFirst(min(2, historyCount))
}
postProcess(output)
isAvailable = true
Expand Down

0 comments on commit e27f19c

Please sign in to comment.