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) {
|
2024-10-29 21:03:47 +00:00
|
|
|
msgs := []*goopenai.ChatCompletionMessage{
|
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
|
|
|
}
|
|
|
|
|
2024-10-29 21:03:47 +00:00
|
|
|
expected := []*goopenai.ChatCompletionMessage{
|
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)
|
|
|
|
}
|