generated from speakeasy-sdks/template-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
honeyhive.go
executable file
·154 lines (131 loc) · 3.05 KB
/
honeyhive.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package honeyhive
import (
"github.com/speakeasy-sdks/honeyhive-go-sdk/pkg/models/shared"
"github.com/speakeasy-sdks/honeyhive-go-sdk/pkg/utils"
"net/http"
"time"
)
var ServerList = []string{
"https://honeyhive.ai:5000/",
}
type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}
// SDK Documentation: https://docs.honeyhive.ai/api-reference/authentication - HoneyHive Docs
type Honeyhive struct {
Dataset *dataset
Feedback *feedback
FineTunedModel *fineTunedModel
Generation *generation
Metric *metric
Prompt *prompt
Task *task
// Non-idiomatic field names below are to namespace fields from the fields names above to avoid name conflicts
_defaultClient HTTPClient
_securityClient HTTPClient
_security *shared.Security
_serverURL string
_language string
_sdkVersion string
_genVersion string
}
type SDKOption func(*Honeyhive)
func WithServerURL(serverURL string, params map[string]string) SDKOption {
return func(sdk *Honeyhive) {
if params != nil {
serverURL = utils.ReplaceParameters(serverURL, params)
}
sdk._serverURL = serverURL
}
}
func WithClient(client HTTPClient) SDKOption {
return func(sdk *Honeyhive) {
sdk._defaultClient = client
}
}
func WithSecurity(security shared.Security) SDKOption {
return func(sdk *Honeyhive) {
sdk._security = &security
}
}
func New(opts ...SDKOption) *Honeyhive {
sdk := &Honeyhive{
_language: "go",
_sdkVersion: "0.3.0",
_genVersion: "1.6.0",
}
for _, opt := range opts {
opt(sdk)
}
// Use WithClient to override the default client if you would like to customize the timeout
if sdk._defaultClient == nil {
sdk._defaultClient = &http.Client{Timeout: 60 * time.Second}
}
if sdk._securityClient == nil {
if sdk._security != nil {
sdk._securityClient = utils.ConfigureSecurityClient(sdk._defaultClient, sdk._security)
} else {
sdk._securityClient = sdk._defaultClient
}
}
if sdk._serverURL == "" {
sdk._serverURL = ServerList[0]
}
sdk.Dataset = newDataset(
sdk._defaultClient,
sdk._securityClient,
sdk._serverURL,
sdk._language,
sdk._sdkVersion,
sdk._genVersion,
)
sdk.Feedback = newFeedback(
sdk._defaultClient,
sdk._securityClient,
sdk._serverURL,
sdk._language,
sdk._sdkVersion,
sdk._genVersion,
)
sdk.FineTunedModel = newFineTunedModel(
sdk._defaultClient,
sdk._securityClient,
sdk._serverURL,
sdk._language,
sdk._sdkVersion,
sdk._genVersion,
)
sdk.Generation = newGeneration(
sdk._defaultClient,
sdk._securityClient,
sdk._serverURL,
sdk._language,
sdk._sdkVersion,
sdk._genVersion,
)
sdk.Metric = newMetric(
sdk._defaultClient,
sdk._securityClient,
sdk._serverURL,
sdk._language,
sdk._sdkVersion,
sdk._genVersion,
)
sdk.Prompt = newPrompt(
sdk._defaultClient,
sdk._securityClient,
sdk._serverURL,
sdk._language,
sdk._sdkVersion,
sdk._genVersion,
)
sdk.Task = newTask(
sdk._defaultClient,
sdk._securityClient,
sdk._serverURL,
sdk._language,
sdk._sdkVersion,
sdk._genVersion,
)
return sdk
}