2024-08-22 18:57:49 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2024-09-15 13:09:45 +00:00
|
|
|
goopenai "github.com/sashabaranov/go-openai"
|
2024-08-22 18:57:49 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNormalizeMessages(t *testing.T) {
|
|
|
|
msgs := []*Message{
|
2024-09-15 13:09:45 +00:00
|
|
|
{Role: goopenai.ChatMessageRoleUser, Content: "Hello"},
|
|
|
|
{Role: goopenai.ChatMessageRoleAssistant, Content: "Hi there!"},
|
|
|
|
{Role: goopenai.ChatMessageRoleUser, Content: ""},
|
|
|
|
{Role: goopenai.ChatMessageRoleUser, Content: ""},
|
|
|
|
{Role: goopenai.ChatMessageRoleUser, Content: "How are you?"},
|
2024-08-22 18:57:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expected := []*Message{
|
2024-09-15 13:09:45 +00:00
|
|
|
{Role: goopenai.ChatMessageRoleUser, Content: "Hello"},
|
|
|
|
{Role: goopenai.ChatMessageRoleAssistant, Content: "Hi there!"},
|
|
|
|
{Role: goopenai.ChatMessageRoleUser, Content: "How are you?"},
|
2024-08-22 18:57:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
actual := NormalizeMessages(msgs, "default")
|
|
|
|
assert.Equal(t, expected, actual)
|
|
|
|
}
|