-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathfunction_call_test.go
40 lines (32 loc) · 1.12 KB
/
function_call_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package ai
import (
"testing"
"github.com/stretchr/testify/assert"
)
var original = &FunctionCall{
ReqID: "yYdzyl",
Arguments: "{\n \"sourceTimezone\": \"America/Los_Angeles\",\n \"targetTimezone\": \"Asia/Singapore\",\n \"timeString\": \"2024-03-25 07:00:00\"\n}",
FunctionName: "fn-timezone-converter",
ToolCallID: "call_aZrtm5xcLs1qtP0SWo4CZi75",
IsOK: false,
}
func TestFunctionCallBytes(t *testing.T) {
t.Run("ok", func(t *testing.T) {
bytes, err := original.Bytes()
assert.NoError(t, err)
actual := &FunctionCall{}
err = actual.FromBytes(bytes)
assert.NoError(t, err)
assert.Equal(t, original, actual)
})
t.Run("data is not a json string", func(t *testing.T) {
actual := &FunctionCall{}
err := actual.FromBytes([]byte("not a json string"))
assert.EqualError(t, err, "llm-sfn: cannot read function call object from context data")
})
t.Run("data cannot be unmarshaled as FunctionCall", func(t *testing.T) {
actual := &FunctionCall{}
err := actual.FromBytes([]byte(`{"hello":"yomo"}`))
assert.EqualError(t, err, "llm-sfn: cannot read function call object from context data")
})
}