-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
file_test.go
71 lines (55 loc) · 1.92 KB
/
file_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
60
61
62
63
64
65
66
67
68
69
70
71
package zhipu
import (
"context"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
func TestFileServiceFineTune(t *testing.T) {
client, err := NewClient()
require.NoError(t, err)
s := client.FileCreate(FilePurposeFineTune)
s.SetLocalFile(filepath.Join("testdata", "test-file.jsonl"))
res, err := s.Do(context.Background())
require.NoError(t, err)
require.NotZero(t, res.Bytes)
require.NotZero(t, res.CreatedAt)
require.NotEmpty(t, res.ID)
}
func TestFileServiceKnowledge(t *testing.T) {
client, err := NewClient()
require.NoError(t, err)
s := client.FileCreate(FilePurposeRetrieval)
s.SetKnowledgeID(os.Getenv("TEST_KNOWLEDGE_ID"))
s.SetLocalFile(filepath.Join("testdata", "test-file.txt"))
res, err := s.Do(context.Background())
require.NoError(t, err)
require.NotEmpty(t, res.SuccessInfos)
require.NotEmpty(t, res.SuccessInfos[0].DocumentID)
require.NotEmpty(t, res.SuccessInfos[0].Filename)
documentID := res.SuccessInfos[0].DocumentID
res2, err := client.FileGet(documentID).Do(context.Background())
require.NoError(t, err)
require.NotEmpty(t, res2.ID)
err = client.FileEdit(documentID).SetKnowledgeType(KnowledgeTypeCustom).Do(context.Background())
require.True(t, err == nil || GetAPIErrorCode(err) == "10019")
err = client.FileDelete(res.SuccessInfos[0].DocumentID).Do(context.Background())
require.True(t, err == nil || GetAPIErrorCode(err) == "10019")
}
func TestFileListServiceKnowledge(t *testing.T) {
client, err := NewClient()
require.NoError(t, err)
s := client.FileList(FilePurposeRetrieval).SetKnowledgeID(os.Getenv("TEST_KNOWLEDGE_ID"))
res, err := s.Do(context.Background())
require.NoError(t, err)
require.NotEmpty(t, res.List)
}
func TestFileListServiceFineTune(t *testing.T) {
client, err := NewClient()
require.NoError(t, err)
s := client.FileList(FilePurposeFineTune)
res, err := s.Do(context.Background())
require.NoError(t, err)
require.NotEmpty(t, res.Data)
}