feat(plugin) add ai-history plugin (#1224)

This commit is contained in:
sakura
2024-08-27 19:24:39 +08:00
committed by GitHub
parent 6701a86e66
commit 75e1defd6c
8 changed files with 802 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
package main
import (
"reflect"
"testing"
)
func TestDistinctChat(t *testing.T) {
type args struct {
chat []ChatHistory
currMessage []ChatHistory
}
firstChat := []ChatHistory{{Role: "user", Content: "userInput1"}, {Role: "assistant", Content: "assistantOutput1"}}
sendUser := []ChatHistory{{Role: "user", Content: "userInput2"}}
tests := []struct {
name string
args args
want []ChatHistory
}{
{name: "填充历史", args: args{
chat: append([]ChatHistory{}, firstChat...),
currMessage: append([]ChatHistory{}, sendUser...)},
want: append(append([]ChatHistory{}, firstChat...), sendUser...)},
{name: "无需填充", args: args{
chat: append([]ChatHistory{}, firstChat...),
currMessage: append(append([]ChatHistory{}, firstChat...), sendUser...)},
want: append(append([]ChatHistory{}, firstChat...), sendUser...)},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := fillHistory(tt.args.chat, tt.args.currMessage, 3); !reflect.DeepEqual(got, tt.want) {
t.Errorf("fillHistory() = %v, want %v", got, tt.want)
}
})
}
}