yao/aigc/aigc_test.go
2023-04-27 22:31:51 +08:00

57 lines
1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package aigc
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/yaoapp/yao/config"
"github.com/yaoapp/yao/test"
)
func TestCall(t *testing.T) {
test.Prepare(t, config.Conf)
defer test.Clean()
prepare(t)
aigc, err := Select("translate")
if err != nil {
t.Fatal(err)
}
content, ex := aigc.Call("你好哇", "", nil)
if ex != nil {
t.Fatal(ex.Message)
}
assert.Equal(t, "Hello", content)
}
func TestCallWithProcess(t *testing.T) {
test.Prepare(t, config.Conf)
defer test.Clean()
prepare(t)
aigc, err := Select("draw")
if err != nil {
t.Fatal(err)
}
args, ex := aigc.Call("帮我画一只小白兔,要有白色的耳朵. 画布高度 256宽度 256", "", nil)
if ex != nil {
t.Fatal(ex.Message)
}
data, ok := args.(map[string]interface{})
if !ok {
t.Fatal("args is not map[string]interface{}")
}
assert.Equal(t, float64(256), data["height"])
assert.Equal(t, float64(256), data["width"])
}
func prepare(t *testing.T) {
err := Load(config.Conf)
if err != nil {
t.Fatal(err)
}
}