-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathmain.go
112 lines (98 loc) · 2.59 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright 2024 Deepgram SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT
package main
import (
"context"
"fmt"
"os"
api "github.com/deepgram/deepgram-go-sdk/pkg/api/manage/v1"
client "github.com/deepgram/deepgram-go-sdk/pkg/client/manage"
)
func main() {
// init library
client.InitWithDefault()
// context
ctx := context.Background()
//client
dg := client.NewWithDefaults()
mgClient := api.New(dg)
// list projects
respList, err := mgClient.ListProjects(ctx)
if err != nil {
fmt.Printf("ListProjects failed. Err: %v\n", err)
os.Exit(1)
}
// save 1 project
var projectID string
for _, item := range respList.Projects {
projectID = item.ProjectID
name := item.Name
fmt.Printf("ListProjects() - Name: %s, ID: %s\n", name, projectID)
break
}
fmt.Printf("\n\n\n")
// list models
respModels, err := mgClient.ListModels(ctx, nil)
if err != nil {
fmt.Printf("ListModels() failed. Err: %v\n", err)
os.Exit(1)
}
modelId := ""
if respModels == nil {
fmt.Printf("ListModels() - No models found\n")
} else {
for _, item := range respModels.Stt {
id := item.UUID
name := item.Name
fmt.Printf("STT - ID: %s, Scope: %s\n", id, name)
modelId = id // save one model id
}
for _, item := range respModels.Tts {
id := item.UUID
name := item.Name
fmt.Printf("TTS - ID: %s, Scope: %s\n", id, name)
}
}
fmt.Printf("\n\n\n")
// get model
respModel, err := mgClient.GetModel(ctx, modelId)
if err != nil {
fmt.Printf("GetModel failed. Err: %v\n", err)
os.Exit(1)
} else {
fmt.Printf("GetModel() - ID: %s, Name: %s\n", respModel.UUID, respModel.Name)
}
fmt.Printf("\n\n\n")
// list project models
respModels, err = mgClient.ListProjectModels(ctx, projectID, nil)
if err != nil {
fmt.Printf("ListProjectModels failed. Err: %v\n", err)
os.Exit(1)
}
modelId = ""
if respModels == nil {
fmt.Printf("ListModels() - No models found\n")
} else {
for _, item := range respModels.Stt {
id := item.UUID
name := item.Name
fmt.Printf("STT - ID: %s, Scope: %s\n", id, name)
modelId = id // save one model id
}
for _, item := range respModels.Tts {
id := item.UUID
name := item.Name
fmt.Printf("TTS - ID: %s, Scope: %s\n", id, name)
}
}
fmt.Printf("\n\n\n")
// get model
respModel, err = mgClient.GetProjectModel(ctx, projectID, modelId)
if err != nil {
fmt.Printf("GetProjectModel failed. Err: %v\n", err)
os.Exit(1)
} else {
fmt.Printf("GetProjectModel() - ID: %s, Name: %s\n", respModel.UUID, respModel.Name)
}
}