Skip to content

Commit c7fafed

Browse files
chore: use Pydantic to generate OpenAPI schema
1 parent 09986d1 commit c7fafed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+13807
-14206
lines changed

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 96
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/llamastack%2Fllama-stack-client-602ce64aa309cc15fa09388d99c9f298795686fc37605237cbc03c39d29aabf6.yml
3-
openapi_spec_hash: fc6995247b2555e8660bc9291eb10415
4-
config_hash: e8a35d9d37cb4774b4b0fe1b167dc156
1+
configured_endpoints: 103
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/llamastack%2Fllama-stack-client-2b99a80543f8bc8fa164167693c214651ac8e710f4726fb5869183b4d6c71a03.yml
3+
openapi_spec_hash: a5632057f5e4d956a71c20a79c0d879c
4+
config_hash: 0017f6c419cbbf7b949f9b2842917a79

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,11 @@ import (
5353

5454
func main() {
5555
client := llamastackclient.NewClient()
56-
response, err := client.Models.Register(context.TODO(), llamastackclient.ModelRegisterParams{
57-
ModelID: "model_id",
58-
})
56+
models, err := client.Models.List(context.TODO())
5957
if err != nil {
6058
panic(err.Error())
6159
}
62-
fmt.Printf("%+v\n", response.Identifier)
60+
fmt.Printf("%+v\n", models)
6361
}
6462

6563
```
@@ -302,6 +300,7 @@ _, err := client.Chat.Completions.New(context.TODO(), llamastackclient.ChatCompl
302300
Content: llamastackclient.ChatCompletionNewParamsMessageUserContentUnion{
303301
OfString: llamastackclient.String("string"),
304302
},
303+
Role: "user",
305304
},
306305
}},
307306
Model: "model",
@@ -338,6 +337,7 @@ client.Chat.Completions.New(
338337
Content: llamastackclient.ChatCompletionNewParamsMessageUserContentUnion{
339338
OfString: llamastackclient.String("string"),
340339
},
340+
Role: "user",
341341
},
342342
}},
343343
Model: "model",
@@ -404,6 +404,7 @@ client.Chat.Completions.New(
404404
Content: llamastackclient.ChatCompletionNewParamsMessageUserContentUnion{
405405
OfString: llamastackclient.String("string"),
406406
},
407+
Role: "user",
407408
},
408409
}},
409410
Model: "model",
@@ -428,6 +429,7 @@ completion, err := client.Chat.Completions.New(
428429
Content: llamastackclient.ChatCompletionNewParamsMessageUserContentUnion{
429430
OfString: llamastackclient.String("string"),
430431
},
432+
Role: "user",
431433
},
432434
}},
433435
Model: "model",

alphabenchmark.go

Lines changed: 36 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ package llamastackclient
1010

1111
import (
1212
"context"
13-
"encoding/json"
1413
"errors"
1514
"fmt"
1615
"net/http"
@@ -21,7 +20,6 @@ import (
2120
"github.com/llamastack/llama-stack-client-go/option"
2221
"github.com/llamastack/llama-stack-client-go/packages/param"
2322
"github.com/llamastack/llama-stack-client-go/packages/respjson"
24-
"github.com/llamastack/llama-stack-client-go/shared/constant"
2523
)
2624

2725
// AlphaBenchmarkService contains methods and other services that help with
@@ -79,28 +77,44 @@ func (r *AlphaBenchmarkService) Register(ctx context.Context, body AlphaBenchmar
7977
return
8078
}
8179

80+
// Unregister a benchmark.
81+
//
82+
// Deprecated: deprecated
83+
func (r *AlphaBenchmarkService) Unregister(ctx context.Context, benchmarkID string, opts ...option.RequestOption) (err error) {
84+
opts = slices.Concat(r.Options, opts)
85+
opts = append([]option.RequestOption{option.WithHeader("Accept", "")}, opts...)
86+
if benchmarkID == "" {
87+
err = errors.New("missing required benchmark_id parameter")
88+
return
89+
}
90+
path := fmt.Sprintf("v1alpha/eval/benchmarks/%s", benchmarkID)
91+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, nil, opts...)
92+
return
93+
}
94+
8295
// A benchmark resource for evaluating model performance.
8396
type Benchmark struct {
84-
// Identifier of the dataset to use for the benchmark evaluation
85-
DatasetID string `json:"dataset_id,required"`
97+
DatasetID string `json:"dataset_id,required"`
98+
// Unique identifier for this resource in llama stack
8699
Identifier string `json:"identifier,required"`
87-
// Metadata for this evaluation task
88-
Metadata map[string]BenchmarkMetadataUnion `json:"metadata,required"`
89-
ProviderID string `json:"provider_id,required"`
90-
// List of scoring function identifiers to apply during evaluation
100+
// ID of the provider that owns this resource
101+
ProviderID string `json:"provider_id,required"`
91102
ScoringFunctions []string `json:"scoring_functions,required"`
92-
// The resource type, always benchmark
93-
Type constant.Benchmark `json:"type,required"`
94-
ProviderResourceID string `json:"provider_resource_id"`
103+
// Metadata for this evaluation task
104+
Metadata map[string]any `json:"metadata"`
105+
// Unique identifier for this resource in the provider
106+
ProviderResourceID string `json:"provider_resource_id,nullable"`
107+
// Any of "benchmark".
108+
Type BenchmarkType `json:"type"`
95109
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
96110
JSON struct {
97111
DatasetID respjson.Field
98112
Identifier respjson.Field
99-
Metadata respjson.Field
100113
ProviderID respjson.Field
101114
ScoringFunctions respjson.Field
102-
Type respjson.Field
115+
Metadata respjson.Field
103116
ProviderResourceID respjson.Field
117+
Type respjson.Field
104118
ExtraFields map[string]respjson.Field
105119
raw string
106120
} `json:"-"`
@@ -112,57 +126,11 @@ func (r *Benchmark) UnmarshalJSON(data []byte) error {
112126
return apijson.UnmarshalRoot(data, r)
113127
}
114128

115-
// BenchmarkMetadataUnion contains all possible properties and values from [bool],
116-
// [float64], [string], [[]any].
117-
//
118-
// Use the methods beginning with 'As' to cast the union to one of its variants.
119-
//
120-
// If the underlying value is not a json object, one of the following properties
121-
// will be valid: OfBool OfFloat OfString OfAnyArray]
122-
type BenchmarkMetadataUnion struct {
123-
// This field will be present if the value is a [bool] instead of an object.
124-
OfBool bool `json:",inline"`
125-
// This field will be present if the value is a [float64] instead of an object.
126-
OfFloat float64 `json:",inline"`
127-
// This field will be present if the value is a [string] instead of an object.
128-
OfString string `json:",inline"`
129-
// This field will be present if the value is a [[]any] instead of an object.
130-
OfAnyArray []any `json:",inline"`
131-
JSON struct {
132-
OfBool respjson.Field
133-
OfFloat respjson.Field
134-
OfString respjson.Field
135-
OfAnyArray respjson.Field
136-
raw string
137-
} `json:"-"`
138-
}
139-
140-
func (u BenchmarkMetadataUnion) AsBool() (v bool) {
141-
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
142-
return
143-
}
144-
145-
func (u BenchmarkMetadataUnion) AsFloat() (v float64) {
146-
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
147-
return
148-
}
149-
150-
func (u BenchmarkMetadataUnion) AsString() (v string) {
151-
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
152-
return
153-
}
129+
type BenchmarkType string
154130

155-
func (u BenchmarkMetadataUnion) AsAnyArray() (v []any) {
156-
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
157-
return
158-
}
159-
160-
// Returns the unmodified JSON received from the API
161-
func (u BenchmarkMetadataUnion) RawJSON() string { return u.JSON.raw }
162-
163-
func (r *BenchmarkMetadataUnion) UnmarshalJSON(data []byte) error {
164-
return apijson.UnmarshalRoot(data, r)
165-
}
131+
const (
132+
BenchmarkTypeBenchmark BenchmarkType = "benchmark"
133+
)
166134

167135
type ListBenchmarksResponse struct {
168136
Data []Benchmark `json:"data,required"`
@@ -181,18 +149,12 @@ func (r *ListBenchmarksResponse) UnmarshalJSON(data []byte) error {
181149
}
182150

183151
type AlphaBenchmarkRegisterParams struct {
184-
// The ID of the benchmark to register.
185-
BenchmarkID string `json:"benchmark_id,required"`
186-
// The ID of the dataset to use for the benchmark.
187-
DatasetID string `json:"dataset_id,required"`
188-
// The scoring functions to use for the benchmark.
189-
ScoringFunctions []string `json:"scoring_functions,omitzero,required"`
190-
// The ID of the provider benchmark to use for the benchmark.
152+
BenchmarkID string `json:"benchmark_id,required"`
153+
DatasetID string `json:"dataset_id,required"`
154+
ScoringFunctions []string `json:"scoring_functions,omitzero,required"`
191155
ProviderBenchmarkID param.Opt[string] `json:"provider_benchmark_id,omitzero"`
192-
// The ID of the provider to use for the benchmark.
193-
ProviderID param.Opt[string] `json:"provider_id,omitzero"`
194-
// The metadata to use for the benchmark.
195-
Metadata map[string]AlphaBenchmarkRegisterParamsMetadataUnion `json:"metadata,omitzero"`
156+
ProviderID param.Opt[string] `json:"provider_id,omitzero"`
157+
Metadata map[string]any `json:"metadata,omitzero"`
196158
paramObj
197159
}
198160

@@ -203,34 +165,3 @@ func (r AlphaBenchmarkRegisterParams) MarshalJSON() (data []byte, err error) {
203165
func (r *AlphaBenchmarkRegisterParams) UnmarshalJSON(data []byte) error {
204166
return apijson.UnmarshalRoot(data, r)
205167
}
206-
207-
// Only one field can be non-zero.
208-
//
209-
// Use [param.IsOmitted] to confirm if a field is set.
210-
type AlphaBenchmarkRegisterParamsMetadataUnion struct {
211-
OfBool param.Opt[bool] `json:",omitzero,inline"`
212-
OfFloat param.Opt[float64] `json:",omitzero,inline"`
213-
OfString param.Opt[string] `json:",omitzero,inline"`
214-
OfAnyArray []any `json:",omitzero,inline"`
215-
paramUnion
216-
}
217-
218-
func (u AlphaBenchmarkRegisterParamsMetadataUnion) MarshalJSON() ([]byte, error) {
219-
return param.MarshalUnion(u, u.OfBool, u.OfFloat, u.OfString, u.OfAnyArray)
220-
}
221-
func (u *AlphaBenchmarkRegisterParamsMetadataUnion) UnmarshalJSON(data []byte) error {
222-
return apijson.UnmarshalRoot(data, u)
223-
}
224-
225-
func (u *AlphaBenchmarkRegisterParamsMetadataUnion) asAny() any {
226-
if !param.IsOmitted(u.OfBool) {
227-
return &u.OfBool.Value
228-
} else if !param.IsOmitted(u.OfFloat) {
229-
return &u.OfFloat.Value
230-
} else if !param.IsOmitted(u.OfString) {
231-
return &u.OfString.Value
232-
} else if !param.IsOmitted(u.OfAnyArray) {
233-
return &u.OfAnyArray
234-
}
235-
return nil
236-
}

alphabenchmark_test.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,8 @@ func TestAlphaBenchmarkRegisterWithOptionalParams(t *testing.T) {
7676
BenchmarkID: "benchmark_id",
7777
DatasetID: "dataset_id",
7878
ScoringFunctions: []string{"string"},
79-
Metadata: map[string]llamastackclient.AlphaBenchmarkRegisterParamsMetadataUnion{
80-
"foo": {
81-
OfBool: llamastackclient.Bool(true),
82-
},
79+
Metadata: map[string]any{
80+
"foo": "bar",
8381
},
8482
ProviderBenchmarkID: llamastackclient.String("provider_benchmark_id"),
8583
ProviderID: llamastackclient.String("provider_id"),
@@ -92,3 +90,24 @@ func TestAlphaBenchmarkRegisterWithOptionalParams(t *testing.T) {
9290
t.Fatalf("err should be nil: %s", err.Error())
9391
}
9492
}
93+
94+
func TestAlphaBenchmarkUnregister(t *testing.T) {
95+
baseURL := "http://localhost:4010"
96+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
97+
baseURL = envURL
98+
}
99+
if !testutil.CheckTestServer(t, baseURL) {
100+
return
101+
}
102+
client := llamastackclient.NewClient(
103+
option.WithBaseURL(baseURL),
104+
)
105+
err := client.Alpha.Benchmarks.Unregister(context.TODO(), "benchmark_id")
106+
if err != nil {
107+
var apierr *llamastackclient.Error
108+
if errors.As(err, &apierr) {
109+
t.Log(string(apierr.DumpRequest(true)))
110+
}
111+
t.Fatalf("err should be nil: %s", err.Error())
112+
}
113+
}

0 commit comments

Comments
 (0)