diff --git a/main.go b/main.go index fe1d8da..a6dd024 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/pkg/openai/respond.go b/pkg/openai/respond.go index bcfcfe9..d4e60f8 100644 --- a/pkg/openai/respond.go +++ b/pkg/openai/respond.go @@ -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)