-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
73 lines (61 loc) · 1.81 KB
/
main.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
72
73
package main
import (
"context"
"fmt"
"os"
"strconv"
"github.com/coze-dev/coze-go"
)
func main() {
// Get an access_token through personal access token or oauth.
token := os.Getenv("COZE_API_TOKEN")
authCli := coze.NewTokenAuth(token)
// Init the Coze client through the access_token.
cozeCli := coze.NewCozeAPI(authCli, coze.WithBaseURL(os.Getenv("COZE_API_BASE")))
ctx := context.Background()
datasetID, _ := strconv.ParseInt(os.Getenv("DATASET_ID"), 10, 64)
//
// create document in to specific dataset
createReq := &coze.CreateDatasetsDocumentsReq{
DatasetID: datasetID,
DocumentBases: []*coze.DocumentBase{
coze.DocumentBaseBuildLocalFile("file doc examples", "your file content", "txt"),
},
}
createResp, err := cozeCli.Datasets.Documents.Create(ctx, createReq)
if err != nil {
fmt.Println("Error creating documents:", err)
return
}
fmt.Println(createResp)
fmt.Println(createResp.LogID())
var documentIDs []int64
for _, doc := range createResp.DocumentInfos {
id, _ := strconv.ParseInt(doc.DocumentID, 10, 64)
documentIDs = append(documentIDs, id)
}
//
// update document. It means success that no exception has been thrown
updateReq := &coze.UpdateDatasetsDocumentsReq{
DocumentID: documentIDs[0],
DocumentName: "new name",
}
updateResp, err := cozeCli.Datasets.Documents.Update(ctx, updateReq)
if err != nil {
fmt.Println("Error updating document:", err)
return
}
fmt.Println(updateResp)
fmt.Println(updateResp.LogID())
//
// delete document. It means success that no exception has been thrown
deleteResp, err := cozeCli.Datasets.Documents.Delete(ctx, &coze.DeleteDatasetsDocumentsReq{
DocumentIDs: []int64{documentIDs[0]},
})
if err != nil {
fmt.Println("Error deleting document:", err)
return
}
fmt.Println(deleteResp)
fmt.Println(deleteResp.LogID())
}