Skip to content

Commit

Permalink
fix: don't remove pre-prompt on maxHistory breach
Browse files Browse the repository at this point in the history
  • Loading branch information
rhnvrm committed Apr 10, 2023
1 parent 62d3079 commit a3e84ef
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func main() {

// Setup openai store. TODO: make configurable
ttl := int64(24 * time.Hour) // 1 day
maxHistory := 10 // store only 10
maxHistory := 20 // store only 10

store := openai.NewStore(ttl, maxHistory)

Expand Down
5 changes: 3 additions & 2 deletions pkg/openai/respond.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ func (r *Responder) Respond(interactionKey string, prompts []ChatCompletionMessa

prompts = append(prompts, msgsRecv...)

// if cache size is greater than 10, remove the oldest message
// if cache size is greater than maxHistory, remove the oldest message
// but keep the first message as that is the pre-prompt
if len(prompts) > r.store.maxHistory {
prompts = prompts[1:]
prompts = append(prompts[:1], prompts[2:]...)
}

r.store.Set(interactionKey, prompts)
Expand Down

0 comments on commit a3e84ef

Please sign in to comment.