mirror of
https://github.com/alibaba/higress.git
synced 2026-06-05 10:37:28 +08:00
feat(plugin) add ai-history plugin (#1224)
This commit is contained in:
36
plugins/wasm-go/extensions/ai-history/main_test.go
Normal file
36
plugins/wasm-go/extensions/ai-history/main_test.go
Normal 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user