3
3
package llamastackclient
4
4
5
5
import (
6
- "context"
7
- "encoding/json"
8
- "errors"
9
- "fmt"
10
- "net/http"
11
- "slices"
12
-
13
- "github.com/llamastack/llama-stack-client-go/internal/apijson"
14
- "github.com/llamastack/llama-stack-client-go/internal/requestconfig"
15
6
"github.com/llamastack/llama-stack-client-go/option"
16
- "github.com/llamastack/llama-stack-client-go/packages/param"
17
- "github.com/llamastack/llama-stack-client-go/packages/respjson"
18
- "github.com/llamastack/llama-stack-client-go/shared/constant"
19
7
)
20
8
21
9
// BenchmarkService contains methods and other services that help with interacting
@@ -36,193 +24,3 @@ func NewBenchmarkService(opts ...option.RequestOption) (r BenchmarkService) {
36
24
r .Options = opts
37
25
return
38
26
}
39
-
40
- // Get a benchmark by its ID.
41
- func (r * BenchmarkService ) Get (ctx context.Context , benchmarkID string , opts ... option.RequestOption ) (res * Benchmark , err error ) {
42
- opts = slices .Concat (r .Options , opts )
43
- if benchmarkID == "" {
44
- err = errors .New ("missing required benchmark_id parameter" )
45
- return
46
- }
47
- path := fmt .Sprintf ("v1/eval/benchmarks/%s" , benchmarkID )
48
- err = requestconfig .ExecuteNewRequest (ctx , http .MethodGet , path , nil , & res , opts ... )
49
- return
50
- }
51
-
52
- // List all benchmarks.
53
- func (r * BenchmarkService ) List (ctx context.Context , opts ... option.RequestOption ) (res * []Benchmark , err error ) {
54
- var env ListBenchmarksResponse
55
- opts = slices .Concat (r .Options , opts )
56
- path := "v1/eval/benchmarks"
57
- err = requestconfig .ExecuteNewRequest (ctx , http .MethodGet , path , nil , & env , opts ... )
58
- if err != nil {
59
- return
60
- }
61
- res = & env .Data
62
- return
63
- }
64
-
65
- // Register a benchmark.
66
- func (r * BenchmarkService ) Register (ctx context.Context , body BenchmarkRegisterParams , opts ... option.RequestOption ) (err error ) {
67
- opts = slices .Concat (r .Options , opts )
68
- opts = append ([]option.RequestOption {option .WithHeader ("Accept" , "" )}, opts ... )
69
- path := "v1/eval/benchmarks"
70
- err = requestconfig .ExecuteNewRequest (ctx , http .MethodPost , path , body , nil , opts ... )
71
- return
72
- }
73
-
74
- // A benchmark resource for evaluating model performance.
75
- type Benchmark struct {
76
- // Identifier of the dataset to use for the benchmark evaluation
77
- DatasetID string `json:"dataset_id,required"`
78
- Identifier string `json:"identifier,required"`
79
- // Metadata for this evaluation task
80
- Metadata map [string ]BenchmarkMetadataUnion `json:"metadata,required"`
81
- ProviderID string `json:"provider_id,required"`
82
- // List of scoring function identifiers to apply during evaluation
83
- ScoringFunctions []string `json:"scoring_functions,required"`
84
- // The resource type, always benchmark
85
- Type constant.Benchmark `json:"type,required"`
86
- ProviderResourceID string `json:"provider_resource_id"`
87
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
88
- JSON struct {
89
- DatasetID respjson.Field
90
- Identifier respjson.Field
91
- Metadata respjson.Field
92
- ProviderID respjson.Field
93
- ScoringFunctions respjson.Field
94
- Type respjson.Field
95
- ProviderResourceID respjson.Field
96
- ExtraFields map [string ]respjson.Field
97
- raw string
98
- } `json:"-"`
99
- }
100
-
101
- // Returns the unmodified JSON received from the API
102
- func (r Benchmark ) RawJSON () string { return r .JSON .raw }
103
- func (r * Benchmark ) UnmarshalJSON (data []byte ) error {
104
- return apijson .UnmarshalRoot (data , r )
105
- }
106
-
107
- // BenchmarkMetadataUnion contains all possible properties and values from [bool],
108
- // [float64], [string], [[]any].
109
- //
110
- // Use the methods beginning with 'As' to cast the union to one of its variants.
111
- //
112
- // If the underlying value is not a json object, one of the following properties
113
- // will be valid: OfBool OfFloat OfString OfAnyArray]
114
- type BenchmarkMetadataUnion struct {
115
- // This field will be present if the value is a [bool] instead of an object.
116
- OfBool bool `json:",inline"`
117
- // This field will be present if the value is a [float64] instead of an object.
118
- OfFloat float64 `json:",inline"`
119
- // This field will be present if the value is a [string] instead of an object.
120
- OfString string `json:",inline"`
121
- // This field will be present if the value is a [[]any] instead of an object.
122
- OfAnyArray []any `json:",inline"`
123
- JSON struct {
124
- OfBool respjson.Field
125
- OfFloat respjson.Field
126
- OfString respjson.Field
127
- OfAnyArray respjson.Field
128
- raw string
129
- } `json:"-"`
130
- }
131
-
132
- func (u BenchmarkMetadataUnion ) AsBool () (v bool ) {
133
- apijson .UnmarshalRoot (json .RawMessage (u .JSON .raw ), & v )
134
- return
135
- }
136
-
137
- func (u BenchmarkMetadataUnion ) AsFloat () (v float64 ) {
138
- apijson .UnmarshalRoot (json .RawMessage (u .JSON .raw ), & v )
139
- return
140
- }
141
-
142
- func (u BenchmarkMetadataUnion ) AsString () (v string ) {
143
- apijson .UnmarshalRoot (json .RawMessage (u .JSON .raw ), & v )
144
- return
145
- }
146
-
147
- func (u BenchmarkMetadataUnion ) AsAnyArray () (v []any ) {
148
- apijson .UnmarshalRoot (json .RawMessage (u .JSON .raw ), & v )
149
- return
150
- }
151
-
152
- // Returns the unmodified JSON received from the API
153
- func (u BenchmarkMetadataUnion ) RawJSON () string { return u .JSON .raw }
154
-
155
- func (r * BenchmarkMetadataUnion ) UnmarshalJSON (data []byte ) error {
156
- return apijson .UnmarshalRoot (data , r )
157
- }
158
-
159
- type ListBenchmarksResponse struct {
160
- Data []Benchmark `json:"data,required"`
161
- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
162
- JSON struct {
163
- Data respjson.Field
164
- ExtraFields map [string ]respjson.Field
165
- raw string
166
- } `json:"-"`
167
- }
168
-
169
- // Returns the unmodified JSON received from the API
170
- func (r ListBenchmarksResponse ) RawJSON () string { return r .JSON .raw }
171
- func (r * ListBenchmarksResponse ) UnmarshalJSON (data []byte ) error {
172
- return apijson .UnmarshalRoot (data , r )
173
- }
174
-
175
- type BenchmarkRegisterParams struct {
176
- // The ID of the benchmark to register.
177
- BenchmarkID string `json:"benchmark_id,required"`
178
- // The ID of the dataset to use for the benchmark.
179
- DatasetID string `json:"dataset_id,required"`
180
- // The scoring functions to use for the benchmark.
181
- ScoringFunctions []string `json:"scoring_functions,omitzero,required"`
182
- // The ID of the provider benchmark to use for the benchmark.
183
- ProviderBenchmarkID param.Opt [string ] `json:"provider_benchmark_id,omitzero"`
184
- // The ID of the provider to use for the benchmark.
185
- ProviderID param.Opt [string ] `json:"provider_id,omitzero"`
186
- // The metadata to use for the benchmark.
187
- Metadata map [string ]BenchmarkRegisterParamsMetadataUnion `json:"metadata,omitzero"`
188
- paramObj
189
- }
190
-
191
- func (r BenchmarkRegisterParams ) MarshalJSON () (data []byte , err error ) {
192
- type shadow BenchmarkRegisterParams
193
- return param .MarshalObject (r , (* shadow )(& r ))
194
- }
195
- func (r * BenchmarkRegisterParams ) UnmarshalJSON (data []byte ) error {
196
- return apijson .UnmarshalRoot (data , r )
197
- }
198
-
199
- // Only one field can be non-zero.
200
- //
201
- // Use [param.IsOmitted] to confirm if a field is set.
202
- type BenchmarkRegisterParamsMetadataUnion struct {
203
- OfBool param.Opt [bool ] `json:",omitzero,inline"`
204
- OfFloat param.Opt [float64 ] `json:",omitzero,inline"`
205
- OfString param.Opt [string ] `json:",omitzero,inline"`
206
- OfAnyArray []any `json:",omitzero,inline"`
207
- paramUnion
208
- }
209
-
210
- func (u BenchmarkRegisterParamsMetadataUnion ) MarshalJSON () ([]byte , error ) {
211
- return param .MarshalUnion (u , u .OfBool , u .OfFloat , u .OfString , u .OfAnyArray )
212
- }
213
- func (u * BenchmarkRegisterParamsMetadataUnion ) UnmarshalJSON (data []byte ) error {
214
- return apijson .UnmarshalRoot (data , u )
215
- }
216
-
217
- func (u * BenchmarkRegisterParamsMetadataUnion ) asAny () any {
218
- if ! param .IsOmitted (u .OfBool ) {
219
- return & u .OfBool .Value
220
- } else if ! param .IsOmitted (u .OfFloat ) {
221
- return & u .OfFloat .Value
222
- } else if ! param .IsOmitted (u .OfString ) {
223
- return & u .OfString .Value
224
- } else if ! param .IsOmitted (u .OfAnyArray ) {
225
- return & u .OfAnyArray
226
- }
227
- return nil
228
- }
0 commit comments