-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
batch_test.go
59 lines (46 loc) · 1.55 KB
/
batch_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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package zhipu
import (
"bytes"
"context"
"testing"
"github.com/stretchr/testify/require"
)
func TestBatchServiceAll(t *testing.T) {
client, err := NewClient()
require.NoError(t, err)
buf := &bytes.Buffer{}
bfw := NewBatchFileWriter(buf)
err = bfw.Write("batch_1", client.ChatCompletion("glm-4-flash").AddMessage(ChatCompletionMessage{
Role: RoleUser, Content: "你好呀",
}))
require.NoError(t, err)
err = bfw.Write("batch_2", client.ChatCompletion("glm-4-flash").AddMessage(ChatCompletionMessage{
Role: RoleUser, Content: "你叫什么名字",
}))
require.NoError(t, err)
res, err := client.FileCreate(FilePurposeBatch).SetFile(bytes.NewReader(buf.Bytes()), "batch.jsonl").Do(context.Background())
require.NoError(t, err)
fileID := res.FileCreateFineTuneResponse.ID
require.NotEmpty(t, fileID)
res1, err := client.BatchCreate().
SetInputFileID(fileID).
SetCompletionWindow(BatchCompletionWindow24h).
SetEndpoint(BatchEndpointV4ChatCompletions).Do(context.Background())
require.NoError(t, err)
require.NotEmpty(t, res1.ID)
res2, err := client.BatchGet(res1.ID).Do(context.Background())
require.NoError(t, err)
require.Equal(t, res2.ID, res1.ID)
res3, err := client.BatchList().Do(context.Background())
require.NoError(t, err)
require.NotEmpty(t, res3.Data)
err = client.BatchCancel(res1.ID).Do(context.Background())
require.NoError(t, err)
}
func TestBatchListService(t *testing.T) {
client, err := NewClient()
require.NoError(t, err)
res, err := client.BatchList().Do(context.Background())
require.NoError(t, err)
t.Log(res)
}