From 1f11530f349a540e9ab8f50ec8e34ed3f2acc6a6 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 7 Apr 2025 21:36:55 +0000 Subject: [PATCH 1/9] feat(client): add escape hatch to omit required param fields (#354) --- packages/param/encoder.go | 9 ++++++++- packages/param/encoder_test.go | 18 ++++++++++++++++++ packages/param/param.go | 11 +++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/packages/param/encoder.go b/packages/param/encoder.go index 97bf07db..f88a64e4 100644 --- a/packages/param/encoder.go +++ b/packages/param/encoder.go @@ -33,7 +33,14 @@ func MarshalObject[T OverridableObject](f T, underlying any) ([]byte, error) { return nil, err } for k, v := range extras { - bytes, err = sjson.SetBytes(bytes, k, v) + if v == Omit { + // Errors handling ForceOmitted are ignored. + if b, e := sjson.DeleteBytes(bytes, k); e == nil { + bytes = b + } + } else { + bytes, err = sjson.SetBytes(bytes, k, v) + } if err != nil { return nil, err } diff --git a/packages/param/encoder_test.go b/packages/param/encoder_test.go index 3dce9ceb..8ba62c15 100644 --- a/packages/param/encoder_test.go +++ b/packages/param/encoder_test.go @@ -117,6 +117,24 @@ func TestExtraFields(t *testing.T) { } } +func TestExtraFieldsForceOmitted(t *testing.T) { + v := Struct{ + // Testing with the zero value. + // A: "", + // B: 0, + } + v.WithExtraFields(map[string]any{ + "b": param.Omit, + }) + bytes, err := json.Marshal(v) + if err != nil { + t.Fatalf("failed to marshal: %v", err) + } + if string(bytes) != `{"a":""}` { + t.Fatalf("failed to marshal: got %v", string(bytes)) + } +} + type UnionWithDates struct { OfDate param.Opt[time.Time] OfTime param.Opt[time.Time] diff --git a/packages/param/param.go b/packages/param/param.go index cafcafac..cfbcd81a 100644 --- a/packages/param/param.go +++ b/packages/param/param.go @@ -62,6 +62,13 @@ type APIObject struct{ metadata } // APIUnion should be embedded in all api unions fields, preferably using an alias to make private type APIUnion struct{ metadata } +type forceOmit int + +// Omit can be used with [metadata.WithExtraFields] to ensure that a +// required field is omitted. This is useful as an escape hatch for +// when a required is unwanted for some unexpected reason. +const Omit forceOmit = -1 + type metadata struct{ any } type metadataNull struct{} type metadataExtraFields map[string]any @@ -98,6 +105,10 @@ func (m metadata) GetExtraFields() map[string]any { // // WithExtraFields will override any existing fields with the same key. // For security reasons, ensure this is only used with trusted input data. +// +// To intentionally omit a required field, use [Omit]. +// +// foo.WithExtraFields(map[string]any{"bar": Omit}) func (m *metadata) WithExtraFields(extraFields map[string]any) { m.any = metadataExtraFields(extraFields) } From 54ad943e70b9d73103141c319631c91a90333b1c Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 7 Apr 2025 21:47:42 +0000 Subject: [PATCH 2/9] chore(docs): readme improvements (#356) --- README.md | 93 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 5224ac29..f659b569 100644 --- a/README.md +++ b/README.md @@ -314,16 +314,16 @@ send non-conforming fields in the request body. Extra fields overwrite any struc key, so only use with trusted data. ```go -params := FooParams{ - ID: "id_xxx", // required property - Name: openai.String("hello"), // optional property - Description: param.NullOpt[string](), // explicit null property +params := openai.ExampleParams{ + ID: "id_xxx", // required property + Name: openai.String("..."), // optional property + Description: param.NullOpt[string](), // explicit null property Point: openai.Point{ - X: 0, // required field will serialize as 0 + X: 0, // required field will serialize as 0 Y: openai.Int(1), // optional field will serialize as 1 - // ... omitted non-required fields will not be serialized - }), + // ... omitted non-required fields will not be serialized + }, Origin: openai.Origin{}, // the zero value of [Origin] is considered omitted } @@ -352,8 +352,8 @@ These methods return a mutable pointer to the underlying data, if present. ```go // Only one field can be non-zero, use param.IsOmitted() to check if a field is set type AnimalUnionParam struct { - OfCat *Cat `json:",omitzero,inline` - OfDog *Dog `json:",omitzero,inline` + OfCat *Cat `json:",omitzero,inline` + OfDog *Dog `json:",omitzero,inline` } animal := AnimalUnionParam{ @@ -376,31 +376,41 @@ if address := animal.GetOwner().GetAddress(); address != nil { All fields in response structs are value types (not pointers or wrappers). If a given field is `null`, not present, or invalid, the corresponding field -will simply be its zero value. +will simply be its zero value. To handle optional fields, see the `IsPresent()` method +below. All response structs also include a special `JSON` field, containing more detailed information about each property, which you can use like so: ```go -if res.Name == "" { - // true if `"name"` was unmarshalled successfully - res.JSON.Name.IsPresent() - - res.JSON.Name.IsExplicitNull() // true if `"name"` is explicitly null - res.JSON.Name.Raw() == "" // true if `"name"` field does not exist - - // When the API returns data that cannot be coerced to the expected type: - if !res.JSON.Name.IsPresent() && res.JSON.Name.Raw() != "" { - raw := res.JSON.Name.Raw() - - legacyName := struct{ - First string `json:"first"` - Last string `json:"last"` - }{} - json.Unmarshal([]byte(raw), &legacyName) - name = legacyName.First + " " + legacyName.Last - } -} +type Animal struct { + Name string `json:"name,nullable"` + Owners int `json:"owners"` + Age int `json:"age"` + JSON struct { + Name resp.Field + Owner resp.Field + Age resp.Field + } `json:"-"` +} + +var res Animal +json.Unmarshal([]byte(`{"name": null, "owners": 0}`), &res) + +// Use the IsPresent() method to handle optional fields +res.Owners // 0 +res.JSON.Owners.IsPresent() // true +res.JSON.Owners.Raw() // "0" + +res.Age // 0 +res.JSON.Age.IsPresent() // false +res.JSON.Age.Raw() // "" + +// Use the IsExplicitNull() method to differentiate null and omitted +res.Name // "" +res.JSON.Name.IsPresent() // false +res.JSON.Name.Raw() // "null" +res.JSON.Name.IsExplicitNull() // true ``` These `.JSON` structs also include an `ExtraFields` map containing @@ -423,31 +433,26 @@ the properties but prefixed with `Of` and feature the tag `json:"...,inline"`. ```go type AnimalUnion struct { - OfString string `json:",inline"` - Name string `json:"name"` - Owner Person `json:"owner"` + // From variants [Dog], [Cat] + Owner Person `json:"owner"` + // From variant [Dog] + DogBreed string `json:"dog_breed"` + // From variant [Cat] + CatBreed string `json:"cat_breed"` // ... JSON struct { - OfString resp.Field - Name resp.Field - Owner resp.Field + Owner resp.Field // ... - } + } `json:"-"` } // If animal variant -if animal.Owner.Address.JSON.ZipCode == "" { +if animal.Owner.Address.ZipCode == "" { panic("missing zip code") } -// If string variant -if !animal.OfString == "" { - panic("expected a name") -} - // Switch on the variant -switch variant := animalOrName.AsAny().(type) { -case string: +switch variant := animal.AsAny().(type) { case Dog: case Cat: default: From 4d4168700eb25470c8ca6aea7cc9aed6abce1750 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 7 Apr 2025 22:00:21 +0000 Subject: [PATCH 3/9] feat(client): support custom http clients (#357) --- internal/requestconfig/requestconfig.go | 10 +++++++++ option/requestoption.go | 29 ++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/internal/requestconfig/requestconfig.go b/internal/requestconfig/requestconfig.go index 96b6024d..8d5f77ec 100644 --- a/internal/requestconfig/requestconfig.go +++ b/internal/requestconfig/requestconfig.go @@ -189,6 +189,12 @@ func NewRequestConfig(ctx context.Context, method string, u string, body interfa return &cfg, nil } +// This interface is primarily used to describe an [*http.Client], but also +// supports custom HTTP implementations. +type HTTPDoer interface { + Do(req *http.Request) (*http.Response, error) +} + // RequestConfig represents all the state related to one request. // // Editing the variables inside RequestConfig directly is unstable api. Prefer @@ -199,6 +205,7 @@ type RequestConfig struct { Context context.Context Request *http.Request BaseURL *url.URL + CustomHTTPDoer HTTPDoer HTTPClient *http.Client Middlewares []middleware APIKey string @@ -398,6 +405,9 @@ func (cfg *RequestConfig) Execute() (err error) { } handler := cfg.HTTPClient.Do + if cfg.CustomHTTPDoer != nil { + handler = cfg.CustomHTTPDoer.Do + } for i := len(cfg.Middlewares) - 1; i >= 0; i -= 1 { handler = applyMiddleware(cfg.Middlewares[i], handler) } diff --git a/option/requestoption.go b/option/requestoption.go index 1dcf7620..778e350c 100644 --- a/option/requestoption.go +++ b/option/requestoption.go @@ -40,11 +40,34 @@ func WithBaseURL(base string) RequestOption { }) } -// WithHTTPClient returns a RequestOption that changes the underlying [http.Client] used to make this +// HTTPClient is primarily used to describe an [*http.Client], but also +// supports custom implementations. +// +// For bespoke implementations, prefer using an [*http.Client] with a +// custom transport. See [http.RoundTripper] for further information. +type HTTPClient interface { + Do(*http.Request) (*http.Response, error) +} + +// WithHTTPClient returns a RequestOption that changes the underlying http client used to make this // request, which by default is [http.DefaultClient]. -func WithHTTPClient(client *http.Client) RequestOption { +// +// For custom uses cases, it is recommended to provide an [*http.Client] with a custom +// [http.RoundTripper] as its transport, rather than directly implementing [HTTPClient]. +func WithHTTPClient(client HTTPClient) RequestOption { return requestconfig.RequestOptionFunc(func(r *requestconfig.RequestConfig) error { - r.HTTPClient = client + if client == nil { + return fmt.Errorf("requestoption: custom http client cannot be nil") + } + + if c, ok := client.(*http.Client); ok { + // Prefer the native client if possible. + r.HTTPClient = c + r.CustomHTTPDoer = nil + } else { + r.CustomHTTPDoer = client + } + return nil }) } From b8b67a2eab48eba1a01f127973389152d57a43e2 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 8 Apr 2025 14:25:34 +0000 Subject: [PATCH 4/9] chore(tests): improve enum examples (#359) --- image_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/image_test.go b/image_test.go index e8f2b627..fd9b99a3 100644 --- a/image_test.go +++ b/image_test.go @@ -32,7 +32,7 @@ func TestImageNewVariationWithOptionalParams(t *testing.T) { Model: openai.ImageModelDallE2, N: openai.Int(1), ResponseFormat: openai.ImageNewVariationParamsResponseFormatURL, - Size: openai.ImageNewVariationParamsSize256x256, + Size: openai.ImageNewVariationParamsSize1024x1024, User: openai.String("user-1234"), }) if err != nil { @@ -63,7 +63,7 @@ func TestImageEditWithOptionalParams(t *testing.T) { Model: openai.ImageModelDallE2, N: openai.Int(1), ResponseFormat: openai.ImageEditParamsResponseFormatURL, - Size: openai.ImageEditParamsSize256x256, + Size: openai.ImageEditParamsSize1024x1024, User: openai.String("user-1234"), }) if err != nil { @@ -93,7 +93,7 @@ func TestImageGenerateWithOptionalParams(t *testing.T) { N: openai.Int(1), Quality: openai.ImageGenerateParamsQualityStandard, ResponseFormat: openai.ImageGenerateParamsResponseFormatURL, - Size: openai.ImageGenerateParamsSize256x256, + Size: openai.ImageGenerateParamsSize1024x1024, Style: openai.ImageGenerateParamsStyleVivid, User: openai.String("user-1234"), }) From 4a496a7674de63d9fb838a5095a2958a7cbaa1f7 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 8 Apr 2025 18:49:37 +0000 Subject: [PATCH 5/9] feat(api): Add evalapi to sdk (#360) Adding the evalsapi to the sdk. --- .stats.yml | 8 +- api.md | 82 + client.go | 2 + eval.go | 2338 +++++++++++++++++ eval_test.go | 306 +++ evalrun.go | 3169 ++++++++++++++++++++++++ evalrun_test.go | 171 ++ evalrunoutputitem.go | 465 ++++ evalrunoutputitem_test.go | 73 + finetuning.go | 6 +- finetuningcheckpoint.go | 28 + finetuningcheckpointpermission.go | 263 ++ finetuningcheckpointpermission_test.go | 95 + responses/response.go | 2 +- shared/constant/constants.go | 39 + 15 files changed, 7040 insertions(+), 7 deletions(-) create mode 100644 eval.go create mode 100644 eval_test.go create mode 100644 evalrun.go create mode 100644 evalrun_test.go create mode 100644 evalrunoutputitem.go create mode 100644 evalrunoutputitem_test.go create mode 100644 finetuningcheckpoint.go create mode 100644 finetuningcheckpointpermission.go create mode 100644 finetuningcheckpointpermission_test.go diff --git a/.stats.yml b/.stats.yml index e0e1a71e..43112911 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 80 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-4bce8217a697c729ac98046d4caf2c9e826b54c427fb0ab4f98e549a2e0ce31c.yml -openapi_spec_hash: 7996d2c34cc44fe2ce9ffe93c0ab774e -config_hash: bcd2cacdcb9fae9938f273cd167f613c +configured_endpoints: 95 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-472fe3036ea745365257fe870c0330917fb3153705c2826f49873cd631319b0a.yml +openapi_spec_hash: ea86343b5e9858a74e85da8ab2c532f6 +config_hash: ef19d36c307306f14f2e1cd5c834a151 diff --git a/api.md b/api.md index 760fd340..f0d0eeb8 100644 --- a/api.md +++ b/api.md @@ -248,6 +248,22 @@ Methods: - client.FineTuning.Jobs.Checkpoints.List(ctx context.Context, fineTuningJobID string, query openai.FineTuningJobCheckpointListParams) (pagination.CursorPage[openai.FineTuningJobCheckpoint], error) +## Checkpoints + +### Permissions + +Response Types: + +- openai.FineTuningCheckpointPermissionNewResponse +- openai.FineTuningCheckpointPermissionGetResponse +- openai.FineTuningCheckpointPermissionDeleteResponse + +Methods: + +- client.FineTuning.Checkpoints.Permissions.New(ctx context.Context, fineTunedModelCheckpoint string, body openai.FineTuningCheckpointPermissionNewParams) (pagination.Page[openai.FineTuningCheckpointPermissionNewResponse], error) +- client.FineTuning.Checkpoints.Permissions.Get(ctx context.Context, fineTunedModelCheckpoint string, query openai.FineTuningCheckpointPermissionGetParams) (openai.FineTuningCheckpointPermissionGetResponse, error) +- client.FineTuning.Checkpoints.Permissions.Delete(ctx context.Context, fineTunedModelCheckpoint string) (openai.FineTuningCheckpointPermissionDeleteResponse, error) + # VectorStores Params Types: @@ -615,3 +631,69 @@ Response Types: Methods: - client.Responses.InputItems.List(ctx context.Context, responseID string, query responses.InputItemListParams) (pagination.CursorPage[responses.ResponseItemUnion], error) + +# Evals + +Params Types: + +- openai.EvalStringCheckGraderParam +- openai.EvalTextSimilarityGraderParam + +Response Types: + +- openai.EvalCustomDataSourceConfig +- openai.EvalLabelModelGrader +- openai.EvalStoredCompletionsDataSourceConfig +- openai.EvalStringCheckGrader +- openai.EvalTextSimilarityGrader +- openai.EvalNewResponse +- openai.EvalGetResponse +- openai.EvalUpdateResponse +- openai.EvalListResponse +- openai.EvalDeleteResponse + +Methods: + +- client.Evals.New(ctx context.Context, body openai.EvalNewParams) (openai.EvalNewResponse, error) +- client.Evals.Get(ctx context.Context, evalID string) (openai.EvalGetResponse, error) +- client.Evals.Update(ctx context.Context, evalID string, body openai.EvalUpdateParams) (openai.EvalUpdateResponse, error) +- client.Evals.List(ctx context.Context, query openai.EvalListParams) (pagination.CursorPage[openai.EvalListResponse], error) +- client.Evals.Delete(ctx context.Context, evalID string) (openai.EvalDeleteResponse, error) + +## Runs + +Params Types: + +- openai.CreateEvalCompletionsRunDataSourceParam +- openai.CreateEvalJSONLRunDataSourceParam + +Response Types: + +- openai.CreateEvalCompletionsRunDataSource +- openai.CreateEvalJSONLRunDataSource +- openai.EvalAPIError +- openai.EvalRunNewResponse +- openai.EvalRunGetResponse +- openai.EvalRunListResponse +- openai.EvalRunDeleteResponse +- openai.EvalRunCancelResponse + +Methods: + +- client.Evals.Runs.New(ctx context.Context, evalID string, body openai.EvalRunNewParams) (openai.EvalRunNewResponse, error) +- client.Evals.Runs.Get(ctx context.Context, evalID string, runID string) (openai.EvalRunGetResponse, error) +- client.Evals.Runs.List(ctx context.Context, evalID string, query openai.EvalRunListParams) (pagination.CursorPage[openai.EvalRunListResponse], error) +- client.Evals.Runs.Delete(ctx context.Context, evalID string, runID string) (openai.EvalRunDeleteResponse, error) +- client.Evals.Runs.Cancel(ctx context.Context, evalID string, runID string) (openai.EvalRunCancelResponse, error) + +### OutputItems + +Response Types: + +- openai.EvalRunOutputItemGetResponse +- openai.EvalRunOutputItemListResponse + +Methods: + +- client.Evals.Runs.OutputItems.Get(ctx context.Context, evalID string, runID string, outputItemID string) (openai.EvalRunOutputItemGetResponse, error) +- client.Evals.Runs.OutputItems.List(ctx context.Context, evalID string, runID string, query openai.EvalRunOutputItemListParams) (pagination.CursorPage[openai.EvalRunOutputItemListResponse], error) diff --git a/client.go b/client.go index e99313f7..0ef8533e 100644 --- a/client.go +++ b/client.go @@ -31,6 +31,7 @@ type Client struct { Batches BatchService Uploads UploadService Responses responses.ResponseService + Evals EvalService } // DefaultClientOptions read from the environment (OPENAI_API_KEY, OPENAI_ORG_ID, @@ -72,6 +73,7 @@ func NewClient(opts ...option.RequestOption) (r Client) { r.Batches = NewBatchService(opts...) r.Uploads = NewUploadService(opts...) r.Responses = responses.NewResponseService(opts...) + r.Evals = NewEvalService(opts...) return } diff --git a/eval.go b/eval.go new file mode 100644 index 00000000..e9d1399f --- /dev/null +++ b/eval.go @@ -0,0 +1,2338 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package openai + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "net/http" + "net/url" + "reflect" + + "github.com/openai/openai-go/internal/apijson" + "github.com/openai/openai-go/internal/apiquery" + "github.com/openai/openai-go/internal/requestconfig" + "github.com/openai/openai-go/option" + "github.com/openai/openai-go/packages/pagination" + "github.com/openai/openai-go/packages/param" + "github.com/openai/openai-go/packages/resp" + "github.com/openai/openai-go/shared" + "github.com/openai/openai-go/shared/constant" + "github.com/tidwall/gjson" +) + +// EvalService contains methods and other services that help with interacting with +// the openai API. +// +// Note, unlike clients, this service does not read variables from the environment +// automatically. You should not instantiate this service directly, and instead use +// the [NewEvalService] method instead. +type EvalService struct { + Options []option.RequestOption + Runs EvalRunService +} + +// NewEvalService generates a new service that applies the given options to each +// request. These options are applied after the parent client's options (if there +// is one), and before any request-specific options. +func NewEvalService(opts ...option.RequestOption) (r EvalService) { + r = EvalService{} + r.Options = opts + r.Runs = NewEvalRunService(opts...) + return +} + +// Create the structure of an evaluation that can be used to test a model's +// performance. An evaluation is a set of testing criteria and a datasource. After +// creating an evaluation, you can run it on different models and model parameters. +// We support several types of graders and datasources. For more information, see +// the [Evals guide](https://platform.openai.com/docs/guides/evals). +func (r *EvalService) New(ctx context.Context, body EvalNewParams, opts ...option.RequestOption) (res *EvalNewResponse, err error) { + opts = append(r.Options[:], opts...) + path := "evals" + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) + return +} + +// Get an evaluation by ID. +func (r *EvalService) Get(ctx context.Context, evalID string, opts ...option.RequestOption) (res *EvalGetResponse, err error) { + opts = append(r.Options[:], opts...) + if evalID == "" { + err = errors.New("missing required eval_id parameter") + return + } + path := fmt.Sprintf("evals/%s", evalID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) + return +} + +// Update certain properties of an evaluation. +func (r *EvalService) Update(ctx context.Context, evalID string, body EvalUpdateParams, opts ...option.RequestOption) (res *EvalUpdateResponse, err error) { + opts = append(r.Options[:], opts...) + if evalID == "" { + err = errors.New("missing required eval_id parameter") + return + } + path := fmt.Sprintf("evals/%s", evalID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) + return +} + +// List evaluations for a project. +func (r *EvalService) List(ctx context.Context, query EvalListParams, opts ...option.RequestOption) (res *pagination.CursorPage[EvalListResponse], err error) { + var raw *http.Response + opts = append(r.Options[:], opts...) + opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) + path := "evals" + cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...) + if err != nil { + return nil, err + } + err = cfg.Execute() + if err != nil { + return nil, err + } + res.SetPageConfig(cfg, raw) + return res, nil +} + +// List evaluations for a project. +func (r *EvalService) ListAutoPaging(ctx context.Context, query EvalListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[EvalListResponse] { + return pagination.NewCursorPageAutoPager(r.List(ctx, query, opts...)) +} + +// Delete an evaluation. +func (r *EvalService) Delete(ctx context.Context, evalID string, opts ...option.RequestOption) (res *EvalDeleteResponse, err error) { + opts = append(r.Options[:], opts...) + if evalID == "" { + err = errors.New("missing required eval_id parameter") + return + } + path := fmt.Sprintf("evals/%s", evalID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...) + return +} + +// A CustomDataSourceConfig which specifies the schema of your `item` and +// optionally `sample` namespaces. The response schema defines the shape of the +// data that will be: +// +// - Used to define your testing criteria and +// - What data is required when creating a run +type EvalCustomDataSourceConfig struct { + // The json schema for the run data source items. Learn how to build JSON schemas + // [here](https://json-schema.org/). + Schema map[string]interface{} `json:"schema,required"` + // The type of data source. Always `custom`. + Type constant.Custom `json:"type,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Schema resp.Field + Type resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalCustomDataSourceConfig) RawJSON() string { return r.JSON.raw } +func (r *EvalCustomDataSourceConfig) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// A LabelModelGrader object which uses a model to assign labels to each item in +// the evaluation. +type EvalLabelModelGrader struct { + Input []EvalLabelModelGraderInputUnion `json:"input,required"` + // The labels to assign to each item in the evaluation. + Labels []string `json:"labels,required"` + // The model to use for the evaluation. Must support structured outputs. + Model string `json:"model,required"` + // The name of the grader. + Name string `json:"name,required"` + // The labels that indicate a passing result. Must be a subset of labels. + PassingLabels []string `json:"passing_labels,required"` + // The object type, which is always `label_model`. + Type constant.LabelModel `json:"type,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Input resp.Field + Labels resp.Field + Model resp.Field + Name resp.Field + PassingLabels resp.Field + Type resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalLabelModelGrader) RawJSON() string { return r.JSON.raw } +func (r *EvalLabelModelGrader) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalLabelModelGraderInputUnion contains all possible properties and values from +// [EvalLabelModelGraderInputInputMessage], [EvalLabelModelGraderInputAssistant]. +// +// Use the [EvalLabelModelGraderInputUnion.AsAny] method to switch on the variant. +// +// Use the methods beginning with 'As' to cast the union to one of its variants. +type EvalLabelModelGraderInputUnion struct { + // This field is a union of [EvalLabelModelGraderInputInputMessageContent], + // [EvalLabelModelGraderInputAssistantContent] + Content EvalLabelModelGraderInputUnionContent `json:"content"` + // Any of nil, "assistant". + Role string `json:"role"` + Type string `json:"type"` + JSON struct { + Content resp.Field + Role resp.Field + Type resp.Field + raw string + } `json:"-"` +} + +func (u EvalLabelModelGraderInputUnion) AsInputMessage() (v EvalLabelModelGraderInputInputMessage) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u EvalLabelModelGraderInputUnion) AsAssistant() (v EvalLabelModelGraderInputAssistant) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +// Returns the unmodified JSON received from the API +func (u EvalLabelModelGraderInputUnion) RawJSON() string { return u.JSON.raw } + +func (r *EvalLabelModelGraderInputUnion) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalLabelModelGraderInputUnionContent is an implicit subunion of +// [EvalLabelModelGraderInputUnion]. EvalLabelModelGraderInputUnionContent provides +// convenient access to the sub-properties of the union. +// +// For type safety it is recommended to directly use a variant of the +// [EvalLabelModelGraderInputUnion]. +type EvalLabelModelGraderInputUnionContent struct { + Text string `json:"text"` + Type string `json:"type"` + JSON struct { + Text resp.Field + Type resp.Field + raw string + } `json:"-"` +} + +func (r *EvalLabelModelGraderInputUnionContent) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type EvalLabelModelGraderInputInputMessage struct { + Content EvalLabelModelGraderInputInputMessageContent `json:"content,required"` + // The role of the message. One of `user`, `system`, or `developer`. + // + // Any of "user", "system", "developer". + Role string `json:"role,required"` + // The type of item, which is always `message`. + // + // Any of "message". + Type string `json:"type,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Content resp.Field + Role resp.Field + Type resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalLabelModelGraderInputInputMessage) RawJSON() string { return r.JSON.raw } +func (r *EvalLabelModelGraderInputInputMessage) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type EvalLabelModelGraderInputInputMessageContent struct { + // The text content. + Text string `json:"text,required"` + // The type of content, which is always `input_text`. + // + // Any of "input_text". + Type string `json:"type,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Text resp.Field + Type resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalLabelModelGraderInputInputMessageContent) RawJSON() string { return r.JSON.raw } +func (r *EvalLabelModelGraderInputInputMessageContent) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type EvalLabelModelGraderInputAssistant struct { + Content EvalLabelModelGraderInputAssistantContent `json:"content,required"` + // The role of the message. Must be `assistant` for output. + Role constant.Assistant `json:"role,required"` + // The type of item, which is always `message`. + // + // Any of "message". + Type string `json:"type,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Content resp.Field + Role resp.Field + Type resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalLabelModelGraderInputAssistant) RawJSON() string { return r.JSON.raw } +func (r *EvalLabelModelGraderInputAssistant) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type EvalLabelModelGraderInputAssistantContent struct { + // The text content. + Text string `json:"text,required"` + // The type of content, which is always `output_text`. + // + // Any of "output_text". + Type string `json:"type,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Text resp.Field + Type resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalLabelModelGraderInputAssistantContent) RawJSON() string { return r.JSON.raw } +func (r *EvalLabelModelGraderInputAssistantContent) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// A StoredCompletionsDataSourceConfig which specifies the metadata property of +// your stored completions query. This is usually metadata like `usecase=chatbot` +// or `prompt-version=v2`, etc. The schema returned by this data source config is +// used to defined what variables are available in your evals. `item` and `sample` +// are both defined when using this data source config. +type EvalStoredCompletionsDataSourceConfig struct { + // The json schema for the run data source items. Learn how to build JSON schemas + // [here](https://json-schema.org/). + Schema map[string]interface{} `json:"schema,required"` + // The type of data source. Always `stored_completions`. + Type constant.StoredCompletions `json:"type,required"` + // Set of 16 key-value pairs that can be attached to an object. This can be useful + // for storing additional information about the object in a structured format, and + // querying for objects via API or the dashboard. + // + // Keys are strings with a maximum length of 64 characters. Values are strings with + // a maximum length of 512 characters. + Metadata shared.Metadata `json:"metadata,nullable"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Schema resp.Field + Type resp.Field + Metadata resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalStoredCompletionsDataSourceConfig) RawJSON() string { return r.JSON.raw } +func (r *EvalStoredCompletionsDataSourceConfig) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// A StringCheckGrader object that performs a string comparison between input and +// reference using a specified operation. +type EvalStringCheckGrader struct { + // The input text. This may include template strings. + Input string `json:"input,required"` + // The name of the grader. + Name string `json:"name,required"` + // The string check operation to perform. One of `eq`, `ne`, `like`, or `ilike`. + // + // Any of "eq", "ne", "like", "ilike". + Operation EvalStringCheckGraderOperation `json:"operation,required"` + // The reference text. This may include template strings. + Reference string `json:"reference,required"` + // The object type, which is always `string_check`. + Type constant.StringCheck `json:"type,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Input resp.Field + Name resp.Field + Operation resp.Field + Reference resp.Field + Type resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalStringCheckGrader) RawJSON() string { return r.JSON.raw } +func (r *EvalStringCheckGrader) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// ToParam converts this EvalStringCheckGrader to a EvalStringCheckGraderParam. +// +// Warning: the fields of the param type will not be present. ToParam should only +// be used at the last possible moment before sending a request. Test for this with +// EvalStringCheckGraderParam.IsOverridden() +func (r EvalStringCheckGrader) ToParam() EvalStringCheckGraderParam { + return param.OverrideObj[EvalStringCheckGraderParam](r.RawJSON()) +} + +// The string check operation to perform. One of `eq`, `ne`, `like`, or `ilike`. +type EvalStringCheckGraderOperation string + +const ( + EvalStringCheckGraderOperationEq EvalStringCheckGraderOperation = "eq" + EvalStringCheckGraderOperationNe EvalStringCheckGraderOperation = "ne" + EvalStringCheckGraderOperationLike EvalStringCheckGraderOperation = "like" + EvalStringCheckGraderOperationIlike EvalStringCheckGraderOperation = "ilike" +) + +// A StringCheckGrader object that performs a string comparison between input and +// reference using a specified operation. +// +// The properties Input, Name, Operation, Reference, Type are required. +type EvalStringCheckGraderParam struct { + // The input text. This may include template strings. + Input string `json:"input,required"` + // The name of the grader. + Name string `json:"name,required"` + // The string check operation to perform. One of `eq`, `ne`, `like`, or `ilike`. + // + // Any of "eq", "ne", "like", "ilike". + Operation EvalStringCheckGraderOperation `json:"operation,omitzero,required"` + // The reference text. This may include template strings. + Reference string `json:"reference,required"` + // The object type, which is always `string_check`. + // + // This field can be elided, and will marshal its zero value as "string_check". + Type constant.StringCheck `json:"type,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f EvalStringCheckGraderParam) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() } +func (r EvalStringCheckGraderParam) MarshalJSON() (data []byte, err error) { + type shadow EvalStringCheckGraderParam + return param.MarshalObject(r, (*shadow)(&r)) +} + +// A TextSimilarityGrader object which grades text based on similarity metrics. +type EvalTextSimilarityGrader struct { + // The evaluation metric to use. One of `cosine`, `fuzzy_match`, `bleu`, `gleu`, + // `meteor`, `rouge_1`, `rouge_2`, `rouge_3`, `rouge_4`, `rouge_5`, or `rouge_l`. + // + // Any of "fuzzy_match", "bleu", "gleu", "meteor", "rouge_1", "rouge_2", "rouge_3", + // "rouge_4", "rouge_5", "rouge_l", "cosine". + EvaluationMetric EvalTextSimilarityGraderEvaluationMetric `json:"evaluation_metric,required"` + // The text being graded. + Input string `json:"input,required"` + // A float score where a value greater than or equal indicates a passing grade. + PassThreshold float64 `json:"pass_threshold,required"` + // The text being graded against. + Reference string `json:"reference,required"` + // The type of grader. + Type constant.TextSimilarity `json:"type,required"` + // The name of the grader. + Name string `json:"name"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + EvaluationMetric resp.Field + Input resp.Field + PassThreshold resp.Field + Reference resp.Field + Type resp.Field + Name resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalTextSimilarityGrader) RawJSON() string { return r.JSON.raw } +func (r *EvalTextSimilarityGrader) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// ToParam converts this EvalTextSimilarityGrader to a +// EvalTextSimilarityGraderParam. +// +// Warning: the fields of the param type will not be present. ToParam should only +// be used at the last possible moment before sending a request. Test for this with +// EvalTextSimilarityGraderParam.IsOverridden() +func (r EvalTextSimilarityGrader) ToParam() EvalTextSimilarityGraderParam { + return param.OverrideObj[EvalTextSimilarityGraderParam](r.RawJSON()) +} + +// The evaluation metric to use. One of `cosine`, `fuzzy_match`, `bleu`, `gleu`, +// `meteor`, `rouge_1`, `rouge_2`, `rouge_3`, `rouge_4`, `rouge_5`, or `rouge_l`. +type EvalTextSimilarityGraderEvaluationMetric string + +const ( + EvalTextSimilarityGraderEvaluationMetricFuzzyMatch EvalTextSimilarityGraderEvaluationMetric = "fuzzy_match" + EvalTextSimilarityGraderEvaluationMetricBleu EvalTextSimilarityGraderEvaluationMetric = "bleu" + EvalTextSimilarityGraderEvaluationMetricGleu EvalTextSimilarityGraderEvaluationMetric = "gleu" + EvalTextSimilarityGraderEvaluationMetricMeteor EvalTextSimilarityGraderEvaluationMetric = "meteor" + EvalTextSimilarityGraderEvaluationMetricRouge1 EvalTextSimilarityGraderEvaluationMetric = "rouge_1" + EvalTextSimilarityGraderEvaluationMetricRouge2 EvalTextSimilarityGraderEvaluationMetric = "rouge_2" + EvalTextSimilarityGraderEvaluationMetricRouge3 EvalTextSimilarityGraderEvaluationMetric = "rouge_3" + EvalTextSimilarityGraderEvaluationMetricRouge4 EvalTextSimilarityGraderEvaluationMetric = "rouge_4" + EvalTextSimilarityGraderEvaluationMetricRouge5 EvalTextSimilarityGraderEvaluationMetric = "rouge_5" + EvalTextSimilarityGraderEvaluationMetricRougeL EvalTextSimilarityGraderEvaluationMetric = "rouge_l" + EvalTextSimilarityGraderEvaluationMetricCosine EvalTextSimilarityGraderEvaluationMetric = "cosine" +) + +// A TextSimilarityGrader object which grades text based on similarity metrics. +// +// The properties EvaluationMetric, Input, PassThreshold, Reference, Type are +// required. +type EvalTextSimilarityGraderParam struct { + // The evaluation metric to use. One of `cosine`, `fuzzy_match`, `bleu`, `gleu`, + // `meteor`, `rouge_1`, `rouge_2`, `rouge_3`, `rouge_4`, `rouge_5`, or `rouge_l`. + // + // Any of "fuzzy_match", "bleu", "gleu", "meteor", "rouge_1", "rouge_2", "rouge_3", + // "rouge_4", "rouge_5", "rouge_l", "cosine". + EvaluationMetric EvalTextSimilarityGraderEvaluationMetric `json:"evaluation_metric,omitzero,required"` + // The text being graded. + Input string `json:"input,required"` + // A float score where a value greater than or equal indicates a passing grade. + PassThreshold float64 `json:"pass_threshold,required"` + // The text being graded against. + Reference string `json:"reference,required"` + // The name of the grader. + Name param.Opt[string] `json:"name,omitzero"` + // The type of grader. + // + // This field can be elided, and will marshal its zero value as "text_similarity". + Type constant.TextSimilarity `json:"type,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f EvalTextSimilarityGraderParam) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() } +func (r EvalTextSimilarityGraderParam) MarshalJSON() (data []byte, err error) { + type shadow EvalTextSimilarityGraderParam + return param.MarshalObject(r, (*shadow)(&r)) +} + +// An Eval object with a data source config and testing criteria. An Eval +// represents a task to be done for your LLM integration. Like: +// +// - Improve the quality of my chatbot +// - See how well my chatbot handles customer support +// - Check if o3-mini is better at my usecase than gpt-4o +type EvalNewResponse struct { + // Unique identifier for the evaluation. + ID string `json:"id,required"` + // The Unix timestamp (in seconds) for when the eval was created. + CreatedAt int64 `json:"created_at,required"` + // Configuration of data sources used in runs of the evaluation. + DataSourceConfig EvalNewResponseDataSourceConfigUnion `json:"data_source_config,required"` + // Set of 16 key-value pairs that can be attached to an object. This can be useful + // for storing additional information about the object in a structured format, and + // querying for objects via API or the dashboard. + // + // Keys are strings with a maximum length of 64 characters. Values are strings with + // a maximum length of 512 characters. + Metadata shared.Metadata `json:"metadata,required"` + // The name of the evaluation. + Name string `json:"name,required"` + // The object type. + Object constant.Eval `json:"object,required"` + // Indicates whether the evaluation is shared with OpenAI. + ShareWithOpenAI bool `json:"share_with_openai,required"` + // A list of testing criteria. + TestingCriteria []EvalNewResponseTestingCriterionUnion `json:"testing_criteria,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + ID resp.Field + CreatedAt resp.Field + DataSourceConfig resp.Field + Metadata resp.Field + Name resp.Field + Object resp.Field + ShareWithOpenAI resp.Field + TestingCriteria resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalNewResponse) RawJSON() string { return r.JSON.raw } +func (r *EvalNewResponse) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalNewResponseDataSourceConfigUnion contains all possible properties and values +// from [EvalCustomDataSourceConfig], [EvalStoredCompletionsDataSourceConfig]. +// +// Use the [EvalNewResponseDataSourceConfigUnion.AsAny] method to switch on the +// variant. +// +// Use the methods beginning with 'As' to cast the union to one of its variants. +type EvalNewResponseDataSourceConfigUnion struct { + // This field is a union of [map[string]interface{}], [map[string]interface{}] + Schema EvalNewResponseDataSourceConfigUnionSchema `json:"schema"` + // Any of "custom", "stored_completions". + Type string `json:"type"` + // This field is from variant [EvalStoredCompletionsDataSourceConfig]. + Metadata shared.Metadata `json:"metadata"` + JSON struct { + Schema resp.Field + Type resp.Field + Metadata resp.Field + raw string + } `json:"-"` +} + +// anyEvalNewResponseDataSourceConfig is implemented by each variant of +// [EvalNewResponseDataSourceConfigUnion] to add type safety for the return type of +// [EvalNewResponseDataSourceConfigUnion.AsAny] +type anyEvalNewResponseDataSourceConfig interface { + implEvalNewResponseDataSourceConfigUnion() +} + +func (EvalCustomDataSourceConfig) implEvalNewResponseDataSourceConfigUnion() {} +func (EvalStoredCompletionsDataSourceConfig) implEvalNewResponseDataSourceConfigUnion() {} + +// Use the following switch statement to find the correct variant +// +// switch variant := EvalNewResponseDataSourceConfigUnion.AsAny().(type) { +// case EvalCustomDataSourceConfig: +// case EvalStoredCompletionsDataSourceConfig: +// default: +// fmt.Errorf("no variant present") +// } +func (u EvalNewResponseDataSourceConfigUnion) AsAny() anyEvalNewResponseDataSourceConfig { + switch u.Type { + case "custom": + return u.AsCustom() + case "stored_completions": + return u.AsStoredCompletions() + } + return nil +} + +func (u EvalNewResponseDataSourceConfigUnion) AsCustom() (v EvalCustomDataSourceConfig) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u EvalNewResponseDataSourceConfigUnion) AsStoredCompletions() (v EvalStoredCompletionsDataSourceConfig) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +// Returns the unmodified JSON received from the API +func (u EvalNewResponseDataSourceConfigUnion) RawJSON() string { return u.JSON.raw } + +func (r *EvalNewResponseDataSourceConfigUnion) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalNewResponseDataSourceConfigUnionSchema is an implicit subunion of +// [EvalNewResponseDataSourceConfigUnion]. +// EvalNewResponseDataSourceConfigUnionSchema provides convenient access to the +// sub-properties of the union. +// +// For type safety it is recommended to directly use a variant of the +// [EvalNewResponseDataSourceConfigUnion]. +// +// If the underlying value is not a json object, one of the following properties +// will be valid: OfEvalCustomDataSourceConfigSchema +// OfEvalStoredCompletionsDataSourceConfigSchema] +type EvalNewResponseDataSourceConfigUnionSchema struct { + // This field will be present if the value is a [interface{}] instead of an object. + OfEvalCustomDataSourceConfigSchema interface{} `json:",inline"` + // This field will be present if the value is a [interface{}] instead of an object. + OfEvalStoredCompletionsDataSourceConfigSchema interface{} `json:",inline"` + JSON struct { + OfEvalCustomDataSourceConfigSchema resp.Field + OfEvalStoredCompletionsDataSourceConfigSchema resp.Field + raw string + } `json:"-"` +} + +func (r *EvalNewResponseDataSourceConfigUnionSchema) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalNewResponseTestingCriterionUnion contains all possible properties and values +// from [EvalLabelModelGrader], [EvalStringCheckGrader], +// [EvalTextSimilarityGrader]. +// +// Use the [EvalNewResponseTestingCriterionUnion.AsAny] method to switch on the +// variant. +// +// Use the methods beginning with 'As' to cast the union to one of its variants. +type EvalNewResponseTestingCriterionUnion struct { + // This field is a union of [[]EvalLabelModelGraderInputUnion], [string], [string] + Input EvalNewResponseTestingCriterionUnionInput `json:"input"` + // This field is from variant [EvalLabelModelGrader]. + Labels []string `json:"labels"` + // This field is from variant [EvalLabelModelGrader]. + Model string `json:"model"` + Name string `json:"name"` + // This field is from variant [EvalLabelModelGrader]. + PassingLabels []string `json:"passing_labels"` + // Any of "label_model", "string_check", "text_similarity". + Type string `json:"type"` + // This field is from variant [EvalStringCheckGrader]. + Operation EvalStringCheckGraderOperation `json:"operation"` + Reference string `json:"reference"` + // This field is from variant [EvalTextSimilarityGrader]. + EvaluationMetric EvalTextSimilarityGraderEvaluationMetric `json:"evaluation_metric"` + // This field is from variant [EvalTextSimilarityGrader]. + PassThreshold float64 `json:"pass_threshold"` + JSON struct { + Input resp.Field + Labels resp.Field + Model resp.Field + Name resp.Field + PassingLabels resp.Field + Type resp.Field + Operation resp.Field + Reference resp.Field + EvaluationMetric resp.Field + PassThreshold resp.Field + raw string + } `json:"-"` +} + +// anyEvalNewResponseTestingCriterion is implemented by each variant of +// [EvalNewResponseTestingCriterionUnion] to add type safety for the return type of +// [EvalNewResponseTestingCriterionUnion.AsAny] +type anyEvalNewResponseTestingCriterion interface { + implEvalNewResponseTestingCriterionUnion() +} + +func (EvalLabelModelGrader) implEvalNewResponseTestingCriterionUnion() {} +func (EvalStringCheckGrader) implEvalNewResponseTestingCriterionUnion() {} +func (EvalTextSimilarityGrader) implEvalNewResponseTestingCriterionUnion() {} + +// Use the following switch statement to find the correct variant +// +// switch variant := EvalNewResponseTestingCriterionUnion.AsAny().(type) { +// case EvalLabelModelGrader: +// case EvalStringCheckGrader: +// case EvalTextSimilarityGrader: +// default: +// fmt.Errorf("no variant present") +// } +func (u EvalNewResponseTestingCriterionUnion) AsAny() anyEvalNewResponseTestingCriterion { + switch u.Type { + case "label_model": + return u.AsLabelModel() + case "string_check": + return u.AsStringCheck() + case "text_similarity": + return u.AsTextSimilarity() + } + return nil +} + +func (u EvalNewResponseTestingCriterionUnion) AsLabelModel() (v EvalLabelModelGrader) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u EvalNewResponseTestingCriterionUnion) AsStringCheck() (v EvalStringCheckGrader) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u EvalNewResponseTestingCriterionUnion) AsTextSimilarity() (v EvalTextSimilarityGrader) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +// Returns the unmodified JSON received from the API +func (u EvalNewResponseTestingCriterionUnion) RawJSON() string { return u.JSON.raw } + +func (r *EvalNewResponseTestingCriterionUnion) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalNewResponseTestingCriterionUnionInput is an implicit subunion of +// [EvalNewResponseTestingCriterionUnion]. +// EvalNewResponseTestingCriterionUnionInput provides convenient access to the +// sub-properties of the union. +// +// For type safety it is recommended to directly use a variant of the +// [EvalNewResponseTestingCriterionUnion]. +// +// If the underlying value is not a json object, one of the following properties +// will be valid: OfEvalLabelModelGraderInput OfString] +type EvalNewResponseTestingCriterionUnionInput struct { + // This field will be present if the value is a [[]EvalLabelModelGraderInputUnion] + // instead of an object. + OfEvalLabelModelGraderInput []EvalLabelModelGraderInputUnion `json:",inline"` + // This field will be present if the value is a [string] instead of an object. + OfString string `json:",inline"` + JSON struct { + OfEvalLabelModelGraderInput resp.Field + OfString resp.Field + raw string + } `json:"-"` +} + +func (r *EvalNewResponseTestingCriterionUnionInput) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// An Eval object with a data source config and testing criteria. An Eval +// represents a task to be done for your LLM integration. Like: +// +// - Improve the quality of my chatbot +// - See how well my chatbot handles customer support +// - Check if o3-mini is better at my usecase than gpt-4o +type EvalGetResponse struct { + // Unique identifier for the evaluation. + ID string `json:"id,required"` + // The Unix timestamp (in seconds) for when the eval was created. + CreatedAt int64 `json:"created_at,required"` + // Configuration of data sources used in runs of the evaluation. + DataSourceConfig EvalGetResponseDataSourceConfigUnion `json:"data_source_config,required"` + // Set of 16 key-value pairs that can be attached to an object. This can be useful + // for storing additional information about the object in a structured format, and + // querying for objects via API or the dashboard. + // + // Keys are strings with a maximum length of 64 characters. Values are strings with + // a maximum length of 512 characters. + Metadata shared.Metadata `json:"metadata,required"` + // The name of the evaluation. + Name string `json:"name,required"` + // The object type. + Object constant.Eval `json:"object,required"` + // Indicates whether the evaluation is shared with OpenAI. + ShareWithOpenAI bool `json:"share_with_openai,required"` + // A list of testing criteria. + TestingCriteria []EvalGetResponseTestingCriterionUnion `json:"testing_criteria,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + ID resp.Field + CreatedAt resp.Field + DataSourceConfig resp.Field + Metadata resp.Field + Name resp.Field + Object resp.Field + ShareWithOpenAI resp.Field + TestingCriteria resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalGetResponse) RawJSON() string { return r.JSON.raw } +func (r *EvalGetResponse) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalGetResponseDataSourceConfigUnion contains all possible properties and values +// from [EvalCustomDataSourceConfig], [EvalStoredCompletionsDataSourceConfig]. +// +// Use the [EvalGetResponseDataSourceConfigUnion.AsAny] method to switch on the +// variant. +// +// Use the methods beginning with 'As' to cast the union to one of its variants. +type EvalGetResponseDataSourceConfigUnion struct { + // This field is a union of [map[string]interface{}], [map[string]interface{}] + Schema EvalGetResponseDataSourceConfigUnionSchema `json:"schema"` + // Any of "custom", "stored_completions". + Type string `json:"type"` + // This field is from variant [EvalStoredCompletionsDataSourceConfig]. + Metadata shared.Metadata `json:"metadata"` + JSON struct { + Schema resp.Field + Type resp.Field + Metadata resp.Field + raw string + } `json:"-"` +} + +// anyEvalGetResponseDataSourceConfig is implemented by each variant of +// [EvalGetResponseDataSourceConfigUnion] to add type safety for the return type of +// [EvalGetResponseDataSourceConfigUnion.AsAny] +type anyEvalGetResponseDataSourceConfig interface { + implEvalGetResponseDataSourceConfigUnion() +} + +func (EvalCustomDataSourceConfig) implEvalGetResponseDataSourceConfigUnion() {} +func (EvalStoredCompletionsDataSourceConfig) implEvalGetResponseDataSourceConfigUnion() {} + +// Use the following switch statement to find the correct variant +// +// switch variant := EvalGetResponseDataSourceConfigUnion.AsAny().(type) { +// case EvalCustomDataSourceConfig: +// case EvalStoredCompletionsDataSourceConfig: +// default: +// fmt.Errorf("no variant present") +// } +func (u EvalGetResponseDataSourceConfigUnion) AsAny() anyEvalGetResponseDataSourceConfig { + switch u.Type { + case "custom": + return u.AsCustom() + case "stored_completions": + return u.AsStoredCompletions() + } + return nil +} + +func (u EvalGetResponseDataSourceConfigUnion) AsCustom() (v EvalCustomDataSourceConfig) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u EvalGetResponseDataSourceConfigUnion) AsStoredCompletions() (v EvalStoredCompletionsDataSourceConfig) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +// Returns the unmodified JSON received from the API +func (u EvalGetResponseDataSourceConfigUnion) RawJSON() string { return u.JSON.raw } + +func (r *EvalGetResponseDataSourceConfigUnion) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalGetResponseDataSourceConfigUnionSchema is an implicit subunion of +// [EvalGetResponseDataSourceConfigUnion]. +// EvalGetResponseDataSourceConfigUnionSchema provides convenient access to the +// sub-properties of the union. +// +// For type safety it is recommended to directly use a variant of the +// [EvalGetResponseDataSourceConfigUnion]. +// +// If the underlying value is not a json object, one of the following properties +// will be valid: OfEvalCustomDataSourceConfigSchema +// OfEvalStoredCompletionsDataSourceConfigSchema] +type EvalGetResponseDataSourceConfigUnionSchema struct { + // This field will be present if the value is a [interface{}] instead of an object. + OfEvalCustomDataSourceConfigSchema interface{} `json:",inline"` + // This field will be present if the value is a [interface{}] instead of an object. + OfEvalStoredCompletionsDataSourceConfigSchema interface{} `json:",inline"` + JSON struct { + OfEvalCustomDataSourceConfigSchema resp.Field + OfEvalStoredCompletionsDataSourceConfigSchema resp.Field + raw string + } `json:"-"` +} + +func (r *EvalGetResponseDataSourceConfigUnionSchema) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalGetResponseTestingCriterionUnion contains all possible properties and values +// from [EvalLabelModelGrader], [EvalStringCheckGrader], +// [EvalTextSimilarityGrader]. +// +// Use the [EvalGetResponseTestingCriterionUnion.AsAny] method to switch on the +// variant. +// +// Use the methods beginning with 'As' to cast the union to one of its variants. +type EvalGetResponseTestingCriterionUnion struct { + // This field is a union of [[]EvalLabelModelGraderInputUnion], [string], [string] + Input EvalGetResponseTestingCriterionUnionInput `json:"input"` + // This field is from variant [EvalLabelModelGrader]. + Labels []string `json:"labels"` + // This field is from variant [EvalLabelModelGrader]. + Model string `json:"model"` + Name string `json:"name"` + // This field is from variant [EvalLabelModelGrader]. + PassingLabels []string `json:"passing_labels"` + // Any of "label_model", "string_check", "text_similarity". + Type string `json:"type"` + // This field is from variant [EvalStringCheckGrader]. + Operation EvalStringCheckGraderOperation `json:"operation"` + Reference string `json:"reference"` + // This field is from variant [EvalTextSimilarityGrader]. + EvaluationMetric EvalTextSimilarityGraderEvaluationMetric `json:"evaluation_metric"` + // This field is from variant [EvalTextSimilarityGrader]. + PassThreshold float64 `json:"pass_threshold"` + JSON struct { + Input resp.Field + Labels resp.Field + Model resp.Field + Name resp.Field + PassingLabels resp.Field + Type resp.Field + Operation resp.Field + Reference resp.Field + EvaluationMetric resp.Field + PassThreshold resp.Field + raw string + } `json:"-"` +} + +// anyEvalGetResponseTestingCriterion is implemented by each variant of +// [EvalGetResponseTestingCriterionUnion] to add type safety for the return type of +// [EvalGetResponseTestingCriterionUnion.AsAny] +type anyEvalGetResponseTestingCriterion interface { + implEvalGetResponseTestingCriterionUnion() +} + +func (EvalLabelModelGrader) implEvalGetResponseTestingCriterionUnion() {} +func (EvalStringCheckGrader) implEvalGetResponseTestingCriterionUnion() {} +func (EvalTextSimilarityGrader) implEvalGetResponseTestingCriterionUnion() {} + +// Use the following switch statement to find the correct variant +// +// switch variant := EvalGetResponseTestingCriterionUnion.AsAny().(type) { +// case EvalLabelModelGrader: +// case EvalStringCheckGrader: +// case EvalTextSimilarityGrader: +// default: +// fmt.Errorf("no variant present") +// } +func (u EvalGetResponseTestingCriterionUnion) AsAny() anyEvalGetResponseTestingCriterion { + switch u.Type { + case "label_model": + return u.AsLabelModel() + case "string_check": + return u.AsStringCheck() + case "text_similarity": + return u.AsTextSimilarity() + } + return nil +} + +func (u EvalGetResponseTestingCriterionUnion) AsLabelModel() (v EvalLabelModelGrader) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u EvalGetResponseTestingCriterionUnion) AsStringCheck() (v EvalStringCheckGrader) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u EvalGetResponseTestingCriterionUnion) AsTextSimilarity() (v EvalTextSimilarityGrader) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +// Returns the unmodified JSON received from the API +func (u EvalGetResponseTestingCriterionUnion) RawJSON() string { return u.JSON.raw } + +func (r *EvalGetResponseTestingCriterionUnion) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalGetResponseTestingCriterionUnionInput is an implicit subunion of +// [EvalGetResponseTestingCriterionUnion]. +// EvalGetResponseTestingCriterionUnionInput provides convenient access to the +// sub-properties of the union. +// +// For type safety it is recommended to directly use a variant of the +// [EvalGetResponseTestingCriterionUnion]. +// +// If the underlying value is not a json object, one of the following properties +// will be valid: OfEvalLabelModelGraderInput OfString] +type EvalGetResponseTestingCriterionUnionInput struct { + // This field will be present if the value is a [[]EvalLabelModelGraderInputUnion] + // instead of an object. + OfEvalLabelModelGraderInput []EvalLabelModelGraderInputUnion `json:",inline"` + // This field will be present if the value is a [string] instead of an object. + OfString string `json:",inline"` + JSON struct { + OfEvalLabelModelGraderInput resp.Field + OfString resp.Field + raw string + } `json:"-"` +} + +func (r *EvalGetResponseTestingCriterionUnionInput) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// An Eval object with a data source config and testing criteria. An Eval +// represents a task to be done for your LLM integration. Like: +// +// - Improve the quality of my chatbot +// - See how well my chatbot handles customer support +// - Check if o3-mini is better at my usecase than gpt-4o +type EvalUpdateResponse struct { + // Unique identifier for the evaluation. + ID string `json:"id,required"` + // The Unix timestamp (in seconds) for when the eval was created. + CreatedAt int64 `json:"created_at,required"` + // Configuration of data sources used in runs of the evaluation. + DataSourceConfig EvalUpdateResponseDataSourceConfigUnion `json:"data_source_config,required"` + // Set of 16 key-value pairs that can be attached to an object. This can be useful + // for storing additional information about the object in a structured format, and + // querying for objects via API or the dashboard. + // + // Keys are strings with a maximum length of 64 characters. Values are strings with + // a maximum length of 512 characters. + Metadata shared.Metadata `json:"metadata,required"` + // The name of the evaluation. + Name string `json:"name,required"` + // The object type. + Object constant.Eval `json:"object,required"` + // Indicates whether the evaluation is shared with OpenAI. + ShareWithOpenAI bool `json:"share_with_openai,required"` + // A list of testing criteria. + TestingCriteria []EvalUpdateResponseTestingCriterionUnion `json:"testing_criteria,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + ID resp.Field + CreatedAt resp.Field + DataSourceConfig resp.Field + Metadata resp.Field + Name resp.Field + Object resp.Field + ShareWithOpenAI resp.Field + TestingCriteria resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalUpdateResponse) RawJSON() string { return r.JSON.raw } +func (r *EvalUpdateResponse) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalUpdateResponseDataSourceConfigUnion contains all possible properties and +// values from [EvalCustomDataSourceConfig], +// [EvalStoredCompletionsDataSourceConfig]. +// +// Use the [EvalUpdateResponseDataSourceConfigUnion.AsAny] method to switch on the +// variant. +// +// Use the methods beginning with 'As' to cast the union to one of its variants. +type EvalUpdateResponseDataSourceConfigUnion struct { + // This field is a union of [map[string]interface{}], [map[string]interface{}] + Schema EvalUpdateResponseDataSourceConfigUnionSchema `json:"schema"` + // Any of "custom", "stored_completions". + Type string `json:"type"` + // This field is from variant [EvalStoredCompletionsDataSourceConfig]. + Metadata shared.Metadata `json:"metadata"` + JSON struct { + Schema resp.Field + Type resp.Field + Metadata resp.Field + raw string + } `json:"-"` +} + +// anyEvalUpdateResponseDataSourceConfig is implemented by each variant of +// [EvalUpdateResponseDataSourceConfigUnion] to add type safety for the return type +// of [EvalUpdateResponseDataSourceConfigUnion.AsAny] +type anyEvalUpdateResponseDataSourceConfig interface { + implEvalUpdateResponseDataSourceConfigUnion() +} + +func (EvalCustomDataSourceConfig) implEvalUpdateResponseDataSourceConfigUnion() {} +func (EvalStoredCompletionsDataSourceConfig) implEvalUpdateResponseDataSourceConfigUnion() {} + +// Use the following switch statement to find the correct variant +// +// switch variant := EvalUpdateResponseDataSourceConfigUnion.AsAny().(type) { +// case EvalCustomDataSourceConfig: +// case EvalStoredCompletionsDataSourceConfig: +// default: +// fmt.Errorf("no variant present") +// } +func (u EvalUpdateResponseDataSourceConfigUnion) AsAny() anyEvalUpdateResponseDataSourceConfig { + switch u.Type { + case "custom": + return u.AsCustom() + case "stored_completions": + return u.AsStoredCompletions() + } + return nil +} + +func (u EvalUpdateResponseDataSourceConfigUnion) AsCustom() (v EvalCustomDataSourceConfig) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u EvalUpdateResponseDataSourceConfigUnion) AsStoredCompletions() (v EvalStoredCompletionsDataSourceConfig) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +// Returns the unmodified JSON received from the API +func (u EvalUpdateResponseDataSourceConfigUnion) RawJSON() string { return u.JSON.raw } + +func (r *EvalUpdateResponseDataSourceConfigUnion) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalUpdateResponseDataSourceConfigUnionSchema is an implicit subunion of +// [EvalUpdateResponseDataSourceConfigUnion]. +// EvalUpdateResponseDataSourceConfigUnionSchema provides convenient access to the +// sub-properties of the union. +// +// For type safety it is recommended to directly use a variant of the +// [EvalUpdateResponseDataSourceConfigUnion]. +// +// If the underlying value is not a json object, one of the following properties +// will be valid: OfEvalCustomDataSourceConfigSchema +// OfEvalStoredCompletionsDataSourceConfigSchema] +type EvalUpdateResponseDataSourceConfigUnionSchema struct { + // This field will be present if the value is a [interface{}] instead of an object. + OfEvalCustomDataSourceConfigSchema interface{} `json:",inline"` + // This field will be present if the value is a [interface{}] instead of an object. + OfEvalStoredCompletionsDataSourceConfigSchema interface{} `json:",inline"` + JSON struct { + OfEvalCustomDataSourceConfigSchema resp.Field + OfEvalStoredCompletionsDataSourceConfigSchema resp.Field + raw string + } `json:"-"` +} + +func (r *EvalUpdateResponseDataSourceConfigUnionSchema) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalUpdateResponseTestingCriterionUnion contains all possible properties and +// values from [EvalLabelModelGrader], [EvalStringCheckGrader], +// [EvalTextSimilarityGrader]. +// +// Use the [EvalUpdateResponseTestingCriterionUnion.AsAny] method to switch on the +// variant. +// +// Use the methods beginning with 'As' to cast the union to one of its variants. +type EvalUpdateResponseTestingCriterionUnion struct { + // This field is a union of [[]EvalLabelModelGraderInputUnion], [string], [string] + Input EvalUpdateResponseTestingCriterionUnionInput `json:"input"` + // This field is from variant [EvalLabelModelGrader]. + Labels []string `json:"labels"` + // This field is from variant [EvalLabelModelGrader]. + Model string `json:"model"` + Name string `json:"name"` + // This field is from variant [EvalLabelModelGrader]. + PassingLabels []string `json:"passing_labels"` + // Any of "label_model", "string_check", "text_similarity". + Type string `json:"type"` + // This field is from variant [EvalStringCheckGrader]. + Operation EvalStringCheckGraderOperation `json:"operation"` + Reference string `json:"reference"` + // This field is from variant [EvalTextSimilarityGrader]. + EvaluationMetric EvalTextSimilarityGraderEvaluationMetric `json:"evaluation_metric"` + // This field is from variant [EvalTextSimilarityGrader]. + PassThreshold float64 `json:"pass_threshold"` + JSON struct { + Input resp.Field + Labels resp.Field + Model resp.Field + Name resp.Field + PassingLabels resp.Field + Type resp.Field + Operation resp.Field + Reference resp.Field + EvaluationMetric resp.Field + PassThreshold resp.Field + raw string + } `json:"-"` +} + +// anyEvalUpdateResponseTestingCriterion is implemented by each variant of +// [EvalUpdateResponseTestingCriterionUnion] to add type safety for the return type +// of [EvalUpdateResponseTestingCriterionUnion.AsAny] +type anyEvalUpdateResponseTestingCriterion interface { + implEvalUpdateResponseTestingCriterionUnion() +} + +func (EvalLabelModelGrader) implEvalUpdateResponseTestingCriterionUnion() {} +func (EvalStringCheckGrader) implEvalUpdateResponseTestingCriterionUnion() {} +func (EvalTextSimilarityGrader) implEvalUpdateResponseTestingCriterionUnion() {} + +// Use the following switch statement to find the correct variant +// +// switch variant := EvalUpdateResponseTestingCriterionUnion.AsAny().(type) { +// case EvalLabelModelGrader: +// case EvalStringCheckGrader: +// case EvalTextSimilarityGrader: +// default: +// fmt.Errorf("no variant present") +// } +func (u EvalUpdateResponseTestingCriterionUnion) AsAny() anyEvalUpdateResponseTestingCriterion { + switch u.Type { + case "label_model": + return u.AsLabelModel() + case "string_check": + return u.AsStringCheck() + case "text_similarity": + return u.AsTextSimilarity() + } + return nil +} + +func (u EvalUpdateResponseTestingCriterionUnion) AsLabelModel() (v EvalLabelModelGrader) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u EvalUpdateResponseTestingCriterionUnion) AsStringCheck() (v EvalStringCheckGrader) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u EvalUpdateResponseTestingCriterionUnion) AsTextSimilarity() (v EvalTextSimilarityGrader) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +// Returns the unmodified JSON received from the API +func (u EvalUpdateResponseTestingCriterionUnion) RawJSON() string { return u.JSON.raw } + +func (r *EvalUpdateResponseTestingCriterionUnion) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalUpdateResponseTestingCriterionUnionInput is an implicit subunion of +// [EvalUpdateResponseTestingCriterionUnion]. +// EvalUpdateResponseTestingCriterionUnionInput provides convenient access to the +// sub-properties of the union. +// +// For type safety it is recommended to directly use a variant of the +// [EvalUpdateResponseTestingCriterionUnion]. +// +// If the underlying value is not a json object, one of the following properties +// will be valid: OfEvalLabelModelGraderInput OfString] +type EvalUpdateResponseTestingCriterionUnionInput struct { + // This field will be present if the value is a [[]EvalLabelModelGraderInputUnion] + // instead of an object. + OfEvalLabelModelGraderInput []EvalLabelModelGraderInputUnion `json:",inline"` + // This field will be present if the value is a [string] instead of an object. + OfString string `json:",inline"` + JSON struct { + OfEvalLabelModelGraderInput resp.Field + OfString resp.Field + raw string + } `json:"-"` +} + +func (r *EvalUpdateResponseTestingCriterionUnionInput) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// An Eval object with a data source config and testing criteria. An Eval +// represents a task to be done for your LLM integration. Like: +// +// - Improve the quality of my chatbot +// - See how well my chatbot handles customer support +// - Check if o3-mini is better at my usecase than gpt-4o +type EvalListResponse struct { + // Unique identifier for the evaluation. + ID string `json:"id,required"` + // The Unix timestamp (in seconds) for when the eval was created. + CreatedAt int64 `json:"created_at,required"` + // Configuration of data sources used in runs of the evaluation. + DataSourceConfig EvalListResponseDataSourceConfigUnion `json:"data_source_config,required"` + // Set of 16 key-value pairs that can be attached to an object. This can be useful + // for storing additional information about the object in a structured format, and + // querying for objects via API or the dashboard. + // + // Keys are strings with a maximum length of 64 characters. Values are strings with + // a maximum length of 512 characters. + Metadata shared.Metadata `json:"metadata,required"` + // The name of the evaluation. + Name string `json:"name,required"` + // The object type. + Object constant.Eval `json:"object,required"` + // Indicates whether the evaluation is shared with OpenAI. + ShareWithOpenAI bool `json:"share_with_openai,required"` + // A list of testing criteria. + TestingCriteria []EvalListResponseTestingCriterionUnion `json:"testing_criteria,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + ID resp.Field + CreatedAt resp.Field + DataSourceConfig resp.Field + Metadata resp.Field + Name resp.Field + Object resp.Field + ShareWithOpenAI resp.Field + TestingCriteria resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalListResponse) RawJSON() string { return r.JSON.raw } +func (r *EvalListResponse) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalListResponseDataSourceConfigUnion contains all possible properties and +// values from [EvalCustomDataSourceConfig], +// [EvalStoredCompletionsDataSourceConfig]. +// +// Use the [EvalListResponseDataSourceConfigUnion.AsAny] method to switch on the +// variant. +// +// Use the methods beginning with 'As' to cast the union to one of its variants. +type EvalListResponseDataSourceConfigUnion struct { + // This field is a union of [map[string]interface{}], [map[string]interface{}] + Schema EvalListResponseDataSourceConfigUnionSchema `json:"schema"` + // Any of "custom", "stored_completions". + Type string `json:"type"` + // This field is from variant [EvalStoredCompletionsDataSourceConfig]. + Metadata shared.Metadata `json:"metadata"` + JSON struct { + Schema resp.Field + Type resp.Field + Metadata resp.Field + raw string + } `json:"-"` +} + +// anyEvalListResponseDataSourceConfig is implemented by each variant of +// [EvalListResponseDataSourceConfigUnion] to add type safety for the return type +// of [EvalListResponseDataSourceConfigUnion.AsAny] +type anyEvalListResponseDataSourceConfig interface { + implEvalListResponseDataSourceConfigUnion() +} + +func (EvalCustomDataSourceConfig) implEvalListResponseDataSourceConfigUnion() {} +func (EvalStoredCompletionsDataSourceConfig) implEvalListResponseDataSourceConfigUnion() {} + +// Use the following switch statement to find the correct variant +// +// switch variant := EvalListResponseDataSourceConfigUnion.AsAny().(type) { +// case EvalCustomDataSourceConfig: +// case EvalStoredCompletionsDataSourceConfig: +// default: +// fmt.Errorf("no variant present") +// } +func (u EvalListResponseDataSourceConfigUnion) AsAny() anyEvalListResponseDataSourceConfig { + switch u.Type { + case "custom": + return u.AsCustom() + case "stored_completions": + return u.AsStoredCompletions() + } + return nil +} + +func (u EvalListResponseDataSourceConfigUnion) AsCustom() (v EvalCustomDataSourceConfig) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u EvalListResponseDataSourceConfigUnion) AsStoredCompletions() (v EvalStoredCompletionsDataSourceConfig) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +// Returns the unmodified JSON received from the API +func (u EvalListResponseDataSourceConfigUnion) RawJSON() string { return u.JSON.raw } + +func (r *EvalListResponseDataSourceConfigUnion) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalListResponseDataSourceConfigUnionSchema is an implicit subunion of +// [EvalListResponseDataSourceConfigUnion]. +// EvalListResponseDataSourceConfigUnionSchema provides convenient access to the +// sub-properties of the union. +// +// For type safety it is recommended to directly use a variant of the +// [EvalListResponseDataSourceConfigUnion]. +// +// If the underlying value is not a json object, one of the following properties +// will be valid: OfEvalCustomDataSourceConfigSchema +// OfEvalStoredCompletionsDataSourceConfigSchema] +type EvalListResponseDataSourceConfigUnionSchema struct { + // This field will be present if the value is a [interface{}] instead of an object. + OfEvalCustomDataSourceConfigSchema interface{} `json:",inline"` + // This field will be present if the value is a [interface{}] instead of an object. + OfEvalStoredCompletionsDataSourceConfigSchema interface{} `json:",inline"` + JSON struct { + OfEvalCustomDataSourceConfigSchema resp.Field + OfEvalStoredCompletionsDataSourceConfigSchema resp.Field + raw string + } `json:"-"` +} + +func (r *EvalListResponseDataSourceConfigUnionSchema) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalListResponseTestingCriterionUnion contains all possible properties and +// values from [EvalLabelModelGrader], [EvalStringCheckGrader], +// [EvalTextSimilarityGrader]. +// +// Use the [EvalListResponseTestingCriterionUnion.AsAny] method to switch on the +// variant. +// +// Use the methods beginning with 'As' to cast the union to one of its variants. +type EvalListResponseTestingCriterionUnion struct { + // This field is a union of [[]EvalLabelModelGraderInputUnion], [string], [string] + Input EvalListResponseTestingCriterionUnionInput `json:"input"` + // This field is from variant [EvalLabelModelGrader]. + Labels []string `json:"labels"` + // This field is from variant [EvalLabelModelGrader]. + Model string `json:"model"` + Name string `json:"name"` + // This field is from variant [EvalLabelModelGrader]. + PassingLabels []string `json:"passing_labels"` + // Any of "label_model", "string_check", "text_similarity". + Type string `json:"type"` + // This field is from variant [EvalStringCheckGrader]. + Operation EvalStringCheckGraderOperation `json:"operation"` + Reference string `json:"reference"` + // This field is from variant [EvalTextSimilarityGrader]. + EvaluationMetric EvalTextSimilarityGraderEvaluationMetric `json:"evaluation_metric"` + // This field is from variant [EvalTextSimilarityGrader]. + PassThreshold float64 `json:"pass_threshold"` + JSON struct { + Input resp.Field + Labels resp.Field + Model resp.Field + Name resp.Field + PassingLabels resp.Field + Type resp.Field + Operation resp.Field + Reference resp.Field + EvaluationMetric resp.Field + PassThreshold resp.Field + raw string + } `json:"-"` +} + +// anyEvalListResponseTestingCriterion is implemented by each variant of +// [EvalListResponseTestingCriterionUnion] to add type safety for the return type +// of [EvalListResponseTestingCriterionUnion.AsAny] +type anyEvalListResponseTestingCriterion interface { + implEvalListResponseTestingCriterionUnion() +} + +func (EvalLabelModelGrader) implEvalListResponseTestingCriterionUnion() {} +func (EvalStringCheckGrader) implEvalListResponseTestingCriterionUnion() {} +func (EvalTextSimilarityGrader) implEvalListResponseTestingCriterionUnion() {} + +// Use the following switch statement to find the correct variant +// +// switch variant := EvalListResponseTestingCriterionUnion.AsAny().(type) { +// case EvalLabelModelGrader: +// case EvalStringCheckGrader: +// case EvalTextSimilarityGrader: +// default: +// fmt.Errorf("no variant present") +// } +func (u EvalListResponseTestingCriterionUnion) AsAny() anyEvalListResponseTestingCriterion { + switch u.Type { + case "label_model": + return u.AsLabelModel() + case "string_check": + return u.AsStringCheck() + case "text_similarity": + return u.AsTextSimilarity() + } + return nil +} + +func (u EvalListResponseTestingCriterionUnion) AsLabelModel() (v EvalLabelModelGrader) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u EvalListResponseTestingCriterionUnion) AsStringCheck() (v EvalStringCheckGrader) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u EvalListResponseTestingCriterionUnion) AsTextSimilarity() (v EvalTextSimilarityGrader) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +// Returns the unmodified JSON received from the API +func (u EvalListResponseTestingCriterionUnion) RawJSON() string { return u.JSON.raw } + +func (r *EvalListResponseTestingCriterionUnion) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalListResponseTestingCriterionUnionInput is an implicit subunion of +// [EvalListResponseTestingCriterionUnion]. +// EvalListResponseTestingCriterionUnionInput provides convenient access to the +// sub-properties of the union. +// +// For type safety it is recommended to directly use a variant of the +// [EvalListResponseTestingCriterionUnion]. +// +// If the underlying value is not a json object, one of the following properties +// will be valid: OfEvalLabelModelGraderInput OfString] +type EvalListResponseTestingCriterionUnionInput struct { + // This field will be present if the value is a [[]EvalLabelModelGraderInputUnion] + // instead of an object. + OfEvalLabelModelGraderInput []EvalLabelModelGraderInputUnion `json:",inline"` + // This field will be present if the value is a [string] instead of an object. + OfString string `json:",inline"` + JSON struct { + OfEvalLabelModelGraderInput resp.Field + OfString resp.Field + raw string + } `json:"-"` +} + +func (r *EvalListResponseTestingCriterionUnionInput) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type EvalDeleteResponse struct { + Deleted bool `json:"deleted,required"` + EvalID string `json:"eval_id,required"` + Object string `json:"object,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Deleted resp.Field + EvalID resp.Field + Object resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalDeleteResponse) RawJSON() string { return r.JSON.raw } +func (r *EvalDeleteResponse) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type EvalNewParams struct { + // The configuration for the data source used for the evaluation runs. + DataSourceConfig EvalNewParamsDataSourceConfigUnion `json:"data_source_config,omitzero,required"` + // A list of graders for all eval runs in this group. + TestingCriteria []EvalNewParamsTestingCriterionUnion `json:"testing_criteria,omitzero,required"` + // The name of the evaluation. + Name param.Opt[string] `json:"name,omitzero"` + // Indicates whether the evaluation is shared with OpenAI. + ShareWithOpenAI param.Opt[bool] `json:"share_with_openai,omitzero"` + // Set of 16 key-value pairs that can be attached to an object. This can be useful + // for storing additional information about the object in a structured format, and + // querying for objects via API or the dashboard. + // + // Keys are strings with a maximum length of 64 characters. Values are strings with + // a maximum length of 512 characters. + Metadata shared.MetadataParam `json:"metadata,omitzero"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f EvalNewParams) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() } + +func (r EvalNewParams) MarshalJSON() (data []byte, err error) { + type shadow EvalNewParams + return param.MarshalObject(r, (*shadow)(&r)) +} + +// Only one field can be non-zero. +// +// Use [param.IsOmitted] to confirm if a field is set. +type EvalNewParamsDataSourceConfigUnion struct { + OfCustom *EvalNewParamsDataSourceConfigCustom `json:",omitzero,inline"` + OfStoredCompletions *EvalNewParamsDataSourceConfigStoredCompletions `json:",omitzero,inline"` + paramUnion +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (u EvalNewParamsDataSourceConfigUnion) IsPresent() bool { + return !param.IsOmitted(u) && !u.IsNull() +} +func (u EvalNewParamsDataSourceConfigUnion) MarshalJSON() ([]byte, error) { + return param.MarshalUnion[EvalNewParamsDataSourceConfigUnion](u.OfCustom, u.OfStoredCompletions) +} + +func (u *EvalNewParamsDataSourceConfigUnion) asAny() any { + if !param.IsOmitted(u.OfCustom) { + return u.OfCustom + } else if !param.IsOmitted(u.OfStoredCompletions) { + return u.OfStoredCompletions + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u EvalNewParamsDataSourceConfigUnion) GetItemSchema() map[string]interface{} { + if vt := u.OfCustom; vt != nil { + return vt.ItemSchema + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u EvalNewParamsDataSourceConfigUnion) GetIncludeSampleSchema() *bool { + if vt := u.OfCustom; vt != nil && vt.IncludeSampleSchema.IsPresent() { + return &vt.IncludeSampleSchema.Value + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u EvalNewParamsDataSourceConfigUnion) GetMetadata() shared.MetadataParam { + if vt := u.OfStoredCompletions; vt != nil { + return vt.Metadata + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u EvalNewParamsDataSourceConfigUnion) GetType() *string { + if vt := u.OfCustom; vt != nil { + return (*string)(&vt.Type) + } else if vt := u.OfStoredCompletions; vt != nil { + return (*string)(&vt.Type) + } + return nil +} + +func init() { + apijson.RegisterUnion[EvalNewParamsDataSourceConfigUnion]( + "type", + apijson.UnionVariant{ + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(EvalNewParamsDataSourceConfigCustom{}), + DiscriminatorValue: "custom", + }, + apijson.UnionVariant{ + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(EvalNewParamsDataSourceConfigStoredCompletions{}), + DiscriminatorValue: "stored_completions", + }, + ) +} + +// A CustomDataSourceConfig object that defines the schema for the data source used +// for the evaluation runs. This schema is used to define the shape of the data +// that will be: +// +// - Used to define your testing criteria and +// - What data is required when creating a run +// +// The properties ItemSchema, Type are required. +type EvalNewParamsDataSourceConfigCustom struct { + // The json schema for the run data source items. + ItemSchema map[string]interface{} `json:"item_schema,omitzero,required"` + // Whether to include the sample schema in the data source. + IncludeSampleSchema param.Opt[bool] `json:"include_sample_schema,omitzero"` + // The type of data source. Always `custom`. + // + // This field can be elided, and will marshal its zero value as "custom". + Type constant.Custom `json:"type,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f EvalNewParamsDataSourceConfigCustom) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r EvalNewParamsDataSourceConfigCustom) MarshalJSON() (data []byte, err error) { + type shadow EvalNewParamsDataSourceConfigCustom + return param.MarshalObject(r, (*shadow)(&r)) +} + +// A data source config which specifies the metadata property of your stored +// completions query. This is usually metadata like `usecase=chatbot` or +// `prompt-version=v2`, etc. +// +// The property Type is required. +type EvalNewParamsDataSourceConfigStoredCompletions struct { + // Set of 16 key-value pairs that can be attached to an object. This can be useful + // for storing additional information about the object in a structured format, and + // querying for objects via API or the dashboard. + // + // Keys are strings with a maximum length of 64 characters. Values are strings with + // a maximum length of 512 characters. + Metadata shared.MetadataParam `json:"metadata,omitzero"` + // The type of data source. Always `stored_completions`. + // + // This field can be elided, and will marshal its zero value as + // "stored_completions". + Type constant.StoredCompletions `json:"type,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f EvalNewParamsDataSourceConfigStoredCompletions) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r EvalNewParamsDataSourceConfigStoredCompletions) MarshalJSON() (data []byte, err error) { + type shadow EvalNewParamsDataSourceConfigStoredCompletions + return param.MarshalObject(r, (*shadow)(&r)) +} + +// Only one field can be non-zero. +// +// Use [param.IsOmitted] to confirm if a field is set. +type EvalNewParamsTestingCriterionUnion struct { + OfLabelModel *EvalNewParamsTestingCriterionLabelModel `json:",omitzero,inline"` + OfStringCheck *EvalStringCheckGraderParam `json:",omitzero,inline"` + OfTextSimilarity *EvalTextSimilarityGraderParam `json:",omitzero,inline"` + paramUnion +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (u EvalNewParamsTestingCriterionUnion) IsPresent() bool { + return !param.IsOmitted(u) && !u.IsNull() +} +func (u EvalNewParamsTestingCriterionUnion) MarshalJSON() ([]byte, error) { + return param.MarshalUnion[EvalNewParamsTestingCriterionUnion](u.OfLabelModel, u.OfStringCheck, u.OfTextSimilarity) +} + +func (u *EvalNewParamsTestingCriterionUnion) asAny() any { + if !param.IsOmitted(u.OfLabelModel) { + return u.OfLabelModel + } else if !param.IsOmitted(u.OfStringCheck) { + return u.OfStringCheck + } else if !param.IsOmitted(u.OfTextSimilarity) { + return u.OfTextSimilarity + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u EvalNewParamsTestingCriterionUnion) GetLabels() []string { + if vt := u.OfLabelModel; vt != nil { + return vt.Labels + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u EvalNewParamsTestingCriterionUnion) GetModel() *string { + if vt := u.OfLabelModel; vt != nil { + return &vt.Model + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u EvalNewParamsTestingCriterionUnion) GetPassingLabels() []string { + if vt := u.OfLabelModel; vt != nil { + return vt.PassingLabels + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u EvalNewParamsTestingCriterionUnion) GetOperation() *string { + if vt := u.OfStringCheck; vt != nil { + return (*string)(&vt.Operation) + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u EvalNewParamsTestingCriterionUnion) GetEvaluationMetric() *string { + if vt := u.OfTextSimilarity; vt != nil { + return (*string)(&vt.EvaluationMetric) + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u EvalNewParamsTestingCriterionUnion) GetPassThreshold() *float64 { + if vt := u.OfTextSimilarity; vt != nil { + return &vt.PassThreshold + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u EvalNewParamsTestingCriterionUnion) GetName() *string { + if vt := u.OfLabelModel; vt != nil { + return (*string)(&vt.Name) + } else if vt := u.OfStringCheck; vt != nil { + return (*string)(&vt.Name) + } else if vt := u.OfTextSimilarity; vt != nil && vt.Name.IsPresent() { + return &vt.Name.Value + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u EvalNewParamsTestingCriterionUnion) GetType() *string { + if vt := u.OfLabelModel; vt != nil { + return (*string)(&vt.Type) + } else if vt := u.OfStringCheck; vt != nil { + return (*string)(&vt.Type) + } else if vt := u.OfTextSimilarity; vt != nil { + return (*string)(&vt.Type) + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u EvalNewParamsTestingCriterionUnion) GetReference() *string { + if vt := u.OfStringCheck; vt != nil { + return (*string)(&vt.Reference) + } else if vt := u.OfTextSimilarity; vt != nil { + return (*string)(&vt.Reference) + } + return nil +} + +// Returns a subunion which exports methods to access subproperties +// +// Or use AsAny() to get the underlying value +func (u EvalNewParamsTestingCriterionUnion) GetInput() (res evalNewParamsTestingCriterionUnionInput) { + if vt := u.OfLabelModel; vt != nil { + res.ofEvalNewsTestingCriterionLabelModelInput = &vt.Input + } else if vt := u.OfStringCheck; vt != nil { + res.ofString = &vt.Input + } else if vt := u.OfTextSimilarity; vt != nil { + res.ofString = &vt.Input + } + return +} + +// Only one field can be non-zero. +// +// Use [param.IsOmitted] to confirm if a field is set. +type evalNewParamsTestingCriterionUnionInput struct { + ofEvalNewsTestingCriterionLabelModelInput *[]EvalNewParamsTestingCriterionLabelModelInputUnion + ofString *string +} + +// Use the following switch statement to get the type of the union: +// +// switch u.AsAny().(type) { +// case *[]openai.EvalNewParamsTestingCriterionLabelModelInputUnion: +// case *string: +// default: +// fmt.Errorf("not present") +// } +func (u evalNewParamsTestingCriterionUnionInput) AsAny() any { + if !param.IsOmitted(u.ofEvalNewsTestingCriterionLabelModelInput) { + return u.ofEvalNewsTestingCriterionLabelModelInput + } else if !param.IsOmitted(u.ofString) { + return u.ofString + } else if !param.IsOmitted(u.ofString) { + return u.ofString + } + return nil +} + +func init() { + apijson.RegisterUnion[EvalNewParamsTestingCriterionUnion]( + "type", + apijson.UnionVariant{ + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(EvalNewParamsTestingCriterionLabelModel{}), + DiscriminatorValue: "label_model", + }, + apijson.UnionVariant{ + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(EvalStringCheckGraderParam{}), + DiscriminatorValue: "string_check", + }, + apijson.UnionVariant{ + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(EvalTextSimilarityGraderParam{}), + DiscriminatorValue: "text_similarity", + }, + ) +} + +// A LabelModelGrader object which uses a model to assign labels to each item in +// the evaluation. +// +// The properties Input, Labels, Model, Name, PassingLabels, Type are required. +type EvalNewParamsTestingCriterionLabelModel struct { + Input []EvalNewParamsTestingCriterionLabelModelInputUnion `json:"input,omitzero,required"` + // The labels to classify to each item in the evaluation. + Labels []string `json:"labels,omitzero,required"` + // The model to use for the evaluation. Must support structured outputs. + Model string `json:"model,required"` + // The name of the grader. + Name string `json:"name,required"` + // The labels that indicate a passing result. Must be a subset of labels. + PassingLabels []string `json:"passing_labels,omitzero,required"` + // The object type, which is always `label_model`. + // + // This field can be elided, and will marshal its zero value as "label_model". + Type constant.LabelModel `json:"type,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f EvalNewParamsTestingCriterionLabelModel) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r EvalNewParamsTestingCriterionLabelModel) MarshalJSON() (data []byte, err error) { + type shadow EvalNewParamsTestingCriterionLabelModel + return param.MarshalObject(r, (*shadow)(&r)) +} + +// Only one field can be non-zero. +// +// Use [param.IsOmitted] to confirm if a field is set. +type EvalNewParamsTestingCriterionLabelModelInputUnion struct { + OfSimpleInputMessage *EvalNewParamsTestingCriterionLabelModelInputSimpleInputMessage `json:",omitzero,inline"` + OfInputMessage *EvalNewParamsTestingCriterionLabelModelInputInputMessage `json:",omitzero,inline"` + OfOutputMessage *EvalNewParamsTestingCriterionLabelModelInputOutputMessage `json:",omitzero,inline"` + paramUnion +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (u EvalNewParamsTestingCriterionLabelModelInputUnion) IsPresent() bool { + return !param.IsOmitted(u) && !u.IsNull() +} +func (u EvalNewParamsTestingCriterionLabelModelInputUnion) MarshalJSON() ([]byte, error) { + return param.MarshalUnion[EvalNewParamsTestingCriterionLabelModelInputUnion](u.OfSimpleInputMessage, u.OfInputMessage, u.OfOutputMessage) +} + +func (u *EvalNewParamsTestingCriterionLabelModelInputUnion) asAny() any { + if !param.IsOmitted(u.OfSimpleInputMessage) { + return u.OfSimpleInputMessage + } else if !param.IsOmitted(u.OfInputMessage) { + return u.OfInputMessage + } else if !param.IsOmitted(u.OfOutputMessage) { + return u.OfOutputMessage + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u EvalNewParamsTestingCriterionLabelModelInputUnion) GetRole() *string { + if vt := u.OfSimpleInputMessage; vt != nil { + return (*string)(&vt.Role) + } else if vt := u.OfInputMessage; vt != nil { + return (*string)(&vt.Role) + } else if vt := u.OfOutputMessage; vt != nil { + return (*string)(&vt.Role) + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u EvalNewParamsTestingCriterionLabelModelInputUnion) GetType() *string { + if vt := u.OfInputMessage; vt != nil { + return (*string)(&vt.Type) + } else if vt := u.OfOutputMessage; vt != nil { + return (*string)(&vt.Type) + } + return nil +} + +// Returns a subunion which exports methods to access subproperties +// +// Or use AsAny() to get the underlying value +func (u EvalNewParamsTestingCriterionLabelModelInputUnion) GetContent() (res evalNewParamsTestingCriterionLabelModelInputUnionContent) { + if vt := u.OfSimpleInputMessage; vt != nil { + res.ofString = &vt.Content + } else if vt := u.OfInputMessage; vt != nil { + res.ofEvalNewsTestingCriterionLabelModelInputInputMessageContent = &vt.Content + } else if vt := u.OfOutputMessage; vt != nil { + res.ofEvalNewsTestingCriterionLabelModelInputOutputMessageContent = &vt.Content + } + return +} + +// Only one field can be non-zero. +// +// Use [param.IsOmitted] to confirm if a field is set. +type evalNewParamsTestingCriterionLabelModelInputUnionContent struct { + ofString *string + ofEvalNewsTestingCriterionLabelModelInputInputMessageContent *EvalNewParamsTestingCriterionLabelModelInputInputMessageContent + ofEvalNewsTestingCriterionLabelModelInputOutputMessageContent *EvalNewParamsTestingCriterionLabelModelInputOutputMessageContent +} + +// Use the following switch statement to get the type of the union: +// +// switch u.AsAny().(type) { +// case *string: +// case *openai.EvalNewParamsTestingCriterionLabelModelInputInputMessageContent: +// case *openai.EvalNewParamsTestingCriterionLabelModelInputOutputMessageContent: +// default: +// fmt.Errorf("not present") +// } +func (u evalNewParamsTestingCriterionLabelModelInputUnionContent) AsAny() any { + if !param.IsOmitted(u.ofString) { + return u.ofString + } else if !param.IsOmitted(u.ofEvalNewsTestingCriterionLabelModelInputInputMessageContent) { + return u.ofEvalNewsTestingCriterionLabelModelInputInputMessageContent + } else if !param.IsOmitted(u.ofEvalNewsTestingCriterionLabelModelInputOutputMessageContent) { + return u.ofEvalNewsTestingCriterionLabelModelInputOutputMessageContent + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u evalNewParamsTestingCriterionLabelModelInputUnionContent) GetText() *string { + if vt := u.ofEvalNewsTestingCriterionLabelModelInputInputMessageContent; vt != nil { + return (*string)(&vt.Text) + } else if vt := u.ofEvalNewsTestingCriterionLabelModelInputOutputMessageContent; vt != nil { + return (*string)(&vt.Text) + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u evalNewParamsTestingCriterionLabelModelInputUnionContent) GetType() *string { + if vt := u.ofEvalNewsTestingCriterionLabelModelInputInputMessageContent; vt != nil { + return (*string)(&vt.Type) + } else if vt := u.ofEvalNewsTestingCriterionLabelModelInputOutputMessageContent; vt != nil { + return (*string)(&vt.Type) + } + return nil +} + +// The properties Content, Role are required. +type EvalNewParamsTestingCriterionLabelModelInputSimpleInputMessage struct { + // The content of the message. + Content string `json:"content,required"` + // The role of the message (e.g. "system", "assistant", "user"). + Role string `json:"role,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f EvalNewParamsTestingCriterionLabelModelInputSimpleInputMessage) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r EvalNewParamsTestingCriterionLabelModelInputSimpleInputMessage) MarshalJSON() (data []byte, err error) { + type shadow EvalNewParamsTestingCriterionLabelModelInputSimpleInputMessage + return param.MarshalObject(r, (*shadow)(&r)) +} + +// The properties Content, Role, Type are required. +type EvalNewParamsTestingCriterionLabelModelInputInputMessage struct { + Content EvalNewParamsTestingCriterionLabelModelInputInputMessageContent `json:"content,omitzero,required"` + // The role of the message. One of `user`, `system`, or `developer`. + // + // Any of "user", "system", "developer". + Role string `json:"role,omitzero,required"` + // The type of item, which is always `message`. + // + // Any of "message". + Type string `json:"type,omitzero,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f EvalNewParamsTestingCriterionLabelModelInputInputMessage) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r EvalNewParamsTestingCriterionLabelModelInputInputMessage) MarshalJSON() (data []byte, err error) { + type shadow EvalNewParamsTestingCriterionLabelModelInputInputMessage + return param.MarshalObject(r, (*shadow)(&r)) +} + +func init() { + apijson.RegisterFieldValidator[EvalNewParamsTestingCriterionLabelModelInputInputMessage]( + "Role", false, "user", "system", "developer", + ) + apijson.RegisterFieldValidator[EvalNewParamsTestingCriterionLabelModelInputInputMessage]( + "Type", false, "message", + ) +} + +// The properties Text, Type are required. +type EvalNewParamsTestingCriterionLabelModelInputInputMessageContent struct { + // The text content. + Text string `json:"text,required"` + // The type of content, which is always `input_text`. + // + // Any of "input_text". + Type string `json:"type,omitzero,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f EvalNewParamsTestingCriterionLabelModelInputInputMessageContent) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r EvalNewParamsTestingCriterionLabelModelInputInputMessageContent) MarshalJSON() (data []byte, err error) { + type shadow EvalNewParamsTestingCriterionLabelModelInputInputMessageContent + return param.MarshalObject(r, (*shadow)(&r)) +} + +func init() { + apijson.RegisterFieldValidator[EvalNewParamsTestingCriterionLabelModelInputInputMessageContent]( + "Type", false, "input_text", + ) +} + +// The properties Content, Role, Type are required. +type EvalNewParamsTestingCriterionLabelModelInputOutputMessage struct { + Content EvalNewParamsTestingCriterionLabelModelInputOutputMessageContent `json:"content,omitzero,required"` + // The role of the message. Must be `assistant` for output. + // + // Any of "assistant". + Role string `json:"role,omitzero,required"` + // The type of item, which is always `message`. + // + // Any of "message". + Type string `json:"type,omitzero,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f EvalNewParamsTestingCriterionLabelModelInputOutputMessage) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r EvalNewParamsTestingCriterionLabelModelInputOutputMessage) MarshalJSON() (data []byte, err error) { + type shadow EvalNewParamsTestingCriterionLabelModelInputOutputMessage + return param.MarshalObject(r, (*shadow)(&r)) +} + +func init() { + apijson.RegisterFieldValidator[EvalNewParamsTestingCriterionLabelModelInputOutputMessage]( + "Role", false, "assistant", + ) + apijson.RegisterFieldValidator[EvalNewParamsTestingCriterionLabelModelInputOutputMessage]( + "Type", false, "message", + ) +} + +// The properties Text, Type are required. +type EvalNewParamsTestingCriterionLabelModelInputOutputMessageContent struct { + // The text content. + Text string `json:"text,required"` + // The type of content, which is always `output_text`. + // + // Any of "output_text". + Type string `json:"type,omitzero,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f EvalNewParamsTestingCriterionLabelModelInputOutputMessageContent) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r EvalNewParamsTestingCriterionLabelModelInputOutputMessageContent) MarshalJSON() (data []byte, err error) { + type shadow EvalNewParamsTestingCriterionLabelModelInputOutputMessageContent + return param.MarshalObject(r, (*shadow)(&r)) +} + +func init() { + apijson.RegisterFieldValidator[EvalNewParamsTestingCriterionLabelModelInputOutputMessageContent]( + "Type", false, "output_text", + ) +} + +type EvalUpdateParams struct { + // Rename the evaluation. + Name param.Opt[string] `json:"name,omitzero"` + // Set of 16 key-value pairs that can be attached to an object. This can be useful + // for storing additional information about the object in a structured format, and + // querying for objects via API or the dashboard. + // + // Keys are strings with a maximum length of 64 characters. Values are strings with + // a maximum length of 512 characters. + Metadata shared.MetadataParam `json:"metadata,omitzero"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f EvalUpdateParams) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() } + +func (r EvalUpdateParams) MarshalJSON() (data []byte, err error) { + type shadow EvalUpdateParams + return param.MarshalObject(r, (*shadow)(&r)) +} + +type EvalListParams struct { + // Identifier for the last eval from the previous pagination request. + After param.Opt[string] `query:"after,omitzero" json:"-"` + // Number of evals to retrieve. + Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` + // Sort order for evals by timestamp. Use `asc` for ascending order or `desc` for + // descending order. + // + // Any of "asc", "desc". + Order EvalListParamsOrder `query:"order,omitzero" json:"-"` + // Evals can be ordered by creation time or last updated time. Use `created_at` for + // creation time or `updated_at` for last updated time. + // + // Any of "created_at", "updated_at". + OrderBy EvalListParamsOrderBy `query:"order_by,omitzero" json:"-"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f EvalListParams) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() } + +// URLQuery serializes [EvalListParams]'s query parameters as `url.Values`. +func (r EvalListParams) URLQuery() (v url.Values, err error) { + return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ + ArrayFormat: apiquery.ArrayQueryFormatBrackets, + NestedFormat: apiquery.NestedQueryFormatBrackets, + }) +} + +// Sort order for evals by timestamp. Use `asc` for ascending order or `desc` for +// descending order. +type EvalListParamsOrder string + +const ( + EvalListParamsOrderAsc EvalListParamsOrder = "asc" + EvalListParamsOrderDesc EvalListParamsOrder = "desc" +) + +// Evals can be ordered by creation time or last updated time. Use `created_at` for +// creation time or `updated_at` for last updated time. +type EvalListParamsOrderBy string + +const ( + EvalListParamsOrderByCreatedAt EvalListParamsOrderBy = "created_at" + EvalListParamsOrderByUpdatedAt EvalListParamsOrderBy = "updated_at" +) diff --git a/eval_test.go b/eval_test.go new file mode 100644 index 00000000..46da2cae --- /dev/null +++ b/eval_test.go @@ -0,0 +1,306 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package openai_test + +import ( + "context" + "errors" + "os" + "testing" + + "github.com/openai/openai-go" + "github.com/openai/openai-go/internal/testutil" + "github.com/openai/openai-go/option" + "github.com/openai/openai-go/shared" +) + +func TestEvalNewWithOptionalParams(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.Evals.New(context.TODO(), openai.EvalNewParams{ + DataSourceConfig: openai.EvalNewParamsDataSourceConfigUnion{ + OfCustom: &openai.EvalNewParamsDataSourceConfigCustom{ + ItemSchema: map[string]interface{}{ + "0": "bar", + "1": "bar", + "2": "bar", + "3": "bar", + "4": "bar", + "5": "bar", + "6": "bar", + "7": "bar", + "8": "bar", + "9": "bar", + "10": "bar", + "11": "bar", + "12": "bar", + "13": "bar", + "14": "bar", + "15": "bar", + "16": "bar", + "17": "bar", + "18": "bar", + "19": "bar", + "20": "bar", + "21": "bar", + "22": "bar", + "23": "bar", + "24": "bar", + "25": "bar", + "26": "bar", + "27": "bar", + "28": "bar", + "29": "bar", + "30": "bar", + "31": "bar", + "32": "bar", + "33": "bar", + "34": "bar", + "35": "bar", + "36": "bar", + "37": "bar", + "38": "bar", + "39": "bar", + "40": "bar", + "41": "bar", + "42": "bar", + "43": "bar", + "44": "bar", + "45": "bar", + "46": "bar", + "47": "bar", + "48": "bar", + "49": "bar", + "50": "bar", + "51": "bar", + "52": "bar", + "53": "bar", + "54": "bar", + "55": "bar", + "56": "bar", + "57": "bar", + "58": "bar", + "59": "bar", + "60": "bar", + "61": "bar", + "62": "bar", + "63": "bar", + "64": "bar", + "65": "bar", + "66": "bar", + "67": "bar", + "68": "bar", + "69": "bar", + "70": "bar", + "71": "bar", + "72": "bar", + "73": "bar", + "74": "bar", + "75": "bar", + "76": "bar", + "77": "bar", + "78": "bar", + "79": "bar", + "80": "bar", + "81": "bar", + "82": "bar", + "83": "bar", + "84": "bar", + "85": "bar", + "86": "bar", + "87": "bar", + "88": "bar", + "89": "bar", + "90": "bar", + "91": "bar", + "92": "bar", + "93": "bar", + "94": "bar", + "95": "bar", + "96": "bar", + "97": "bar", + "98": "bar", + "99": "bar", + "100": "bar", + "101": "bar", + "102": "bar", + "103": "bar", + "104": "bar", + "105": "bar", + "106": "bar", + "107": "bar", + "108": "bar", + "109": "bar", + "110": "bar", + "111": "bar", + "112": "bar", + "113": "bar", + "114": "bar", + "115": "bar", + "116": "bar", + "117": "bar", + "118": "bar", + "119": "bar", + "120": "bar", + "121": "bar", + "122": "bar", + "123": "bar", + "124": "bar", + "125": "bar", + "126": "bar", + "127": "bar", + "128": "bar", + "129": "bar", + "130": "bar", + "131": "bar", + "132": "bar", + "133": "bar", + "134": "bar", + "135": "bar", + "136": "bar", + "137": "bar", + "138": "bar", + "139": "bar", + }, + IncludeSampleSchema: openai.Bool(true), + }, + }, + TestingCriteria: []openai.EvalNewParamsTestingCriterionUnion{{ + OfLabelModel: &openai.EvalNewParamsTestingCriterionLabelModel{ + Input: []openai.EvalNewParamsTestingCriterionLabelModelInputUnion{{ + OfSimpleInputMessage: &openai.EvalNewParamsTestingCriterionLabelModelInputSimpleInputMessage{ + Content: "content", + Role: "role", + }, + }}, + Labels: []string{"string"}, + Model: "model", + Name: "name", + PassingLabels: []string{"string"}, + }, + }}, + Metadata: shared.MetadataParam{ + "foo": "string", + }, + Name: openai.String("name"), + ShareWithOpenAI: openai.Bool(true), + }) + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + +func TestEvalGet(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.Evals.Get(context.TODO(), "eval_id") + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + +func TestEvalUpdateWithOptionalParams(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.Evals.Update( + context.TODO(), + "eval_id", + openai.EvalUpdateParams{ + Metadata: shared.MetadataParam{ + "foo": "string", + }, + Name: openai.String("name"), + }, + ) + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + +func TestEvalListWithOptionalParams(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.Evals.List(context.TODO(), openai.EvalListParams{ + After: openai.String("after"), + Limit: openai.Int(0), + Order: openai.EvalListParamsOrderAsc, + OrderBy: openai.EvalListParamsOrderByCreatedAt, + }) + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + +func TestEvalDelete(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.Evals.Delete(context.TODO(), "eval_id") + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} diff --git a/evalrun.go b/evalrun.go new file mode 100644 index 00000000..e3cf8ce4 --- /dev/null +++ b/evalrun.go @@ -0,0 +1,3169 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package openai + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "net/http" + "net/url" + "reflect" + + "github.com/openai/openai-go/internal/apijson" + "github.com/openai/openai-go/internal/apiquery" + "github.com/openai/openai-go/internal/requestconfig" + "github.com/openai/openai-go/option" + "github.com/openai/openai-go/packages/pagination" + "github.com/openai/openai-go/packages/param" + "github.com/openai/openai-go/packages/resp" + "github.com/openai/openai-go/shared" + "github.com/openai/openai-go/shared/constant" + "github.com/tidwall/gjson" +) + +// EvalRunService contains methods and other services that help with interacting +// with the openai API. +// +// Note, unlike clients, this service does not read variables from the environment +// automatically. You should not instantiate this service directly, and instead use +// the [NewEvalRunService] method instead. +type EvalRunService struct { + Options []option.RequestOption + OutputItems EvalRunOutputItemService +} + +// NewEvalRunService generates a new service that applies the given options to each +// request. These options are applied after the parent client's options (if there +// is one), and before any request-specific options. +func NewEvalRunService(opts ...option.RequestOption) (r EvalRunService) { + r = EvalRunService{} + r.Options = opts + r.OutputItems = NewEvalRunOutputItemService(opts...) + return +} + +// Create a new evaluation run. This is the endpoint that will kick off grading. +func (r *EvalRunService) New(ctx context.Context, evalID string, body EvalRunNewParams, opts ...option.RequestOption) (res *EvalRunNewResponse, err error) { + opts = append(r.Options[:], opts...) + if evalID == "" { + err = errors.New("missing required eval_id parameter") + return + } + path := fmt.Sprintf("evals/%s/runs", evalID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) + return +} + +// Get an evaluation run by ID. +func (r *EvalRunService) Get(ctx context.Context, evalID string, runID string, opts ...option.RequestOption) (res *EvalRunGetResponse, err error) { + opts = append(r.Options[:], opts...) + if evalID == "" { + err = errors.New("missing required eval_id parameter") + return + } + if runID == "" { + err = errors.New("missing required run_id parameter") + return + } + path := fmt.Sprintf("evals/%s/runs/%s", evalID, runID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) + return +} + +// Get a list of runs for an evaluation. +func (r *EvalRunService) List(ctx context.Context, evalID string, query EvalRunListParams, opts ...option.RequestOption) (res *pagination.CursorPage[EvalRunListResponse], err error) { + var raw *http.Response + opts = append(r.Options[:], opts...) + opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) + if evalID == "" { + err = errors.New("missing required eval_id parameter") + return + } + path := fmt.Sprintf("evals/%s/runs", evalID) + cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...) + if err != nil { + return nil, err + } + err = cfg.Execute() + if err != nil { + return nil, err + } + res.SetPageConfig(cfg, raw) + return res, nil +} + +// Get a list of runs for an evaluation. +func (r *EvalRunService) ListAutoPaging(ctx context.Context, evalID string, query EvalRunListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[EvalRunListResponse] { + return pagination.NewCursorPageAutoPager(r.List(ctx, evalID, query, opts...)) +} + +// Delete an eval run. +func (r *EvalRunService) Delete(ctx context.Context, evalID string, runID string, opts ...option.RequestOption) (res *EvalRunDeleteResponse, err error) { + opts = append(r.Options[:], opts...) + if evalID == "" { + err = errors.New("missing required eval_id parameter") + return + } + if runID == "" { + err = errors.New("missing required run_id parameter") + return + } + path := fmt.Sprintf("evals/%s/runs/%s", evalID, runID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...) + return +} + +// Cancel an ongoing evaluation run. +func (r *EvalRunService) Cancel(ctx context.Context, evalID string, runID string, opts ...option.RequestOption) (res *EvalRunCancelResponse, err error) { + opts = append(r.Options[:], opts...) + if evalID == "" { + err = errors.New("missing required eval_id parameter") + return + } + if runID == "" { + err = errors.New("missing required run_id parameter") + return + } + path := fmt.Sprintf("evals/%s/runs/%s", evalID, runID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...) + return +} + +// A CompletionsRunDataSource object describing a model sampling configuration. +type CreateEvalCompletionsRunDataSource struct { + InputMessages CreateEvalCompletionsRunDataSourceInputMessagesUnion `json:"input_messages,required"` + // The name of the model to use for generating completions (e.g. "o3-mini"). + Model string `json:"model,required"` + // A StoredCompletionsRunDataSource configuration describing a set of filters + Source CreateEvalCompletionsRunDataSourceSourceUnion `json:"source,required"` + // The type of run data source. Always `completions`. + // + // Any of "completions". + Type CreateEvalCompletionsRunDataSourceType `json:"type,required"` + SamplingParams CreateEvalCompletionsRunDataSourceSamplingParams `json:"sampling_params"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + InputMessages resp.Field + Model resp.Field + Source resp.Field + Type resp.Field + SamplingParams resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r CreateEvalCompletionsRunDataSource) RawJSON() string { return r.JSON.raw } +func (r *CreateEvalCompletionsRunDataSource) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// ToParam converts this CreateEvalCompletionsRunDataSource to a +// CreateEvalCompletionsRunDataSourceParam. +// +// Warning: the fields of the param type will not be present. ToParam should only +// be used at the last possible moment before sending a request. Test for this with +// CreateEvalCompletionsRunDataSourceParam.IsOverridden() +func (r CreateEvalCompletionsRunDataSource) ToParam() CreateEvalCompletionsRunDataSourceParam { + return param.OverrideObj[CreateEvalCompletionsRunDataSourceParam](r.RawJSON()) +} + +// CreateEvalCompletionsRunDataSourceInputMessagesUnion contains all possible +// properties and values from +// [CreateEvalCompletionsRunDataSourceInputMessagesTemplate], +// [CreateEvalCompletionsRunDataSourceInputMessagesItemReference]. +// +// Use the [CreateEvalCompletionsRunDataSourceInputMessagesUnion.AsAny] method to +// switch on the variant. +// +// Use the methods beginning with 'As' to cast the union to one of its variants. +type CreateEvalCompletionsRunDataSourceInputMessagesUnion struct { + // This field is from variant + // [CreateEvalCompletionsRunDataSourceInputMessagesTemplate]. + Template []CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnion `json:"template"` + // Any of "template", "item_reference". + Type string `json:"type"` + // This field is from variant + // [CreateEvalCompletionsRunDataSourceInputMessagesItemReference]. + ItemReference string `json:"item_reference"` + JSON struct { + Template resp.Field + Type resp.Field + ItemReference resp.Field + raw string + } `json:"-"` +} + +// anyCreateEvalCompletionsRunDataSourceInputMessages is implemented by each +// variant of [CreateEvalCompletionsRunDataSourceInputMessagesUnion] to add type +// safety for the return type of +// [CreateEvalCompletionsRunDataSourceInputMessagesUnion.AsAny] +type anyCreateEvalCompletionsRunDataSourceInputMessages interface { + implCreateEvalCompletionsRunDataSourceInputMessagesUnion() +} + +func (CreateEvalCompletionsRunDataSourceInputMessagesTemplate) implCreateEvalCompletionsRunDataSourceInputMessagesUnion() { +} +func (CreateEvalCompletionsRunDataSourceInputMessagesItemReference) implCreateEvalCompletionsRunDataSourceInputMessagesUnion() { +} + +// Use the following switch statement to find the correct variant +// +// switch variant := CreateEvalCompletionsRunDataSourceInputMessagesUnion.AsAny().(type) { +// case CreateEvalCompletionsRunDataSourceInputMessagesTemplate: +// case CreateEvalCompletionsRunDataSourceInputMessagesItemReference: +// default: +// fmt.Errorf("no variant present") +// } +func (u CreateEvalCompletionsRunDataSourceInputMessagesUnion) AsAny() anyCreateEvalCompletionsRunDataSourceInputMessages { + switch u.Type { + case "template": + return u.AsTemplate() + case "item_reference": + return u.AsItemReference() + } + return nil +} + +func (u CreateEvalCompletionsRunDataSourceInputMessagesUnion) AsTemplate() (v CreateEvalCompletionsRunDataSourceInputMessagesTemplate) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u CreateEvalCompletionsRunDataSourceInputMessagesUnion) AsItemReference() (v CreateEvalCompletionsRunDataSourceInputMessagesItemReference) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +// Returns the unmodified JSON received from the API +func (u CreateEvalCompletionsRunDataSourceInputMessagesUnion) RawJSON() string { return u.JSON.raw } + +func (r *CreateEvalCompletionsRunDataSourceInputMessagesUnion) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type CreateEvalCompletionsRunDataSourceInputMessagesTemplate struct { + // A list of chat messages forming the prompt or context. May include variable + // references to the "item" namespace, ie {{item.name}}. + Template []CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnion `json:"template,required"` + // The type of input messages. Always `template`. + Type constant.Template `json:"type,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Template resp.Field + Type resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r CreateEvalCompletionsRunDataSourceInputMessagesTemplate) RawJSON() string { return r.JSON.raw } +func (r *CreateEvalCompletionsRunDataSourceInputMessagesTemplate) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnion contains +// all possible properties and values from +// [CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateChatMessage], +// [CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessage], +// [CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessage]. +// +// Use the methods beginning with 'As' to cast the union to one of its variants. +type CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnion struct { + // This field is a union of [string], + // [CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageContent], + // [CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageContent] + Content CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnionContent `json:"content"` + Role string `json:"role"` + Type string `json:"type"` + JSON struct { + Content resp.Field + Role resp.Field + Type resp.Field + raw string + } `json:"-"` +} + +func (u CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnion) AsChatMessage() (v CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateChatMessage) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnion) AsInputMessage() (v CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessage) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnion) AsOutputMessage() (v CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessage) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +// Returns the unmodified JSON received from the API +func (u CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnion) RawJSON() string { + return u.JSON.raw +} + +func (r *CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnion) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnionContent is +// an implicit subunion of +// [CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnion]. +// CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnionContent +// provides convenient access to the sub-properties of the union. +// +// For type safety it is recommended to directly use a variant of the +// [CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnion]. +// +// If the underlying value is not a json object, one of the following properties +// will be valid: OfString] +type CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnionContent struct { + // This field will be present if the value is a [string] instead of an object. + OfString string `json:",inline"` + Text string `json:"text"` + Type string `json:"type"` + JSON struct { + OfString resp.Field + Text resp.Field + Type resp.Field + raw string + } `json:"-"` +} + +func (r *CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnionContent) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateChatMessage struct { + // The content of the message. + Content string `json:"content,required"` + // The role of the message (e.g. "system", "assistant", "user"). + Role string `json:"role,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Content resp.Field + Role resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateChatMessage) RawJSON() string { + return r.JSON.raw +} +func (r *CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateChatMessage) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessage struct { + Content CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageContent `json:"content,required"` + // The role of the message. One of `user`, `system`, or `developer`. + // + // Any of "user", "system", "developer". + Role string `json:"role,required"` + // The type of item, which is always `message`. + // + // Any of "message". + Type string `json:"type,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Content resp.Field + Role resp.Field + Type resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessage) RawJSON() string { + return r.JSON.raw +} +func (r *CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessage) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageContent struct { + // The text content. + Text string `json:"text,required"` + // The type of content, which is always `input_text`. + // + // Any of "input_text". + Type string `json:"type,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Text resp.Field + Type resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageContent) RawJSON() string { + return r.JSON.raw +} +func (r *CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageContent) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessage struct { + Content CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageContent `json:"content,required"` + // The role of the message. Must be `assistant` for output. + // + // Any of "assistant". + Role string `json:"role,required"` + // The type of item, which is always `message`. + // + // Any of "message". + Type string `json:"type,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Content resp.Field + Role resp.Field + Type resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessage) RawJSON() string { + return r.JSON.raw +} +func (r *CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessage) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageContent struct { + // The text content. + Text string `json:"text,required"` + // The type of content, which is always `output_text`. + // + // Any of "output_text". + Type string `json:"type,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Text resp.Field + Type resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageContent) RawJSON() string { + return r.JSON.raw +} +func (r *CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageContent) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type CreateEvalCompletionsRunDataSourceInputMessagesItemReference struct { + // A reference to a variable in the "item" namespace. Ie, "item.name" + ItemReference string `json:"item_reference,required"` + // The type of input messages. Always `item_reference`. + Type constant.ItemReference `json:"type,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + ItemReference resp.Field + Type resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r CreateEvalCompletionsRunDataSourceInputMessagesItemReference) RawJSON() string { + return r.JSON.raw +} +func (r *CreateEvalCompletionsRunDataSourceInputMessagesItemReference) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// CreateEvalCompletionsRunDataSourceSourceUnion contains all possible properties +// and values from [CreateEvalCompletionsRunDataSourceSourceFileContent], +// [CreateEvalCompletionsRunDataSourceSourceFileID], +// [CreateEvalCompletionsRunDataSourceSourceStoredCompletions]. +// +// Use the [CreateEvalCompletionsRunDataSourceSourceUnion.AsAny] method to switch +// on the variant. +// +// Use the methods beginning with 'As' to cast the union to one of its variants. +type CreateEvalCompletionsRunDataSourceSourceUnion struct { + // This field is from variant + // [CreateEvalCompletionsRunDataSourceSourceFileContent]. + Content []CreateEvalCompletionsRunDataSourceSourceFileContentContent `json:"content"` + // Any of "file_content", "file_id", "stored_completions". + Type string `json:"type"` + // This field is from variant [CreateEvalCompletionsRunDataSourceSourceFileID]. + ID string `json:"id"` + // This field is from variant + // [CreateEvalCompletionsRunDataSourceSourceStoredCompletions]. + CreatedAfter int64 `json:"created_after"` + // This field is from variant + // [CreateEvalCompletionsRunDataSourceSourceStoredCompletions]. + CreatedBefore int64 `json:"created_before"` + // This field is from variant + // [CreateEvalCompletionsRunDataSourceSourceStoredCompletions]. + Limit int64 `json:"limit"` + // This field is from variant + // [CreateEvalCompletionsRunDataSourceSourceStoredCompletions]. + Metadata shared.Metadata `json:"metadata"` + // This field is from variant + // [CreateEvalCompletionsRunDataSourceSourceStoredCompletions]. + Model string `json:"model"` + JSON struct { + Content resp.Field + Type resp.Field + ID resp.Field + CreatedAfter resp.Field + CreatedBefore resp.Field + Limit resp.Field + Metadata resp.Field + Model resp.Field + raw string + } `json:"-"` +} + +// anyCreateEvalCompletionsRunDataSourceSource is implemented by each variant of +// [CreateEvalCompletionsRunDataSourceSourceUnion] to add type safety for the +// return type of [CreateEvalCompletionsRunDataSourceSourceUnion.AsAny] +type anyCreateEvalCompletionsRunDataSourceSource interface { + implCreateEvalCompletionsRunDataSourceSourceUnion() +} + +func (CreateEvalCompletionsRunDataSourceSourceFileContent) implCreateEvalCompletionsRunDataSourceSourceUnion() { +} +func (CreateEvalCompletionsRunDataSourceSourceFileID) implCreateEvalCompletionsRunDataSourceSourceUnion() { +} +func (CreateEvalCompletionsRunDataSourceSourceStoredCompletions) implCreateEvalCompletionsRunDataSourceSourceUnion() { +} + +// Use the following switch statement to find the correct variant +// +// switch variant := CreateEvalCompletionsRunDataSourceSourceUnion.AsAny().(type) { +// case CreateEvalCompletionsRunDataSourceSourceFileContent: +// case CreateEvalCompletionsRunDataSourceSourceFileID: +// case CreateEvalCompletionsRunDataSourceSourceStoredCompletions: +// default: +// fmt.Errorf("no variant present") +// } +func (u CreateEvalCompletionsRunDataSourceSourceUnion) AsAny() anyCreateEvalCompletionsRunDataSourceSource { + switch u.Type { + case "file_content": + return u.AsFileContent() + case "file_id": + return u.AsFileID() + case "stored_completions": + return u.AsStoredCompletions() + } + return nil +} + +func (u CreateEvalCompletionsRunDataSourceSourceUnion) AsFileContent() (v CreateEvalCompletionsRunDataSourceSourceFileContent) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u CreateEvalCompletionsRunDataSourceSourceUnion) AsFileID() (v CreateEvalCompletionsRunDataSourceSourceFileID) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u CreateEvalCompletionsRunDataSourceSourceUnion) AsStoredCompletions() (v CreateEvalCompletionsRunDataSourceSourceStoredCompletions) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +// Returns the unmodified JSON received from the API +func (u CreateEvalCompletionsRunDataSourceSourceUnion) RawJSON() string { return u.JSON.raw } + +func (r *CreateEvalCompletionsRunDataSourceSourceUnion) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type CreateEvalCompletionsRunDataSourceSourceFileContent struct { + // The content of the jsonl file. + Content []CreateEvalCompletionsRunDataSourceSourceFileContentContent `json:"content,required"` + // The type of jsonl source. Always `file_content`. + Type constant.FileContent `json:"type,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Content resp.Field + Type resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r CreateEvalCompletionsRunDataSourceSourceFileContent) RawJSON() string { return r.JSON.raw } +func (r *CreateEvalCompletionsRunDataSourceSourceFileContent) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type CreateEvalCompletionsRunDataSourceSourceFileContentContent struct { + Item map[string]interface{} `json:"item,required"` + Sample map[string]interface{} `json:"sample"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Item resp.Field + Sample resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r CreateEvalCompletionsRunDataSourceSourceFileContentContent) RawJSON() string { + return r.JSON.raw +} +func (r *CreateEvalCompletionsRunDataSourceSourceFileContentContent) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type CreateEvalCompletionsRunDataSourceSourceFileID struct { + // The identifier of the file. + ID string `json:"id,required"` + // The type of jsonl source. Always `file_id`. + Type constant.FileID `json:"type,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + ID resp.Field + Type resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r CreateEvalCompletionsRunDataSourceSourceFileID) RawJSON() string { return r.JSON.raw } +func (r *CreateEvalCompletionsRunDataSourceSourceFileID) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// A StoredCompletionsRunDataSource configuration describing a set of filters +type CreateEvalCompletionsRunDataSourceSourceStoredCompletions struct { + // An optional Unix timestamp to filter items created after this time. + CreatedAfter int64 `json:"created_after,required"` + // An optional Unix timestamp to filter items created before this time. + CreatedBefore int64 `json:"created_before,required"` + // An optional maximum number of items to return. + Limit int64 `json:"limit,required"` + // Set of 16 key-value pairs that can be attached to an object. This can be useful + // for storing additional information about the object in a structured format, and + // querying for objects via API or the dashboard. + // + // Keys are strings with a maximum length of 64 characters. Values are strings with + // a maximum length of 512 characters. + Metadata shared.Metadata `json:"metadata,required"` + // An optional model to filter by (e.g., 'gpt-4o'). + Model string `json:"model,required"` + // The type of source. Always `stored_completions`. + Type constant.StoredCompletions `json:"type,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + CreatedAfter resp.Field + CreatedBefore resp.Field + Limit resp.Field + Metadata resp.Field + Model resp.Field + Type resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r CreateEvalCompletionsRunDataSourceSourceStoredCompletions) RawJSON() string { + return r.JSON.raw +} +func (r *CreateEvalCompletionsRunDataSourceSourceStoredCompletions) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// The type of run data source. Always `completions`. +type CreateEvalCompletionsRunDataSourceType string + +const ( + CreateEvalCompletionsRunDataSourceTypeCompletions CreateEvalCompletionsRunDataSourceType = "completions" +) + +type CreateEvalCompletionsRunDataSourceSamplingParams struct { + // The maximum number of tokens in the generated output. + MaxCompletionTokens int64 `json:"max_completion_tokens"` + // A seed value to initialize the randomness, during sampling. + Seed int64 `json:"seed"` + // A higher temperature increases randomness in the outputs. + Temperature float64 `json:"temperature"` + // An alternative to temperature for nucleus sampling; 1.0 includes all tokens. + TopP float64 `json:"top_p"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + MaxCompletionTokens resp.Field + Seed resp.Field + Temperature resp.Field + TopP resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r CreateEvalCompletionsRunDataSourceSamplingParams) RawJSON() string { return r.JSON.raw } +func (r *CreateEvalCompletionsRunDataSourceSamplingParams) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// A CompletionsRunDataSource object describing a model sampling configuration. +// +// The properties InputMessages, Model, Source, Type are required. +type CreateEvalCompletionsRunDataSourceParam struct { + InputMessages CreateEvalCompletionsRunDataSourceInputMessagesUnionParam `json:"input_messages,omitzero,required"` + // The name of the model to use for generating completions (e.g. "o3-mini"). + Model string `json:"model,required"` + // A StoredCompletionsRunDataSource configuration describing a set of filters + Source CreateEvalCompletionsRunDataSourceSourceUnionParam `json:"source,omitzero,required"` + // The type of run data source. Always `completions`. + // + // Any of "completions". + Type CreateEvalCompletionsRunDataSourceType `json:"type,omitzero,required"` + SamplingParams CreateEvalCompletionsRunDataSourceSamplingParamsParam `json:"sampling_params,omitzero"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f CreateEvalCompletionsRunDataSourceParam) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r CreateEvalCompletionsRunDataSourceParam) MarshalJSON() (data []byte, err error) { + type shadow CreateEvalCompletionsRunDataSourceParam + return param.MarshalObject(r, (*shadow)(&r)) +} + +// Only one field can be non-zero. +// +// Use [param.IsOmitted] to confirm if a field is set. +type CreateEvalCompletionsRunDataSourceInputMessagesUnionParam struct { + OfTemplate *CreateEvalCompletionsRunDataSourceInputMessagesTemplateParam `json:",omitzero,inline"` + OfItemReference *CreateEvalCompletionsRunDataSourceInputMessagesItemReferenceParam `json:",omitzero,inline"` + paramUnion +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (u CreateEvalCompletionsRunDataSourceInputMessagesUnionParam) IsPresent() bool { + return !param.IsOmitted(u) && !u.IsNull() +} +func (u CreateEvalCompletionsRunDataSourceInputMessagesUnionParam) MarshalJSON() ([]byte, error) { + return param.MarshalUnion[CreateEvalCompletionsRunDataSourceInputMessagesUnionParam](u.OfTemplate, u.OfItemReference) +} + +func (u *CreateEvalCompletionsRunDataSourceInputMessagesUnionParam) asAny() any { + if !param.IsOmitted(u.OfTemplate) { + return u.OfTemplate + } else if !param.IsOmitted(u.OfItemReference) { + return u.OfItemReference + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u CreateEvalCompletionsRunDataSourceInputMessagesUnionParam) GetTemplate() []CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnionParam { + if vt := u.OfTemplate; vt != nil { + return vt.Template + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u CreateEvalCompletionsRunDataSourceInputMessagesUnionParam) GetItemReference() *string { + if vt := u.OfItemReference; vt != nil { + return &vt.ItemReference + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u CreateEvalCompletionsRunDataSourceInputMessagesUnionParam) GetType() *string { + if vt := u.OfTemplate; vt != nil { + return (*string)(&vt.Type) + } else if vt := u.OfItemReference; vt != nil { + return (*string)(&vt.Type) + } + return nil +} + +func init() { + apijson.RegisterUnion[CreateEvalCompletionsRunDataSourceInputMessagesUnionParam]( + "type", + apijson.UnionVariant{ + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(CreateEvalCompletionsRunDataSourceInputMessagesTemplateParam{}), + DiscriminatorValue: "template", + }, + apijson.UnionVariant{ + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(CreateEvalCompletionsRunDataSourceInputMessagesItemReferenceParam{}), + DiscriminatorValue: "item_reference", + }, + ) +} + +// The properties Template, Type are required. +type CreateEvalCompletionsRunDataSourceInputMessagesTemplateParam struct { + // A list of chat messages forming the prompt or context. May include variable + // references to the "item" namespace, ie {{item.name}}. + Template []CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnionParam `json:"template,omitzero,required"` + // The type of input messages. Always `template`. + // + // This field can be elided, and will marshal its zero value as "template". + Type constant.Template `json:"type,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f CreateEvalCompletionsRunDataSourceInputMessagesTemplateParam) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r CreateEvalCompletionsRunDataSourceInputMessagesTemplateParam) MarshalJSON() (data []byte, err error) { + type shadow CreateEvalCompletionsRunDataSourceInputMessagesTemplateParam + return param.MarshalObject(r, (*shadow)(&r)) +} + +// Only one field can be non-zero. +// +// Use [param.IsOmitted] to confirm if a field is set. +type CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnionParam struct { + OfChatMessage *CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateChatMessageParam `json:",omitzero,inline"` + OfInputMessage *CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageParam `json:",omitzero,inline"` + OfOutputMessage *CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageParam `json:",omitzero,inline"` + paramUnion +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (u CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnionParam) IsPresent() bool { + return !param.IsOmitted(u) && !u.IsNull() +} +func (u CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnionParam) MarshalJSON() ([]byte, error) { + return param.MarshalUnion[CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnionParam](u.OfChatMessage, u.OfInputMessage, u.OfOutputMessage) +} + +func (u *CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnionParam) asAny() any { + if !param.IsOmitted(u.OfChatMessage) { + return u.OfChatMessage + } else if !param.IsOmitted(u.OfInputMessage) { + return u.OfInputMessage + } else if !param.IsOmitted(u.OfOutputMessage) { + return u.OfOutputMessage + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnionParam) GetRole() *string { + if vt := u.OfChatMessage; vt != nil { + return (*string)(&vt.Role) + } else if vt := u.OfInputMessage; vt != nil { + return (*string)(&vt.Role) + } else if vt := u.OfOutputMessage; vt != nil { + return (*string)(&vt.Role) + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnionParam) GetType() *string { + if vt := u.OfInputMessage; vt != nil { + return (*string)(&vt.Type) + } else if vt := u.OfOutputMessage; vt != nil { + return (*string)(&vt.Type) + } + return nil +} + +// Returns a subunion which exports methods to access subproperties +// +// Or use AsAny() to get the underlying value +func (u CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnionParam) GetContent() (res createEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnionParamContent) { + if vt := u.OfChatMessage; vt != nil { + res.ofString = &vt.Content + } else if vt := u.OfInputMessage; vt != nil { + res.ofCreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageContent = &vt.Content + } else if vt := u.OfOutputMessage; vt != nil { + res.ofCreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageContent = &vt.Content + } + return +} + +// Only one field can be non-zero. +// +// Use [param.IsOmitted] to confirm if a field is set. +type createEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnionParamContent struct { + ofString *string + ofCreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageContent *CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageContentParam + ofCreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageContent *CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageContentParam +} + +// Use the following switch statement to get the type of the union: +// +// switch u.AsAny().(type) { +// case *string: +// case *openai.CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageContentParam: +// case *openai.CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageContentParam: +// default: +// fmt.Errorf("not present") +// } +func (u createEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnionParamContent) AsAny() any { + if !param.IsOmitted(u.ofString) { + return u.ofString + } else if !param.IsOmitted(u.ofCreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageContent) { + return u.ofCreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageContent + } else if !param.IsOmitted(u.ofCreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageContent) { + return u.ofCreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageContent + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u createEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnionParamContent) GetText() *string { + if vt := u.ofCreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageContent; vt != nil { + return (*string)(&vt.Text) + } else if vt := u.ofCreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageContent; vt != nil { + return (*string)(&vt.Text) + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u createEvalCompletionsRunDataSourceInputMessagesTemplateTemplateUnionParamContent) GetType() *string { + if vt := u.ofCreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageContent; vt != nil { + return (*string)(&vt.Type) + } else if vt := u.ofCreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageContent; vt != nil { + return (*string)(&vt.Type) + } + return nil +} + +// The properties Content, Role are required. +type CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateChatMessageParam struct { + // The content of the message. + Content string `json:"content,required"` + // The role of the message (e.g. "system", "assistant", "user"). + Role string `json:"role,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateChatMessageParam) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateChatMessageParam) MarshalJSON() (data []byte, err error) { + type shadow CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateChatMessageParam + return param.MarshalObject(r, (*shadow)(&r)) +} + +// The properties Content, Role, Type are required. +type CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageParam struct { + Content CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageContentParam `json:"content,omitzero,required"` + // The role of the message. One of `user`, `system`, or `developer`. + // + // Any of "user", "system", "developer". + Role string `json:"role,omitzero,required"` + // The type of item, which is always `message`. + // + // Any of "message". + Type string `json:"type,omitzero,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageParam) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageParam) MarshalJSON() (data []byte, err error) { + type shadow CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageParam + return param.MarshalObject(r, (*shadow)(&r)) +} + +func init() { + apijson.RegisterFieldValidator[CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageParam]( + "Role", false, "user", "system", "developer", + ) + apijson.RegisterFieldValidator[CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageParam]( + "Type", false, "message", + ) +} + +// The properties Text, Type are required. +type CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageContentParam struct { + // The text content. + Text string `json:"text,required"` + // The type of content, which is always `input_text`. + // + // Any of "input_text". + Type string `json:"type,omitzero,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageContentParam) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageContentParam) MarshalJSON() (data []byte, err error) { + type shadow CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageContentParam + return param.MarshalObject(r, (*shadow)(&r)) +} + +func init() { + apijson.RegisterFieldValidator[CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateInputMessageContentParam]( + "Type", false, "input_text", + ) +} + +// The properties Content, Role, Type are required. +type CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageParam struct { + Content CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageContentParam `json:"content,omitzero,required"` + // The role of the message. Must be `assistant` for output. + // + // Any of "assistant". + Role string `json:"role,omitzero,required"` + // The type of item, which is always `message`. + // + // Any of "message". + Type string `json:"type,omitzero,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageParam) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageParam) MarshalJSON() (data []byte, err error) { + type shadow CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageParam + return param.MarshalObject(r, (*shadow)(&r)) +} + +func init() { + apijson.RegisterFieldValidator[CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageParam]( + "Role", false, "assistant", + ) + apijson.RegisterFieldValidator[CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageParam]( + "Type", false, "message", + ) +} + +// The properties Text, Type are required. +type CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageContentParam struct { + // The text content. + Text string `json:"text,required"` + // The type of content, which is always `output_text`. + // + // Any of "output_text". + Type string `json:"type,omitzero,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageContentParam) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageContentParam) MarshalJSON() (data []byte, err error) { + type shadow CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageContentParam + return param.MarshalObject(r, (*shadow)(&r)) +} + +func init() { + apijson.RegisterFieldValidator[CreateEvalCompletionsRunDataSourceInputMessagesTemplateTemplateOutputMessageContentParam]( + "Type", false, "output_text", + ) +} + +// The properties ItemReference, Type are required. +type CreateEvalCompletionsRunDataSourceInputMessagesItemReferenceParam struct { + // A reference to a variable in the "item" namespace. Ie, "item.name" + ItemReference string `json:"item_reference,required"` + // The type of input messages. Always `item_reference`. + // + // This field can be elided, and will marshal its zero value as "item_reference". + Type constant.ItemReference `json:"type,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f CreateEvalCompletionsRunDataSourceInputMessagesItemReferenceParam) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r CreateEvalCompletionsRunDataSourceInputMessagesItemReferenceParam) MarshalJSON() (data []byte, err error) { + type shadow CreateEvalCompletionsRunDataSourceInputMessagesItemReferenceParam + return param.MarshalObject(r, (*shadow)(&r)) +} + +// Only one field can be non-zero. +// +// Use [param.IsOmitted] to confirm if a field is set. +type CreateEvalCompletionsRunDataSourceSourceUnionParam struct { + OfFileContent *CreateEvalCompletionsRunDataSourceSourceFileContentParam `json:",omitzero,inline"` + OfFileID *CreateEvalCompletionsRunDataSourceSourceFileIDParam `json:",omitzero,inline"` + OfStoredCompletions *CreateEvalCompletionsRunDataSourceSourceStoredCompletionsParam `json:",omitzero,inline"` + paramUnion +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (u CreateEvalCompletionsRunDataSourceSourceUnionParam) IsPresent() bool { + return !param.IsOmitted(u) && !u.IsNull() +} +func (u CreateEvalCompletionsRunDataSourceSourceUnionParam) MarshalJSON() ([]byte, error) { + return param.MarshalUnion[CreateEvalCompletionsRunDataSourceSourceUnionParam](u.OfFileContent, u.OfFileID, u.OfStoredCompletions) +} + +func (u *CreateEvalCompletionsRunDataSourceSourceUnionParam) asAny() any { + if !param.IsOmitted(u.OfFileContent) { + return u.OfFileContent + } else if !param.IsOmitted(u.OfFileID) { + return u.OfFileID + } else if !param.IsOmitted(u.OfStoredCompletions) { + return u.OfStoredCompletions + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u CreateEvalCompletionsRunDataSourceSourceUnionParam) GetContent() []CreateEvalCompletionsRunDataSourceSourceFileContentContentParam { + if vt := u.OfFileContent; vt != nil { + return vt.Content + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u CreateEvalCompletionsRunDataSourceSourceUnionParam) GetID() *string { + if vt := u.OfFileID; vt != nil { + return &vt.ID + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u CreateEvalCompletionsRunDataSourceSourceUnionParam) GetCreatedAfter() *int64 { + if vt := u.OfStoredCompletions; vt != nil && vt.CreatedAfter.IsPresent() { + return &vt.CreatedAfter.Value + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u CreateEvalCompletionsRunDataSourceSourceUnionParam) GetCreatedBefore() *int64 { + if vt := u.OfStoredCompletions; vt != nil && vt.CreatedBefore.IsPresent() { + return &vt.CreatedBefore.Value + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u CreateEvalCompletionsRunDataSourceSourceUnionParam) GetLimit() *int64 { + if vt := u.OfStoredCompletions; vt != nil && vt.Limit.IsPresent() { + return &vt.Limit.Value + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u CreateEvalCompletionsRunDataSourceSourceUnionParam) GetMetadata() shared.MetadataParam { + if vt := u.OfStoredCompletions; vt != nil { + return vt.Metadata + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u CreateEvalCompletionsRunDataSourceSourceUnionParam) GetModel() *string { + if vt := u.OfStoredCompletions; vt != nil && vt.Model.IsPresent() { + return &vt.Model.Value + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u CreateEvalCompletionsRunDataSourceSourceUnionParam) GetType() *string { + if vt := u.OfFileContent; vt != nil { + return (*string)(&vt.Type) + } else if vt := u.OfFileID; vt != nil { + return (*string)(&vt.Type) + } else if vt := u.OfStoredCompletions; vt != nil { + return (*string)(&vt.Type) + } + return nil +} + +func init() { + apijson.RegisterUnion[CreateEvalCompletionsRunDataSourceSourceUnionParam]( + "type", + apijson.UnionVariant{ + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(CreateEvalCompletionsRunDataSourceSourceFileContentParam{}), + DiscriminatorValue: "file_content", + }, + apijson.UnionVariant{ + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(CreateEvalCompletionsRunDataSourceSourceFileIDParam{}), + DiscriminatorValue: "file_id", + }, + apijson.UnionVariant{ + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(CreateEvalCompletionsRunDataSourceSourceStoredCompletionsParam{}), + DiscriminatorValue: "stored_completions", + }, + ) +} + +// The properties Content, Type are required. +type CreateEvalCompletionsRunDataSourceSourceFileContentParam struct { + // The content of the jsonl file. + Content []CreateEvalCompletionsRunDataSourceSourceFileContentContentParam `json:"content,omitzero,required"` + // The type of jsonl source. Always `file_content`. + // + // This field can be elided, and will marshal its zero value as "file_content". + Type constant.FileContent `json:"type,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f CreateEvalCompletionsRunDataSourceSourceFileContentParam) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r CreateEvalCompletionsRunDataSourceSourceFileContentParam) MarshalJSON() (data []byte, err error) { + type shadow CreateEvalCompletionsRunDataSourceSourceFileContentParam + return param.MarshalObject(r, (*shadow)(&r)) +} + +// The property Item is required. +type CreateEvalCompletionsRunDataSourceSourceFileContentContentParam struct { + Item map[string]interface{} `json:"item,omitzero,required"` + Sample map[string]interface{} `json:"sample,omitzero"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f CreateEvalCompletionsRunDataSourceSourceFileContentContentParam) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r CreateEvalCompletionsRunDataSourceSourceFileContentContentParam) MarshalJSON() (data []byte, err error) { + type shadow CreateEvalCompletionsRunDataSourceSourceFileContentContentParam + return param.MarshalObject(r, (*shadow)(&r)) +} + +// The properties ID, Type are required. +type CreateEvalCompletionsRunDataSourceSourceFileIDParam struct { + // The identifier of the file. + ID string `json:"id,required"` + // The type of jsonl source. Always `file_id`. + // + // This field can be elided, and will marshal its zero value as "file_id". + Type constant.FileID `json:"type,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f CreateEvalCompletionsRunDataSourceSourceFileIDParam) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r CreateEvalCompletionsRunDataSourceSourceFileIDParam) MarshalJSON() (data []byte, err error) { + type shadow CreateEvalCompletionsRunDataSourceSourceFileIDParam + return param.MarshalObject(r, (*shadow)(&r)) +} + +// A StoredCompletionsRunDataSource configuration describing a set of filters +// +// The properties CreatedAfter, CreatedBefore, Limit, Metadata, Model, Type are +// required. +type CreateEvalCompletionsRunDataSourceSourceStoredCompletionsParam struct { + // An optional Unix timestamp to filter items created after this time. + CreatedAfter param.Opt[int64] `json:"created_after,omitzero,required"` + // An optional Unix timestamp to filter items created before this time. + CreatedBefore param.Opt[int64] `json:"created_before,omitzero,required"` + // An optional maximum number of items to return. + Limit param.Opt[int64] `json:"limit,omitzero,required"` + // An optional model to filter by (e.g., 'gpt-4o'). + Model param.Opt[string] `json:"model,omitzero,required"` + // Set of 16 key-value pairs that can be attached to an object. This can be useful + // for storing additional information about the object in a structured format, and + // querying for objects via API or the dashboard. + // + // Keys are strings with a maximum length of 64 characters. Values are strings with + // a maximum length of 512 characters. + Metadata shared.MetadataParam `json:"metadata,omitzero,required"` + // The type of source. Always `stored_completions`. + // + // This field can be elided, and will marshal its zero value as + // "stored_completions". + Type constant.StoredCompletions `json:"type,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f CreateEvalCompletionsRunDataSourceSourceStoredCompletionsParam) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r CreateEvalCompletionsRunDataSourceSourceStoredCompletionsParam) MarshalJSON() (data []byte, err error) { + type shadow CreateEvalCompletionsRunDataSourceSourceStoredCompletionsParam + return param.MarshalObject(r, (*shadow)(&r)) +} + +type CreateEvalCompletionsRunDataSourceSamplingParamsParam struct { + // The maximum number of tokens in the generated output. + MaxCompletionTokens param.Opt[int64] `json:"max_completion_tokens,omitzero"` + // A seed value to initialize the randomness, during sampling. + Seed param.Opt[int64] `json:"seed,omitzero"` + // A higher temperature increases randomness in the outputs. + Temperature param.Opt[float64] `json:"temperature,omitzero"` + // An alternative to temperature for nucleus sampling; 1.0 includes all tokens. + TopP param.Opt[float64] `json:"top_p,omitzero"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f CreateEvalCompletionsRunDataSourceSamplingParamsParam) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r CreateEvalCompletionsRunDataSourceSamplingParamsParam) MarshalJSON() (data []byte, err error) { + type shadow CreateEvalCompletionsRunDataSourceSamplingParamsParam + return param.MarshalObject(r, (*shadow)(&r)) +} + +// A JsonlRunDataSource object with that specifies a JSONL file that matches the +// eval +type CreateEvalJSONLRunDataSource struct { + Source CreateEvalJSONLRunDataSourceSourceUnion `json:"source,required"` + // The type of data source. Always `jsonl`. + Type constant.JSONL `json:"type,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Source resp.Field + Type resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r CreateEvalJSONLRunDataSource) RawJSON() string { return r.JSON.raw } +func (r *CreateEvalJSONLRunDataSource) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// ToParam converts this CreateEvalJSONLRunDataSource to a +// CreateEvalJSONLRunDataSourceParam. +// +// Warning: the fields of the param type will not be present. ToParam should only +// be used at the last possible moment before sending a request. Test for this with +// CreateEvalJSONLRunDataSourceParam.IsOverridden() +func (r CreateEvalJSONLRunDataSource) ToParam() CreateEvalJSONLRunDataSourceParam { + return param.OverrideObj[CreateEvalJSONLRunDataSourceParam](r.RawJSON()) +} + +// CreateEvalJSONLRunDataSourceSourceUnion contains all possible properties and +// values from [CreateEvalJSONLRunDataSourceSourceFileContent], +// [CreateEvalJSONLRunDataSourceSourceFileID]. +// +// Use the [CreateEvalJSONLRunDataSourceSourceUnion.AsAny] method to switch on the +// variant. +// +// Use the methods beginning with 'As' to cast the union to one of its variants. +type CreateEvalJSONLRunDataSourceSourceUnion struct { + // This field is from variant [CreateEvalJSONLRunDataSourceSourceFileContent]. + Content []CreateEvalJSONLRunDataSourceSourceFileContentContent `json:"content"` + // Any of "file_content", "file_id". + Type string `json:"type"` + // This field is from variant [CreateEvalJSONLRunDataSourceSourceFileID]. + ID string `json:"id"` + JSON struct { + Content resp.Field + Type resp.Field + ID resp.Field + raw string + } `json:"-"` +} + +// anyCreateEvalJSONLRunDataSourceSource is implemented by each variant of +// [CreateEvalJSONLRunDataSourceSourceUnion] to add type safety for the return type +// of [CreateEvalJSONLRunDataSourceSourceUnion.AsAny] +type anyCreateEvalJSONLRunDataSourceSource interface { + implCreateEvalJSONLRunDataSourceSourceUnion() +} + +func (CreateEvalJSONLRunDataSourceSourceFileContent) implCreateEvalJSONLRunDataSourceSourceUnion() {} +func (CreateEvalJSONLRunDataSourceSourceFileID) implCreateEvalJSONLRunDataSourceSourceUnion() {} + +// Use the following switch statement to find the correct variant +// +// switch variant := CreateEvalJSONLRunDataSourceSourceUnion.AsAny().(type) { +// case CreateEvalJSONLRunDataSourceSourceFileContent: +// case CreateEvalJSONLRunDataSourceSourceFileID: +// default: +// fmt.Errorf("no variant present") +// } +func (u CreateEvalJSONLRunDataSourceSourceUnion) AsAny() anyCreateEvalJSONLRunDataSourceSource { + switch u.Type { + case "file_content": + return u.AsFileContent() + case "file_id": + return u.AsFileID() + } + return nil +} + +func (u CreateEvalJSONLRunDataSourceSourceUnion) AsFileContent() (v CreateEvalJSONLRunDataSourceSourceFileContent) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u CreateEvalJSONLRunDataSourceSourceUnion) AsFileID() (v CreateEvalJSONLRunDataSourceSourceFileID) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +// Returns the unmodified JSON received from the API +func (u CreateEvalJSONLRunDataSourceSourceUnion) RawJSON() string { return u.JSON.raw } + +func (r *CreateEvalJSONLRunDataSourceSourceUnion) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type CreateEvalJSONLRunDataSourceSourceFileContent struct { + // The content of the jsonl file. + Content []CreateEvalJSONLRunDataSourceSourceFileContentContent `json:"content,required"` + // The type of jsonl source. Always `file_content`. + Type constant.FileContent `json:"type,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Content resp.Field + Type resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r CreateEvalJSONLRunDataSourceSourceFileContent) RawJSON() string { return r.JSON.raw } +func (r *CreateEvalJSONLRunDataSourceSourceFileContent) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type CreateEvalJSONLRunDataSourceSourceFileContentContent struct { + Item map[string]interface{} `json:"item,required"` + Sample map[string]interface{} `json:"sample"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Item resp.Field + Sample resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r CreateEvalJSONLRunDataSourceSourceFileContentContent) RawJSON() string { return r.JSON.raw } +func (r *CreateEvalJSONLRunDataSourceSourceFileContentContent) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type CreateEvalJSONLRunDataSourceSourceFileID struct { + // The identifier of the file. + ID string `json:"id,required"` + // The type of jsonl source. Always `file_id`. + Type constant.FileID `json:"type,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + ID resp.Field + Type resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r CreateEvalJSONLRunDataSourceSourceFileID) RawJSON() string { return r.JSON.raw } +func (r *CreateEvalJSONLRunDataSourceSourceFileID) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// A JsonlRunDataSource object with that specifies a JSONL file that matches the +// eval +// +// The properties Source, Type are required. +type CreateEvalJSONLRunDataSourceParam struct { + Source CreateEvalJSONLRunDataSourceSourceUnionParam `json:"source,omitzero,required"` + // The type of data source. Always `jsonl`. + // + // This field can be elided, and will marshal its zero value as "jsonl". + Type constant.JSONL `json:"type,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f CreateEvalJSONLRunDataSourceParam) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r CreateEvalJSONLRunDataSourceParam) MarshalJSON() (data []byte, err error) { + type shadow CreateEvalJSONLRunDataSourceParam + return param.MarshalObject(r, (*shadow)(&r)) +} + +// Only one field can be non-zero. +// +// Use [param.IsOmitted] to confirm if a field is set. +type CreateEvalJSONLRunDataSourceSourceUnionParam struct { + OfFileContent *CreateEvalJSONLRunDataSourceSourceFileContentParam `json:",omitzero,inline"` + OfFileID *CreateEvalJSONLRunDataSourceSourceFileIDParam `json:",omitzero,inline"` + paramUnion +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (u CreateEvalJSONLRunDataSourceSourceUnionParam) IsPresent() bool { + return !param.IsOmitted(u) && !u.IsNull() +} +func (u CreateEvalJSONLRunDataSourceSourceUnionParam) MarshalJSON() ([]byte, error) { + return param.MarshalUnion[CreateEvalJSONLRunDataSourceSourceUnionParam](u.OfFileContent, u.OfFileID) +} + +func (u *CreateEvalJSONLRunDataSourceSourceUnionParam) asAny() any { + if !param.IsOmitted(u.OfFileContent) { + return u.OfFileContent + } else if !param.IsOmitted(u.OfFileID) { + return u.OfFileID + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u CreateEvalJSONLRunDataSourceSourceUnionParam) GetContent() []CreateEvalJSONLRunDataSourceSourceFileContentContentParam { + if vt := u.OfFileContent; vt != nil { + return vt.Content + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u CreateEvalJSONLRunDataSourceSourceUnionParam) GetID() *string { + if vt := u.OfFileID; vt != nil { + return &vt.ID + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u CreateEvalJSONLRunDataSourceSourceUnionParam) GetType() *string { + if vt := u.OfFileContent; vt != nil { + return (*string)(&vt.Type) + } else if vt := u.OfFileID; vt != nil { + return (*string)(&vt.Type) + } + return nil +} + +func init() { + apijson.RegisterUnion[CreateEvalJSONLRunDataSourceSourceUnionParam]( + "type", + apijson.UnionVariant{ + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(CreateEvalJSONLRunDataSourceSourceFileContentParam{}), + DiscriminatorValue: "file_content", + }, + apijson.UnionVariant{ + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(CreateEvalJSONLRunDataSourceSourceFileIDParam{}), + DiscriminatorValue: "file_id", + }, + ) +} + +// The properties Content, Type are required. +type CreateEvalJSONLRunDataSourceSourceFileContentParam struct { + // The content of the jsonl file. + Content []CreateEvalJSONLRunDataSourceSourceFileContentContentParam `json:"content,omitzero,required"` + // The type of jsonl source. Always `file_content`. + // + // This field can be elided, and will marshal its zero value as "file_content". + Type constant.FileContent `json:"type,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f CreateEvalJSONLRunDataSourceSourceFileContentParam) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r CreateEvalJSONLRunDataSourceSourceFileContentParam) MarshalJSON() (data []byte, err error) { + type shadow CreateEvalJSONLRunDataSourceSourceFileContentParam + return param.MarshalObject(r, (*shadow)(&r)) +} + +// The property Item is required. +type CreateEvalJSONLRunDataSourceSourceFileContentContentParam struct { + Item map[string]interface{} `json:"item,omitzero,required"` + Sample map[string]interface{} `json:"sample,omitzero"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f CreateEvalJSONLRunDataSourceSourceFileContentContentParam) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r CreateEvalJSONLRunDataSourceSourceFileContentContentParam) MarshalJSON() (data []byte, err error) { + type shadow CreateEvalJSONLRunDataSourceSourceFileContentContentParam + return param.MarshalObject(r, (*shadow)(&r)) +} + +// The properties ID, Type are required. +type CreateEvalJSONLRunDataSourceSourceFileIDParam struct { + // The identifier of the file. + ID string `json:"id,required"` + // The type of jsonl source. Always `file_id`. + // + // This field can be elided, and will marshal its zero value as "file_id". + Type constant.FileID `json:"type,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f CreateEvalJSONLRunDataSourceSourceFileIDParam) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} +func (r CreateEvalJSONLRunDataSourceSourceFileIDParam) MarshalJSON() (data []byte, err error) { + type shadow CreateEvalJSONLRunDataSourceSourceFileIDParam + return param.MarshalObject(r, (*shadow)(&r)) +} + +// An object representing an error response from the Eval API. +type EvalAPIError struct { + // The error code. + Code string `json:"code,required"` + // The error message. + Message string `json:"message,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Code resp.Field + Message resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalAPIError) RawJSON() string { return r.JSON.raw } +func (r *EvalAPIError) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// A schema representing an evaluation run. +type EvalRunNewResponse struct { + // Unique identifier for the evaluation run. + ID string `json:"id,required"` + // Unix timestamp (in seconds) when the evaluation run was created. + CreatedAt int64 `json:"created_at,required"` + // Information about the run's data source. + DataSource EvalRunNewResponseDataSourceUnion `json:"data_source,required"` + // An object representing an error response from the Eval API. + Error EvalAPIError `json:"error,required"` + // The identifier of the associated evaluation. + EvalID string `json:"eval_id,required"` + // Set of 16 key-value pairs that can be attached to an object. This can be useful + // for storing additional information about the object in a structured format, and + // querying for objects via API or the dashboard. + // + // Keys are strings with a maximum length of 64 characters. Values are strings with + // a maximum length of 512 characters. + Metadata shared.Metadata `json:"metadata,required"` + // The model that is evaluated, if applicable. + Model string `json:"model,required"` + // The name of the evaluation run. + Name string `json:"name,required"` + // The type of the object. Always "eval.run". + Object constant.EvalRun `json:"object,required"` + // Usage statistics for each model during the evaluation run. + PerModelUsage []EvalRunNewResponsePerModelUsage `json:"per_model_usage,required"` + // Results per testing criteria applied during the evaluation run. + PerTestingCriteriaResults []EvalRunNewResponsePerTestingCriteriaResult `json:"per_testing_criteria_results,required"` + // The URL to the rendered evaluation run report on the UI dashboard. + ReportURL string `json:"report_url,required"` + // Counters summarizing the outcomes of the evaluation run. + ResultCounts EvalRunNewResponseResultCounts `json:"result_counts,required"` + // The status of the evaluation run. + Status string `json:"status,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + ID resp.Field + CreatedAt resp.Field + DataSource resp.Field + Error resp.Field + EvalID resp.Field + Metadata resp.Field + Model resp.Field + Name resp.Field + Object resp.Field + PerModelUsage resp.Field + PerTestingCriteriaResults resp.Field + ReportURL resp.Field + ResultCounts resp.Field + Status resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunNewResponse) RawJSON() string { return r.JSON.raw } +func (r *EvalRunNewResponse) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalRunNewResponseDataSourceUnion contains all possible properties and values +// from [CreateEvalJSONLRunDataSource], [CreateEvalCompletionsRunDataSource]. +// +// Use the [EvalRunNewResponseDataSourceUnion.AsAny] method to switch on the +// variant. +// +// Use the methods beginning with 'As' to cast the union to one of its variants. +type EvalRunNewResponseDataSourceUnion struct { + // This field is a union of [CreateEvalJSONLRunDataSourceSourceUnion], + // [CreateEvalCompletionsRunDataSourceSourceUnion] + Source EvalRunNewResponseDataSourceUnionSource `json:"source"` + // Any of "jsonl", "completions". + Type string `json:"type"` + // This field is from variant [CreateEvalCompletionsRunDataSource]. + InputMessages CreateEvalCompletionsRunDataSourceInputMessagesUnion `json:"input_messages"` + // This field is from variant [CreateEvalCompletionsRunDataSource]. + Model string `json:"model"` + // This field is from variant [CreateEvalCompletionsRunDataSource]. + SamplingParams CreateEvalCompletionsRunDataSourceSamplingParams `json:"sampling_params"` + JSON struct { + Source resp.Field + Type resp.Field + InputMessages resp.Field + Model resp.Field + SamplingParams resp.Field + raw string + } `json:"-"` +} + +// anyEvalRunNewResponseDataSource is implemented by each variant of +// [EvalRunNewResponseDataSourceUnion] to add type safety for the return type of +// [EvalRunNewResponseDataSourceUnion.AsAny] +type anyEvalRunNewResponseDataSource interface { + implEvalRunNewResponseDataSourceUnion() +} + +func (CreateEvalJSONLRunDataSource) implEvalRunNewResponseDataSourceUnion() {} +func (CreateEvalCompletionsRunDataSource) implEvalRunNewResponseDataSourceUnion() {} + +// Use the following switch statement to find the correct variant +// +// switch variant := EvalRunNewResponseDataSourceUnion.AsAny().(type) { +// case CreateEvalJSONLRunDataSource: +// case CreateEvalCompletionsRunDataSource: +// default: +// fmt.Errorf("no variant present") +// } +func (u EvalRunNewResponseDataSourceUnion) AsAny() anyEvalRunNewResponseDataSource { + switch u.Type { + case "jsonl": + return u.AsJSONL() + case "completions": + return u.AsCompletions() + } + return nil +} + +func (u EvalRunNewResponseDataSourceUnion) AsJSONL() (v CreateEvalJSONLRunDataSource) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u EvalRunNewResponseDataSourceUnion) AsCompletions() (v CreateEvalCompletionsRunDataSource) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +// Returns the unmodified JSON received from the API +func (u EvalRunNewResponseDataSourceUnion) RawJSON() string { return u.JSON.raw } + +func (r *EvalRunNewResponseDataSourceUnion) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalRunNewResponseDataSourceUnionSource is an implicit subunion of +// [EvalRunNewResponseDataSourceUnion]. EvalRunNewResponseDataSourceUnionSource +// provides convenient access to the sub-properties of the union. +// +// For type safety it is recommended to directly use a variant of the +// [EvalRunNewResponseDataSourceUnion]. +type EvalRunNewResponseDataSourceUnionSource struct { + // This field is a union of + // [[]CreateEvalJSONLRunDataSourceSourceFileContentContent], + // [[]CreateEvalCompletionsRunDataSourceSourceFileContentContent] + Content EvalRunNewResponseDataSourceUnionSourceContent `json:"content"` + Type string `json:"type"` + ID string `json:"id"` + // This field is from variant [CreateEvalCompletionsRunDataSourceSourceUnion]. + CreatedAfter int64 `json:"created_after"` + // This field is from variant [CreateEvalCompletionsRunDataSourceSourceUnion]. + CreatedBefore int64 `json:"created_before"` + // This field is from variant [CreateEvalCompletionsRunDataSourceSourceUnion]. + Limit int64 `json:"limit"` + // This field is from variant [CreateEvalCompletionsRunDataSourceSourceUnion]. + Metadata shared.Metadata `json:"metadata"` + // This field is from variant [CreateEvalCompletionsRunDataSourceSourceUnion]. + Model string `json:"model"` + JSON struct { + Content resp.Field + Type resp.Field + ID resp.Field + CreatedAfter resp.Field + CreatedBefore resp.Field + Limit resp.Field + Metadata resp.Field + Model resp.Field + raw string + } `json:"-"` +} + +func (r *EvalRunNewResponseDataSourceUnionSource) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalRunNewResponseDataSourceUnionSourceContent is an implicit subunion of +// [EvalRunNewResponseDataSourceUnion]. +// EvalRunNewResponseDataSourceUnionSourceContent provides convenient access to the +// sub-properties of the union. +// +// For type safety it is recommended to directly use a variant of the +// [EvalRunNewResponseDataSourceUnion]. +// +// If the underlying value is not a json object, one of the following properties +// will be valid: OfCreateEvalJSONLRunDataSourceSourceFileContentContent +// OfCreateEvalCompletionsRunDataSourceSourceFileContentContent] +type EvalRunNewResponseDataSourceUnionSourceContent struct { + // This field will be present if the value is a + // [[]CreateEvalJSONLRunDataSourceSourceFileContentContent] instead of an object. + OfCreateEvalJSONLRunDataSourceSourceFileContentContent []CreateEvalJSONLRunDataSourceSourceFileContentContent `json:",inline"` + // This field will be present if the value is a + // [[]CreateEvalCompletionsRunDataSourceSourceFileContentContent] instead of an + // object. + OfCreateEvalCompletionsRunDataSourceSourceFileContentContent []CreateEvalCompletionsRunDataSourceSourceFileContentContent `json:",inline"` + JSON struct { + OfCreateEvalJSONLRunDataSourceSourceFileContentContent resp.Field + OfCreateEvalCompletionsRunDataSourceSourceFileContentContent resp.Field + raw string + } `json:"-"` +} + +func (r *EvalRunNewResponseDataSourceUnionSourceContent) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type EvalRunNewResponsePerModelUsage struct { + // The number of tokens retrieved from cache. + CachedTokens int64 `json:"cached_tokens,required"` + // The number of completion tokens generated. + CompletionTokens int64 `json:"completion_tokens,required"` + // The number of invocations. + InvocationCount int64 `json:"invocation_count,required"` + // The name of the model. + ModelName string `json:"model_name,required"` + // The number of prompt tokens used. + PromptTokens int64 `json:"prompt_tokens,required"` + // The total number of tokens used. + TotalTokens int64 `json:"total_tokens,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + CachedTokens resp.Field + CompletionTokens resp.Field + InvocationCount resp.Field + ModelName resp.Field + PromptTokens resp.Field + TotalTokens resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunNewResponsePerModelUsage) RawJSON() string { return r.JSON.raw } +func (r *EvalRunNewResponsePerModelUsage) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type EvalRunNewResponsePerTestingCriteriaResult struct { + // Number of tests failed for this criteria. + Failed int64 `json:"failed,required"` + // Number of tests passed for this criteria. + Passed int64 `json:"passed,required"` + // A description of the testing criteria. + TestingCriteria string `json:"testing_criteria,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Failed resp.Field + Passed resp.Field + TestingCriteria resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunNewResponsePerTestingCriteriaResult) RawJSON() string { return r.JSON.raw } +func (r *EvalRunNewResponsePerTestingCriteriaResult) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// Counters summarizing the outcomes of the evaluation run. +type EvalRunNewResponseResultCounts struct { + // Number of output items that resulted in an error. + Errored int64 `json:"errored,required"` + // Number of output items that failed to pass the evaluation. + Failed int64 `json:"failed,required"` + // Number of output items that passed the evaluation. + Passed int64 `json:"passed,required"` + // Total number of executed output items. + Total int64 `json:"total,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Errored resp.Field + Failed resp.Field + Passed resp.Field + Total resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunNewResponseResultCounts) RawJSON() string { return r.JSON.raw } +func (r *EvalRunNewResponseResultCounts) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// A schema representing an evaluation run. +type EvalRunGetResponse struct { + // Unique identifier for the evaluation run. + ID string `json:"id,required"` + // Unix timestamp (in seconds) when the evaluation run was created. + CreatedAt int64 `json:"created_at,required"` + // Information about the run's data source. + DataSource EvalRunGetResponseDataSourceUnion `json:"data_source,required"` + // An object representing an error response from the Eval API. + Error EvalAPIError `json:"error,required"` + // The identifier of the associated evaluation. + EvalID string `json:"eval_id,required"` + // Set of 16 key-value pairs that can be attached to an object. This can be useful + // for storing additional information about the object in a structured format, and + // querying for objects via API or the dashboard. + // + // Keys are strings with a maximum length of 64 characters. Values are strings with + // a maximum length of 512 characters. + Metadata shared.Metadata `json:"metadata,required"` + // The model that is evaluated, if applicable. + Model string `json:"model,required"` + // The name of the evaluation run. + Name string `json:"name,required"` + // The type of the object. Always "eval.run". + Object constant.EvalRun `json:"object,required"` + // Usage statistics for each model during the evaluation run. + PerModelUsage []EvalRunGetResponsePerModelUsage `json:"per_model_usage,required"` + // Results per testing criteria applied during the evaluation run. + PerTestingCriteriaResults []EvalRunGetResponsePerTestingCriteriaResult `json:"per_testing_criteria_results,required"` + // The URL to the rendered evaluation run report on the UI dashboard. + ReportURL string `json:"report_url,required"` + // Counters summarizing the outcomes of the evaluation run. + ResultCounts EvalRunGetResponseResultCounts `json:"result_counts,required"` + // The status of the evaluation run. + Status string `json:"status,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + ID resp.Field + CreatedAt resp.Field + DataSource resp.Field + Error resp.Field + EvalID resp.Field + Metadata resp.Field + Model resp.Field + Name resp.Field + Object resp.Field + PerModelUsage resp.Field + PerTestingCriteriaResults resp.Field + ReportURL resp.Field + ResultCounts resp.Field + Status resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunGetResponse) RawJSON() string { return r.JSON.raw } +func (r *EvalRunGetResponse) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalRunGetResponseDataSourceUnion contains all possible properties and values +// from [CreateEvalJSONLRunDataSource], [CreateEvalCompletionsRunDataSource]. +// +// Use the [EvalRunGetResponseDataSourceUnion.AsAny] method to switch on the +// variant. +// +// Use the methods beginning with 'As' to cast the union to one of its variants. +type EvalRunGetResponseDataSourceUnion struct { + // This field is a union of [CreateEvalJSONLRunDataSourceSourceUnion], + // [CreateEvalCompletionsRunDataSourceSourceUnion] + Source EvalRunGetResponseDataSourceUnionSource `json:"source"` + // Any of "jsonl", "completions". + Type string `json:"type"` + // This field is from variant [CreateEvalCompletionsRunDataSource]. + InputMessages CreateEvalCompletionsRunDataSourceInputMessagesUnion `json:"input_messages"` + // This field is from variant [CreateEvalCompletionsRunDataSource]. + Model string `json:"model"` + // This field is from variant [CreateEvalCompletionsRunDataSource]. + SamplingParams CreateEvalCompletionsRunDataSourceSamplingParams `json:"sampling_params"` + JSON struct { + Source resp.Field + Type resp.Field + InputMessages resp.Field + Model resp.Field + SamplingParams resp.Field + raw string + } `json:"-"` +} + +// anyEvalRunGetResponseDataSource is implemented by each variant of +// [EvalRunGetResponseDataSourceUnion] to add type safety for the return type of +// [EvalRunGetResponseDataSourceUnion.AsAny] +type anyEvalRunGetResponseDataSource interface { + implEvalRunGetResponseDataSourceUnion() +} + +func (CreateEvalJSONLRunDataSource) implEvalRunGetResponseDataSourceUnion() {} +func (CreateEvalCompletionsRunDataSource) implEvalRunGetResponseDataSourceUnion() {} + +// Use the following switch statement to find the correct variant +// +// switch variant := EvalRunGetResponseDataSourceUnion.AsAny().(type) { +// case CreateEvalJSONLRunDataSource: +// case CreateEvalCompletionsRunDataSource: +// default: +// fmt.Errorf("no variant present") +// } +func (u EvalRunGetResponseDataSourceUnion) AsAny() anyEvalRunGetResponseDataSource { + switch u.Type { + case "jsonl": + return u.AsJSONL() + case "completions": + return u.AsCompletions() + } + return nil +} + +func (u EvalRunGetResponseDataSourceUnion) AsJSONL() (v CreateEvalJSONLRunDataSource) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u EvalRunGetResponseDataSourceUnion) AsCompletions() (v CreateEvalCompletionsRunDataSource) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +// Returns the unmodified JSON received from the API +func (u EvalRunGetResponseDataSourceUnion) RawJSON() string { return u.JSON.raw } + +func (r *EvalRunGetResponseDataSourceUnion) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalRunGetResponseDataSourceUnionSource is an implicit subunion of +// [EvalRunGetResponseDataSourceUnion]. EvalRunGetResponseDataSourceUnionSource +// provides convenient access to the sub-properties of the union. +// +// For type safety it is recommended to directly use a variant of the +// [EvalRunGetResponseDataSourceUnion]. +type EvalRunGetResponseDataSourceUnionSource struct { + // This field is a union of + // [[]CreateEvalJSONLRunDataSourceSourceFileContentContent], + // [[]CreateEvalCompletionsRunDataSourceSourceFileContentContent] + Content EvalRunGetResponseDataSourceUnionSourceContent `json:"content"` + Type string `json:"type"` + ID string `json:"id"` + // This field is from variant [CreateEvalCompletionsRunDataSourceSourceUnion]. + CreatedAfter int64 `json:"created_after"` + // This field is from variant [CreateEvalCompletionsRunDataSourceSourceUnion]. + CreatedBefore int64 `json:"created_before"` + // This field is from variant [CreateEvalCompletionsRunDataSourceSourceUnion]. + Limit int64 `json:"limit"` + // This field is from variant [CreateEvalCompletionsRunDataSourceSourceUnion]. + Metadata shared.Metadata `json:"metadata"` + // This field is from variant [CreateEvalCompletionsRunDataSourceSourceUnion]. + Model string `json:"model"` + JSON struct { + Content resp.Field + Type resp.Field + ID resp.Field + CreatedAfter resp.Field + CreatedBefore resp.Field + Limit resp.Field + Metadata resp.Field + Model resp.Field + raw string + } `json:"-"` +} + +func (r *EvalRunGetResponseDataSourceUnionSource) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalRunGetResponseDataSourceUnionSourceContent is an implicit subunion of +// [EvalRunGetResponseDataSourceUnion]. +// EvalRunGetResponseDataSourceUnionSourceContent provides convenient access to the +// sub-properties of the union. +// +// For type safety it is recommended to directly use a variant of the +// [EvalRunGetResponseDataSourceUnion]. +// +// If the underlying value is not a json object, one of the following properties +// will be valid: OfCreateEvalJSONLRunDataSourceSourceFileContentContent +// OfCreateEvalCompletionsRunDataSourceSourceFileContentContent] +type EvalRunGetResponseDataSourceUnionSourceContent struct { + // This field will be present if the value is a + // [[]CreateEvalJSONLRunDataSourceSourceFileContentContent] instead of an object. + OfCreateEvalJSONLRunDataSourceSourceFileContentContent []CreateEvalJSONLRunDataSourceSourceFileContentContent `json:",inline"` + // This field will be present if the value is a + // [[]CreateEvalCompletionsRunDataSourceSourceFileContentContent] instead of an + // object. + OfCreateEvalCompletionsRunDataSourceSourceFileContentContent []CreateEvalCompletionsRunDataSourceSourceFileContentContent `json:",inline"` + JSON struct { + OfCreateEvalJSONLRunDataSourceSourceFileContentContent resp.Field + OfCreateEvalCompletionsRunDataSourceSourceFileContentContent resp.Field + raw string + } `json:"-"` +} + +func (r *EvalRunGetResponseDataSourceUnionSourceContent) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type EvalRunGetResponsePerModelUsage struct { + // The number of tokens retrieved from cache. + CachedTokens int64 `json:"cached_tokens,required"` + // The number of completion tokens generated. + CompletionTokens int64 `json:"completion_tokens,required"` + // The number of invocations. + InvocationCount int64 `json:"invocation_count,required"` + // The name of the model. + ModelName string `json:"model_name,required"` + // The number of prompt tokens used. + PromptTokens int64 `json:"prompt_tokens,required"` + // The total number of tokens used. + TotalTokens int64 `json:"total_tokens,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + CachedTokens resp.Field + CompletionTokens resp.Field + InvocationCount resp.Field + ModelName resp.Field + PromptTokens resp.Field + TotalTokens resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunGetResponsePerModelUsage) RawJSON() string { return r.JSON.raw } +func (r *EvalRunGetResponsePerModelUsage) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type EvalRunGetResponsePerTestingCriteriaResult struct { + // Number of tests failed for this criteria. + Failed int64 `json:"failed,required"` + // Number of tests passed for this criteria. + Passed int64 `json:"passed,required"` + // A description of the testing criteria. + TestingCriteria string `json:"testing_criteria,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Failed resp.Field + Passed resp.Field + TestingCriteria resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunGetResponsePerTestingCriteriaResult) RawJSON() string { return r.JSON.raw } +func (r *EvalRunGetResponsePerTestingCriteriaResult) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// Counters summarizing the outcomes of the evaluation run. +type EvalRunGetResponseResultCounts struct { + // Number of output items that resulted in an error. + Errored int64 `json:"errored,required"` + // Number of output items that failed to pass the evaluation. + Failed int64 `json:"failed,required"` + // Number of output items that passed the evaluation. + Passed int64 `json:"passed,required"` + // Total number of executed output items. + Total int64 `json:"total,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Errored resp.Field + Failed resp.Field + Passed resp.Field + Total resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunGetResponseResultCounts) RawJSON() string { return r.JSON.raw } +func (r *EvalRunGetResponseResultCounts) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// A schema representing an evaluation run. +type EvalRunListResponse struct { + // Unique identifier for the evaluation run. + ID string `json:"id,required"` + // Unix timestamp (in seconds) when the evaluation run was created. + CreatedAt int64 `json:"created_at,required"` + // Information about the run's data source. + DataSource EvalRunListResponseDataSourceUnion `json:"data_source,required"` + // An object representing an error response from the Eval API. + Error EvalAPIError `json:"error,required"` + // The identifier of the associated evaluation. + EvalID string `json:"eval_id,required"` + // Set of 16 key-value pairs that can be attached to an object. This can be useful + // for storing additional information about the object in a structured format, and + // querying for objects via API or the dashboard. + // + // Keys are strings with a maximum length of 64 characters. Values are strings with + // a maximum length of 512 characters. + Metadata shared.Metadata `json:"metadata,required"` + // The model that is evaluated, if applicable. + Model string `json:"model,required"` + // The name of the evaluation run. + Name string `json:"name,required"` + // The type of the object. Always "eval.run". + Object constant.EvalRun `json:"object,required"` + // Usage statistics for each model during the evaluation run. + PerModelUsage []EvalRunListResponsePerModelUsage `json:"per_model_usage,required"` + // Results per testing criteria applied during the evaluation run. + PerTestingCriteriaResults []EvalRunListResponsePerTestingCriteriaResult `json:"per_testing_criteria_results,required"` + // The URL to the rendered evaluation run report on the UI dashboard. + ReportURL string `json:"report_url,required"` + // Counters summarizing the outcomes of the evaluation run. + ResultCounts EvalRunListResponseResultCounts `json:"result_counts,required"` + // The status of the evaluation run. + Status string `json:"status,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + ID resp.Field + CreatedAt resp.Field + DataSource resp.Field + Error resp.Field + EvalID resp.Field + Metadata resp.Field + Model resp.Field + Name resp.Field + Object resp.Field + PerModelUsage resp.Field + PerTestingCriteriaResults resp.Field + ReportURL resp.Field + ResultCounts resp.Field + Status resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunListResponse) RawJSON() string { return r.JSON.raw } +func (r *EvalRunListResponse) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalRunListResponseDataSourceUnion contains all possible properties and values +// from [CreateEvalJSONLRunDataSource], [CreateEvalCompletionsRunDataSource]. +// +// Use the [EvalRunListResponseDataSourceUnion.AsAny] method to switch on the +// variant. +// +// Use the methods beginning with 'As' to cast the union to one of its variants. +type EvalRunListResponseDataSourceUnion struct { + // This field is a union of [CreateEvalJSONLRunDataSourceSourceUnion], + // [CreateEvalCompletionsRunDataSourceSourceUnion] + Source EvalRunListResponseDataSourceUnionSource `json:"source"` + // Any of "jsonl", "completions". + Type string `json:"type"` + // This field is from variant [CreateEvalCompletionsRunDataSource]. + InputMessages CreateEvalCompletionsRunDataSourceInputMessagesUnion `json:"input_messages"` + // This field is from variant [CreateEvalCompletionsRunDataSource]. + Model string `json:"model"` + // This field is from variant [CreateEvalCompletionsRunDataSource]. + SamplingParams CreateEvalCompletionsRunDataSourceSamplingParams `json:"sampling_params"` + JSON struct { + Source resp.Field + Type resp.Field + InputMessages resp.Field + Model resp.Field + SamplingParams resp.Field + raw string + } `json:"-"` +} + +// anyEvalRunListResponseDataSource is implemented by each variant of +// [EvalRunListResponseDataSourceUnion] to add type safety for the return type of +// [EvalRunListResponseDataSourceUnion.AsAny] +type anyEvalRunListResponseDataSource interface { + implEvalRunListResponseDataSourceUnion() +} + +func (CreateEvalJSONLRunDataSource) implEvalRunListResponseDataSourceUnion() {} +func (CreateEvalCompletionsRunDataSource) implEvalRunListResponseDataSourceUnion() {} + +// Use the following switch statement to find the correct variant +// +// switch variant := EvalRunListResponseDataSourceUnion.AsAny().(type) { +// case CreateEvalJSONLRunDataSource: +// case CreateEvalCompletionsRunDataSource: +// default: +// fmt.Errorf("no variant present") +// } +func (u EvalRunListResponseDataSourceUnion) AsAny() anyEvalRunListResponseDataSource { + switch u.Type { + case "jsonl": + return u.AsJSONL() + case "completions": + return u.AsCompletions() + } + return nil +} + +func (u EvalRunListResponseDataSourceUnion) AsJSONL() (v CreateEvalJSONLRunDataSource) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u EvalRunListResponseDataSourceUnion) AsCompletions() (v CreateEvalCompletionsRunDataSource) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +// Returns the unmodified JSON received from the API +func (u EvalRunListResponseDataSourceUnion) RawJSON() string { return u.JSON.raw } + +func (r *EvalRunListResponseDataSourceUnion) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalRunListResponseDataSourceUnionSource is an implicit subunion of +// [EvalRunListResponseDataSourceUnion]. EvalRunListResponseDataSourceUnionSource +// provides convenient access to the sub-properties of the union. +// +// For type safety it is recommended to directly use a variant of the +// [EvalRunListResponseDataSourceUnion]. +type EvalRunListResponseDataSourceUnionSource struct { + // This field is a union of + // [[]CreateEvalJSONLRunDataSourceSourceFileContentContent], + // [[]CreateEvalCompletionsRunDataSourceSourceFileContentContent] + Content EvalRunListResponseDataSourceUnionSourceContent `json:"content"` + Type string `json:"type"` + ID string `json:"id"` + // This field is from variant [CreateEvalCompletionsRunDataSourceSourceUnion]. + CreatedAfter int64 `json:"created_after"` + // This field is from variant [CreateEvalCompletionsRunDataSourceSourceUnion]. + CreatedBefore int64 `json:"created_before"` + // This field is from variant [CreateEvalCompletionsRunDataSourceSourceUnion]. + Limit int64 `json:"limit"` + // This field is from variant [CreateEvalCompletionsRunDataSourceSourceUnion]. + Metadata shared.Metadata `json:"metadata"` + // This field is from variant [CreateEvalCompletionsRunDataSourceSourceUnion]. + Model string `json:"model"` + JSON struct { + Content resp.Field + Type resp.Field + ID resp.Field + CreatedAfter resp.Field + CreatedBefore resp.Field + Limit resp.Field + Metadata resp.Field + Model resp.Field + raw string + } `json:"-"` +} + +func (r *EvalRunListResponseDataSourceUnionSource) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalRunListResponseDataSourceUnionSourceContent is an implicit subunion of +// [EvalRunListResponseDataSourceUnion]. +// EvalRunListResponseDataSourceUnionSourceContent provides convenient access to +// the sub-properties of the union. +// +// For type safety it is recommended to directly use a variant of the +// [EvalRunListResponseDataSourceUnion]. +// +// If the underlying value is not a json object, one of the following properties +// will be valid: OfCreateEvalJSONLRunDataSourceSourceFileContentContent +// OfCreateEvalCompletionsRunDataSourceSourceFileContentContent] +type EvalRunListResponseDataSourceUnionSourceContent struct { + // This field will be present if the value is a + // [[]CreateEvalJSONLRunDataSourceSourceFileContentContent] instead of an object. + OfCreateEvalJSONLRunDataSourceSourceFileContentContent []CreateEvalJSONLRunDataSourceSourceFileContentContent `json:",inline"` + // This field will be present if the value is a + // [[]CreateEvalCompletionsRunDataSourceSourceFileContentContent] instead of an + // object. + OfCreateEvalCompletionsRunDataSourceSourceFileContentContent []CreateEvalCompletionsRunDataSourceSourceFileContentContent `json:",inline"` + JSON struct { + OfCreateEvalJSONLRunDataSourceSourceFileContentContent resp.Field + OfCreateEvalCompletionsRunDataSourceSourceFileContentContent resp.Field + raw string + } `json:"-"` +} + +func (r *EvalRunListResponseDataSourceUnionSourceContent) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type EvalRunListResponsePerModelUsage struct { + // The number of tokens retrieved from cache. + CachedTokens int64 `json:"cached_tokens,required"` + // The number of completion tokens generated. + CompletionTokens int64 `json:"completion_tokens,required"` + // The number of invocations. + InvocationCount int64 `json:"invocation_count,required"` + // The name of the model. + ModelName string `json:"model_name,required"` + // The number of prompt tokens used. + PromptTokens int64 `json:"prompt_tokens,required"` + // The total number of tokens used. + TotalTokens int64 `json:"total_tokens,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + CachedTokens resp.Field + CompletionTokens resp.Field + InvocationCount resp.Field + ModelName resp.Field + PromptTokens resp.Field + TotalTokens resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunListResponsePerModelUsage) RawJSON() string { return r.JSON.raw } +func (r *EvalRunListResponsePerModelUsage) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type EvalRunListResponsePerTestingCriteriaResult struct { + // Number of tests failed for this criteria. + Failed int64 `json:"failed,required"` + // Number of tests passed for this criteria. + Passed int64 `json:"passed,required"` + // A description of the testing criteria. + TestingCriteria string `json:"testing_criteria,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Failed resp.Field + Passed resp.Field + TestingCriteria resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunListResponsePerTestingCriteriaResult) RawJSON() string { return r.JSON.raw } +func (r *EvalRunListResponsePerTestingCriteriaResult) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// Counters summarizing the outcomes of the evaluation run. +type EvalRunListResponseResultCounts struct { + // Number of output items that resulted in an error. + Errored int64 `json:"errored,required"` + // Number of output items that failed to pass the evaluation. + Failed int64 `json:"failed,required"` + // Number of output items that passed the evaluation. + Passed int64 `json:"passed,required"` + // Total number of executed output items. + Total int64 `json:"total,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Errored resp.Field + Failed resp.Field + Passed resp.Field + Total resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunListResponseResultCounts) RawJSON() string { return r.JSON.raw } +func (r *EvalRunListResponseResultCounts) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type EvalRunDeleteResponse struct { + Deleted bool `json:"deleted"` + Object string `json:"object"` + RunID string `json:"run_id"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Deleted resp.Field + Object resp.Field + RunID resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunDeleteResponse) RawJSON() string { return r.JSON.raw } +func (r *EvalRunDeleteResponse) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// A schema representing an evaluation run. +type EvalRunCancelResponse struct { + // Unique identifier for the evaluation run. + ID string `json:"id,required"` + // Unix timestamp (in seconds) when the evaluation run was created. + CreatedAt int64 `json:"created_at,required"` + // Information about the run's data source. + DataSource EvalRunCancelResponseDataSourceUnion `json:"data_source,required"` + // An object representing an error response from the Eval API. + Error EvalAPIError `json:"error,required"` + // The identifier of the associated evaluation. + EvalID string `json:"eval_id,required"` + // Set of 16 key-value pairs that can be attached to an object. This can be useful + // for storing additional information about the object in a structured format, and + // querying for objects via API or the dashboard. + // + // Keys are strings with a maximum length of 64 characters. Values are strings with + // a maximum length of 512 characters. + Metadata shared.Metadata `json:"metadata,required"` + // The model that is evaluated, if applicable. + Model string `json:"model,required"` + // The name of the evaluation run. + Name string `json:"name,required"` + // The type of the object. Always "eval.run". + Object constant.EvalRun `json:"object,required"` + // Usage statistics for each model during the evaluation run. + PerModelUsage []EvalRunCancelResponsePerModelUsage `json:"per_model_usage,required"` + // Results per testing criteria applied during the evaluation run. + PerTestingCriteriaResults []EvalRunCancelResponsePerTestingCriteriaResult `json:"per_testing_criteria_results,required"` + // The URL to the rendered evaluation run report on the UI dashboard. + ReportURL string `json:"report_url,required"` + // Counters summarizing the outcomes of the evaluation run. + ResultCounts EvalRunCancelResponseResultCounts `json:"result_counts,required"` + // The status of the evaluation run. + Status string `json:"status,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + ID resp.Field + CreatedAt resp.Field + DataSource resp.Field + Error resp.Field + EvalID resp.Field + Metadata resp.Field + Model resp.Field + Name resp.Field + Object resp.Field + PerModelUsage resp.Field + PerTestingCriteriaResults resp.Field + ReportURL resp.Field + ResultCounts resp.Field + Status resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunCancelResponse) RawJSON() string { return r.JSON.raw } +func (r *EvalRunCancelResponse) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalRunCancelResponseDataSourceUnion contains all possible properties and values +// from [CreateEvalJSONLRunDataSource], [CreateEvalCompletionsRunDataSource]. +// +// Use the [EvalRunCancelResponseDataSourceUnion.AsAny] method to switch on the +// variant. +// +// Use the methods beginning with 'As' to cast the union to one of its variants. +type EvalRunCancelResponseDataSourceUnion struct { + // This field is a union of [CreateEvalJSONLRunDataSourceSourceUnion], + // [CreateEvalCompletionsRunDataSourceSourceUnion] + Source EvalRunCancelResponseDataSourceUnionSource `json:"source"` + // Any of "jsonl", "completions". + Type string `json:"type"` + // This field is from variant [CreateEvalCompletionsRunDataSource]. + InputMessages CreateEvalCompletionsRunDataSourceInputMessagesUnion `json:"input_messages"` + // This field is from variant [CreateEvalCompletionsRunDataSource]. + Model string `json:"model"` + // This field is from variant [CreateEvalCompletionsRunDataSource]. + SamplingParams CreateEvalCompletionsRunDataSourceSamplingParams `json:"sampling_params"` + JSON struct { + Source resp.Field + Type resp.Field + InputMessages resp.Field + Model resp.Field + SamplingParams resp.Field + raw string + } `json:"-"` +} + +// anyEvalRunCancelResponseDataSource is implemented by each variant of +// [EvalRunCancelResponseDataSourceUnion] to add type safety for the return type of +// [EvalRunCancelResponseDataSourceUnion.AsAny] +type anyEvalRunCancelResponseDataSource interface { + implEvalRunCancelResponseDataSourceUnion() +} + +func (CreateEvalJSONLRunDataSource) implEvalRunCancelResponseDataSourceUnion() {} +func (CreateEvalCompletionsRunDataSource) implEvalRunCancelResponseDataSourceUnion() {} + +// Use the following switch statement to find the correct variant +// +// switch variant := EvalRunCancelResponseDataSourceUnion.AsAny().(type) { +// case CreateEvalJSONLRunDataSource: +// case CreateEvalCompletionsRunDataSource: +// default: +// fmt.Errorf("no variant present") +// } +func (u EvalRunCancelResponseDataSourceUnion) AsAny() anyEvalRunCancelResponseDataSource { + switch u.Type { + case "jsonl": + return u.AsJSONL() + case "completions": + return u.AsCompletions() + } + return nil +} + +func (u EvalRunCancelResponseDataSourceUnion) AsJSONL() (v CreateEvalJSONLRunDataSource) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +func (u EvalRunCancelResponseDataSourceUnion) AsCompletions() (v CreateEvalCompletionsRunDataSource) { + apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) + return +} + +// Returns the unmodified JSON received from the API +func (u EvalRunCancelResponseDataSourceUnion) RawJSON() string { return u.JSON.raw } + +func (r *EvalRunCancelResponseDataSourceUnion) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalRunCancelResponseDataSourceUnionSource is an implicit subunion of +// [EvalRunCancelResponseDataSourceUnion]. +// EvalRunCancelResponseDataSourceUnionSource provides convenient access to the +// sub-properties of the union. +// +// For type safety it is recommended to directly use a variant of the +// [EvalRunCancelResponseDataSourceUnion]. +type EvalRunCancelResponseDataSourceUnionSource struct { + // This field is a union of + // [[]CreateEvalJSONLRunDataSourceSourceFileContentContent], + // [[]CreateEvalCompletionsRunDataSourceSourceFileContentContent] + Content EvalRunCancelResponseDataSourceUnionSourceContent `json:"content"` + Type string `json:"type"` + ID string `json:"id"` + // This field is from variant [CreateEvalCompletionsRunDataSourceSourceUnion]. + CreatedAfter int64 `json:"created_after"` + // This field is from variant [CreateEvalCompletionsRunDataSourceSourceUnion]. + CreatedBefore int64 `json:"created_before"` + // This field is from variant [CreateEvalCompletionsRunDataSourceSourceUnion]. + Limit int64 `json:"limit"` + // This field is from variant [CreateEvalCompletionsRunDataSourceSourceUnion]. + Metadata shared.Metadata `json:"metadata"` + // This field is from variant [CreateEvalCompletionsRunDataSourceSourceUnion]. + Model string `json:"model"` + JSON struct { + Content resp.Field + Type resp.Field + ID resp.Field + CreatedAfter resp.Field + CreatedBefore resp.Field + Limit resp.Field + Metadata resp.Field + Model resp.Field + raw string + } `json:"-"` +} + +func (r *EvalRunCancelResponseDataSourceUnionSource) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// EvalRunCancelResponseDataSourceUnionSourceContent is an implicit subunion of +// [EvalRunCancelResponseDataSourceUnion]. +// EvalRunCancelResponseDataSourceUnionSourceContent provides convenient access to +// the sub-properties of the union. +// +// For type safety it is recommended to directly use a variant of the +// [EvalRunCancelResponseDataSourceUnion]. +// +// If the underlying value is not a json object, one of the following properties +// will be valid: OfCreateEvalJSONLRunDataSourceSourceFileContentContent +// OfCreateEvalCompletionsRunDataSourceSourceFileContentContent] +type EvalRunCancelResponseDataSourceUnionSourceContent struct { + // This field will be present if the value is a + // [[]CreateEvalJSONLRunDataSourceSourceFileContentContent] instead of an object. + OfCreateEvalJSONLRunDataSourceSourceFileContentContent []CreateEvalJSONLRunDataSourceSourceFileContentContent `json:",inline"` + // This field will be present if the value is a + // [[]CreateEvalCompletionsRunDataSourceSourceFileContentContent] instead of an + // object. + OfCreateEvalCompletionsRunDataSourceSourceFileContentContent []CreateEvalCompletionsRunDataSourceSourceFileContentContent `json:",inline"` + JSON struct { + OfCreateEvalJSONLRunDataSourceSourceFileContentContent resp.Field + OfCreateEvalCompletionsRunDataSourceSourceFileContentContent resp.Field + raw string + } `json:"-"` +} + +func (r *EvalRunCancelResponseDataSourceUnionSourceContent) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type EvalRunCancelResponsePerModelUsage struct { + // The number of tokens retrieved from cache. + CachedTokens int64 `json:"cached_tokens,required"` + // The number of completion tokens generated. + CompletionTokens int64 `json:"completion_tokens,required"` + // The number of invocations. + InvocationCount int64 `json:"invocation_count,required"` + // The name of the model. + ModelName string `json:"model_name,required"` + // The number of prompt tokens used. + PromptTokens int64 `json:"prompt_tokens,required"` + // The total number of tokens used. + TotalTokens int64 `json:"total_tokens,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + CachedTokens resp.Field + CompletionTokens resp.Field + InvocationCount resp.Field + ModelName resp.Field + PromptTokens resp.Field + TotalTokens resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunCancelResponsePerModelUsage) RawJSON() string { return r.JSON.raw } +func (r *EvalRunCancelResponsePerModelUsage) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type EvalRunCancelResponsePerTestingCriteriaResult struct { + // Number of tests failed for this criteria. + Failed int64 `json:"failed,required"` + // Number of tests passed for this criteria. + Passed int64 `json:"passed,required"` + // A description of the testing criteria. + TestingCriteria string `json:"testing_criteria,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Failed resp.Field + Passed resp.Field + TestingCriteria resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunCancelResponsePerTestingCriteriaResult) RawJSON() string { return r.JSON.raw } +func (r *EvalRunCancelResponsePerTestingCriteriaResult) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// Counters summarizing the outcomes of the evaluation run. +type EvalRunCancelResponseResultCounts struct { + // Number of output items that resulted in an error. + Errored int64 `json:"errored,required"` + // Number of output items that failed to pass the evaluation. + Failed int64 `json:"failed,required"` + // Number of output items that passed the evaluation. + Passed int64 `json:"passed,required"` + // Total number of executed output items. + Total int64 `json:"total,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Errored resp.Field + Failed resp.Field + Passed resp.Field + Total resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunCancelResponseResultCounts) RawJSON() string { return r.JSON.raw } +func (r *EvalRunCancelResponseResultCounts) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type EvalRunNewParams struct { + // Details about the run's data source. + DataSource EvalRunNewParamsDataSourceUnion `json:"data_source,omitzero,required"` + // The name of the run. + Name param.Opt[string] `json:"name,omitzero"` + // Set of 16 key-value pairs that can be attached to an object. This can be useful + // for storing additional information about the object in a structured format, and + // querying for objects via API or the dashboard. + // + // Keys are strings with a maximum length of 64 characters. Values are strings with + // a maximum length of 512 characters. + Metadata shared.MetadataParam `json:"metadata,omitzero"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f EvalRunNewParams) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() } + +func (r EvalRunNewParams) MarshalJSON() (data []byte, err error) { + type shadow EvalRunNewParams + return param.MarshalObject(r, (*shadow)(&r)) +} + +// Only one field can be non-zero. +// +// Use [param.IsOmitted] to confirm if a field is set. +type EvalRunNewParamsDataSourceUnion struct { + OfJSONLRunDataSource *CreateEvalJSONLRunDataSourceParam `json:",omitzero,inline"` + OfCompletionsRunDataSource *CreateEvalCompletionsRunDataSourceParam `json:",omitzero,inline"` + paramUnion +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (u EvalRunNewParamsDataSourceUnion) IsPresent() bool { return !param.IsOmitted(u) && !u.IsNull() } +func (u EvalRunNewParamsDataSourceUnion) MarshalJSON() ([]byte, error) { + return param.MarshalUnion[EvalRunNewParamsDataSourceUnion](u.OfJSONLRunDataSource, u.OfCompletionsRunDataSource) +} + +func (u *EvalRunNewParamsDataSourceUnion) asAny() any { + if !param.IsOmitted(u.OfJSONLRunDataSource) { + return u.OfJSONLRunDataSource + } else if !param.IsOmitted(u.OfCompletionsRunDataSource) { + return u.OfCompletionsRunDataSource + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u EvalRunNewParamsDataSourceUnion) GetInputMessages() *CreateEvalCompletionsRunDataSourceInputMessagesUnionParam { + if vt := u.OfCompletionsRunDataSource; vt != nil { + return &vt.InputMessages + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u EvalRunNewParamsDataSourceUnion) GetModel() *string { + if vt := u.OfCompletionsRunDataSource; vt != nil { + return &vt.Model + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u EvalRunNewParamsDataSourceUnion) GetSamplingParams() *CreateEvalCompletionsRunDataSourceSamplingParamsParam { + if vt := u.OfCompletionsRunDataSource; vt != nil { + return &vt.SamplingParams + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u EvalRunNewParamsDataSourceUnion) GetType() *string { + if vt := u.OfJSONLRunDataSource; vt != nil { + return (*string)(&vt.Type) + } else if vt := u.OfCompletionsRunDataSource; vt != nil { + return (*string)(&vt.Type) + } + return nil +} + +// Returns a subunion which exports methods to access subproperties +// +// Or use AsAny() to get the underlying value +func (u EvalRunNewParamsDataSourceUnion) GetSource() (res evalRunNewParamsDataSourceUnionSource) { + if vt := u.OfJSONLRunDataSource; vt != nil { + res.ofCreateEvalJSONLRunDataSourceSourceUnion = &vt.Source + } else if vt := u.OfCompletionsRunDataSource; vt != nil { + res.ofCreateEvalCompletionsRunDataSourceSourceUnion = &vt.Source + } + return +} + +// Only one field can be non-zero. +// +// Use [param.IsOmitted] to confirm if a field is set. +type evalRunNewParamsDataSourceUnionSource struct { + ofCreateEvalJSONLRunDataSourceSourceUnion *CreateEvalJSONLRunDataSourceSourceUnionParam + ofCreateEvalCompletionsRunDataSourceSourceUnion *CreateEvalCompletionsRunDataSourceSourceUnionParam +} + +// Use the following switch statement to get the type of the union: +// +// switch u.AsAny().(type) { +// case *openai.CreateEvalJSONLRunDataSourceSourceFileContentParam: +// case *openai.CreateEvalJSONLRunDataSourceSourceFileIDParam: +// case *openai.CreateEvalCompletionsRunDataSourceSourceFileContentParam: +// case *openai.CreateEvalCompletionsRunDataSourceSourceFileIDParam: +// case *openai.CreateEvalCompletionsRunDataSourceSourceStoredCompletionsParam: +// default: +// fmt.Errorf("not present") +// } +func (u evalRunNewParamsDataSourceUnionSource) AsAny() any { + if !param.IsOmitted(u.ofCreateEvalJSONLRunDataSourceSourceUnion) { + return u.ofCreateEvalJSONLRunDataSourceSourceUnion.asAny() + } else if !param.IsOmitted(u.ofCreateEvalCompletionsRunDataSourceSourceUnion) { + return u.ofCreateEvalCompletionsRunDataSourceSourceUnion.asAny() + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u evalRunNewParamsDataSourceUnionSource) GetCreatedAfter() *int64 { + if u.ofCreateEvalCompletionsRunDataSourceSourceUnion != nil { + return u.ofCreateEvalCompletionsRunDataSourceSourceUnion.GetCreatedAfter() + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u evalRunNewParamsDataSourceUnionSource) GetCreatedBefore() *int64 { + if u.ofCreateEvalCompletionsRunDataSourceSourceUnion != nil { + return u.ofCreateEvalCompletionsRunDataSourceSourceUnion.GetCreatedBefore() + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u evalRunNewParamsDataSourceUnionSource) GetLimit() *int64 { + if u.ofCreateEvalCompletionsRunDataSourceSourceUnion != nil { + return u.ofCreateEvalCompletionsRunDataSourceSourceUnion.GetLimit() + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u evalRunNewParamsDataSourceUnionSource) GetMetadata() shared.MetadataParam { + if u.ofCreateEvalCompletionsRunDataSourceSourceUnion != nil { + return u.ofCreateEvalCompletionsRunDataSourceSourceUnion.GetMetadata() + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u evalRunNewParamsDataSourceUnionSource) GetModel() *string { + if u.ofCreateEvalCompletionsRunDataSourceSourceUnion != nil { + return u.ofCreateEvalCompletionsRunDataSourceSourceUnion.GetModel() + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u evalRunNewParamsDataSourceUnionSource) GetType() *string { + if u.ofCreateEvalJSONLRunDataSourceSourceUnion != nil { + return u.ofCreateEvalJSONLRunDataSourceSourceUnion.GetType() + } else if u.ofCreateEvalJSONLRunDataSourceSourceUnion != nil { + return u.ofCreateEvalJSONLRunDataSourceSourceUnion.GetType() + } else if u.ofCreateEvalCompletionsRunDataSourceSourceUnion != nil { + return u.ofCreateEvalCompletionsRunDataSourceSourceUnion.GetType() + } else if u.ofCreateEvalCompletionsRunDataSourceSourceUnion != nil { + return u.ofCreateEvalCompletionsRunDataSourceSourceUnion.GetType() + } else if u.ofCreateEvalCompletionsRunDataSourceSourceUnion != nil { + return u.ofCreateEvalCompletionsRunDataSourceSourceUnion.GetType() + } + return nil +} + +// Returns a pointer to the underlying variant's property, if present. +func (u evalRunNewParamsDataSourceUnionSource) GetID() *string { + if u.ofCreateEvalJSONLRunDataSourceSourceUnion != nil { + return u.ofCreateEvalJSONLRunDataSourceSourceUnion.GetID() + } else if u.ofCreateEvalCompletionsRunDataSourceSourceUnion != nil { + return u.ofCreateEvalCompletionsRunDataSourceSourceUnion.GetID() + } + return nil +} + +// Returns a subunion which exports methods to access subproperties +// +// Or use AsAny() to get the underlying value +func (u evalRunNewParamsDataSourceUnionSource) GetContent() (res evalRunNewParamsDataSourceUnionSourceContent) { + if u.ofCreateEvalJSONLRunDataSourceSourceUnion != nil { + res.ofCreateEvalJSONLRunDataSourceSourceFileContentContent = u.ofCreateEvalJSONLRunDataSourceSourceUnion.GetContent() + } else if u.ofCreateEvalCompletionsRunDataSourceSourceUnion != nil { + res.ofCreateEvalCompletionsRunDataSourceSourceFileContentContent = u.ofCreateEvalCompletionsRunDataSourceSourceUnion.GetContent() + } + return +} + +// Only one field can be non-zero. +// +// Use [param.IsOmitted] to confirm if a field is set. +type evalRunNewParamsDataSourceUnionSourceContent struct { + ofCreateEvalJSONLRunDataSourceSourceFileContentContent *[]CreateEvalJSONLRunDataSourceSourceFileContentContentParam + ofCreateEvalCompletionsRunDataSourceSourceFileContentContent *[]CreateEvalCompletionsRunDataSourceSourceFileContentContentParam +} + +// Use the following switch statement to get the type of the union: +// +// switch u.AsAny().(type) { +// case *[]openai.CreateEvalJSONLRunDataSourceSourceFileContentContentParam: +// case *[]openai.CreateEvalCompletionsRunDataSourceSourceFileContentContentParam: +// default: +// fmt.Errorf("not present") +// } +func (u evalRunNewParamsDataSourceUnionSourceContent) AsAny() any { + if !param.IsOmitted(u.ofCreateEvalJSONLRunDataSourceSourceFileContentContent) { + return u.ofCreateEvalJSONLRunDataSourceSourceFileContentContent + } else if !param.IsOmitted(u.ofCreateEvalCompletionsRunDataSourceSourceFileContentContent) { + return u.ofCreateEvalCompletionsRunDataSourceSourceFileContentContent + } + return nil +} + +type EvalRunListParams struct { + // Identifier for the last run from the previous pagination request. + After param.Opt[string] `query:"after,omitzero" json:"-"` + // Number of runs to retrieve. + Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` + // Sort order for runs by timestamp. Use `asc` for ascending order or `desc` for + // descending order. Defaults to `asc`. + // + // Any of "asc", "desc". + Order EvalRunListParamsOrder `query:"order,omitzero" json:"-"` + // Filter runs by status. Use "queued" | "in_progress" | "failed" | "completed" | + // "canceled". + // + // Any of "queued", "in_progress", "completed", "canceled", "failed". + Status EvalRunListParamsStatus `query:"status,omitzero" json:"-"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f EvalRunListParams) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() } + +// URLQuery serializes [EvalRunListParams]'s query parameters as `url.Values`. +func (r EvalRunListParams) URLQuery() (v url.Values, err error) { + return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ + ArrayFormat: apiquery.ArrayQueryFormatBrackets, + NestedFormat: apiquery.NestedQueryFormatBrackets, + }) +} + +// Sort order for runs by timestamp. Use `asc` for ascending order or `desc` for +// descending order. Defaults to `asc`. +type EvalRunListParamsOrder string + +const ( + EvalRunListParamsOrderAsc EvalRunListParamsOrder = "asc" + EvalRunListParamsOrderDesc EvalRunListParamsOrder = "desc" +) + +// Filter runs by status. Use "queued" | "in_progress" | "failed" | "completed" | +// "canceled". +type EvalRunListParamsStatus string + +const ( + EvalRunListParamsStatusQueued EvalRunListParamsStatus = "queued" + EvalRunListParamsStatusInProgress EvalRunListParamsStatus = "in_progress" + EvalRunListParamsStatusCompleted EvalRunListParamsStatus = "completed" + EvalRunListParamsStatusCanceled EvalRunListParamsStatus = "canceled" + EvalRunListParamsStatusFailed EvalRunListParamsStatus = "failed" +) diff --git a/evalrun_test.go b/evalrun_test.go new file mode 100644 index 00000000..eb974a0f --- /dev/null +++ b/evalrun_test.go @@ -0,0 +1,171 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package openai_test + +import ( + "context" + "errors" + "os" + "testing" + + "github.com/openai/openai-go" + "github.com/openai/openai-go/internal/testutil" + "github.com/openai/openai-go/option" + "github.com/openai/openai-go/shared" +) + +func TestEvalRunNewWithOptionalParams(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.Evals.Runs.New( + context.TODO(), + "eval_id", + openai.EvalRunNewParams{ + DataSource: openai.EvalRunNewParamsDataSourceUnion{ + OfJSONLRunDataSource: &openai.CreateEvalJSONLRunDataSourceParam{ + Source: openai.CreateEvalJSONLRunDataSourceSourceUnionParam{ + OfFileContent: &openai.CreateEvalJSONLRunDataSourceSourceFileContentParam{ + Content: []openai.CreateEvalJSONLRunDataSourceSourceFileContentContentParam{{ + Item: map[string]interface{}{ + "foo": "bar", + }, + Sample: map[string]interface{}{ + "foo": "bar", + }, + }}, + }, + }, + }, + }, + Metadata: shared.MetadataParam{ + "foo": "string", + }, + Name: openai.String("name"), + }, + ) + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + +func TestEvalRunGet(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.Evals.Runs.Get( + context.TODO(), + "eval_id", + "run_id", + ) + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + +func TestEvalRunListWithOptionalParams(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.Evals.Runs.List( + context.TODO(), + "eval_id", + openai.EvalRunListParams{ + After: openai.String("after"), + Limit: openai.Int(0), + Order: openai.EvalRunListParamsOrderAsc, + Status: openai.EvalRunListParamsStatusQueued, + }, + ) + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + +func TestEvalRunDelete(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.Evals.Runs.Delete( + context.TODO(), + "eval_id", + "run_id", + ) + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + +func TestEvalRunCancel(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.Evals.Runs.Cancel( + context.TODO(), + "eval_id", + "run_id", + ) + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} diff --git a/evalrunoutputitem.go b/evalrunoutputitem.go new file mode 100644 index 00000000..6de35241 --- /dev/null +++ b/evalrunoutputitem.go @@ -0,0 +1,465 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package openai + +import ( + "context" + "errors" + "fmt" + "net/http" + "net/url" + + "github.com/openai/openai-go/internal/apijson" + "github.com/openai/openai-go/internal/apiquery" + "github.com/openai/openai-go/internal/requestconfig" + "github.com/openai/openai-go/option" + "github.com/openai/openai-go/packages/pagination" + "github.com/openai/openai-go/packages/param" + "github.com/openai/openai-go/packages/resp" + "github.com/openai/openai-go/shared/constant" +) + +// EvalRunOutputItemService contains methods and other services that help with +// interacting with the openai API. +// +// Note, unlike clients, this service does not read variables from the environment +// automatically. You should not instantiate this service directly, and instead use +// the [NewEvalRunOutputItemService] method instead. +type EvalRunOutputItemService struct { + Options []option.RequestOption +} + +// NewEvalRunOutputItemService generates a new service that applies the given +// options to each request. These options are applied after the parent client's +// options (if there is one), and before any request-specific options. +func NewEvalRunOutputItemService(opts ...option.RequestOption) (r EvalRunOutputItemService) { + r = EvalRunOutputItemService{} + r.Options = opts + return +} + +// Get an evaluation run output item by ID. +func (r *EvalRunOutputItemService) Get(ctx context.Context, evalID string, runID string, outputItemID string, opts ...option.RequestOption) (res *EvalRunOutputItemGetResponse, err error) { + opts = append(r.Options[:], opts...) + if evalID == "" { + err = errors.New("missing required eval_id parameter") + return + } + if runID == "" { + err = errors.New("missing required run_id parameter") + return + } + if outputItemID == "" { + err = errors.New("missing required output_item_id parameter") + return + } + path := fmt.Sprintf("evals/%s/runs/%s/output_items/%s", evalID, runID, outputItemID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) + return +} + +// Get a list of output items for an evaluation run. +func (r *EvalRunOutputItemService) List(ctx context.Context, evalID string, runID string, query EvalRunOutputItemListParams, opts ...option.RequestOption) (res *pagination.CursorPage[EvalRunOutputItemListResponse], err error) { + var raw *http.Response + opts = append(r.Options[:], opts...) + opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) + if evalID == "" { + err = errors.New("missing required eval_id parameter") + return + } + if runID == "" { + err = errors.New("missing required run_id parameter") + return + } + path := fmt.Sprintf("evals/%s/runs/%s/output_items", evalID, runID) + cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...) + if err != nil { + return nil, err + } + err = cfg.Execute() + if err != nil { + return nil, err + } + res.SetPageConfig(cfg, raw) + return res, nil +} + +// Get a list of output items for an evaluation run. +func (r *EvalRunOutputItemService) ListAutoPaging(ctx context.Context, evalID string, runID string, query EvalRunOutputItemListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[EvalRunOutputItemListResponse] { + return pagination.NewCursorPageAutoPager(r.List(ctx, evalID, runID, query, opts...)) +} + +// A schema representing an evaluation run output item. +type EvalRunOutputItemGetResponse struct { + // Unique identifier for the evaluation run output item. + ID string `json:"id,required"` + // Unix timestamp (in seconds) when the evaluation run was created. + CreatedAt int64 `json:"created_at,required"` + // Details of the input data source item. + DatasourceItem map[string]interface{} `json:"datasource_item,required"` + // The identifier for the data source item. + DatasourceItemID int64 `json:"datasource_item_id,required"` + // The identifier of the evaluation group. + EvalID string `json:"eval_id,required"` + // The type of the object. Always "eval.run.output_item". + Object constant.EvalRunOutputItem `json:"object,required"` + // A list of results from the evaluation run. + Results []map[string]interface{} `json:"results,required"` + // The identifier of the evaluation run associated with this output item. + RunID string `json:"run_id,required"` + // A sample containing the input and output of the evaluation run. + Sample EvalRunOutputItemGetResponseSample `json:"sample,required"` + // The status of the evaluation run. + Status string `json:"status,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + ID resp.Field + CreatedAt resp.Field + DatasourceItem resp.Field + DatasourceItemID resp.Field + EvalID resp.Field + Object resp.Field + Results resp.Field + RunID resp.Field + Sample resp.Field + Status resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunOutputItemGetResponse) RawJSON() string { return r.JSON.raw } +func (r *EvalRunOutputItemGetResponse) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// A sample containing the input and output of the evaluation run. +type EvalRunOutputItemGetResponseSample struct { + // An object representing an error response from the Eval API. + Error EvalAPIError `json:"error,required"` + // The reason why the sample generation was finished. + FinishReason string `json:"finish_reason,required"` + // An array of input messages. + Input []EvalRunOutputItemGetResponseSampleInput `json:"input,required"` + // The maximum number of tokens allowed for completion. + MaxCompletionTokens int64 `json:"max_completion_tokens,required"` + // The model used for generating the sample. + Model string `json:"model,required"` + // An array of output messages. + Output []EvalRunOutputItemGetResponseSampleOutput `json:"output,required"` + // The seed used for generating the sample. + Seed int64 `json:"seed,required"` + // The sampling temperature used. + Temperature float64 `json:"temperature,required"` + // The top_p value used for sampling. + TopP float64 `json:"top_p,required"` + // Token usage details for the sample. + Usage EvalRunOutputItemGetResponseSampleUsage `json:"usage,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Error resp.Field + FinishReason resp.Field + Input resp.Field + MaxCompletionTokens resp.Field + Model resp.Field + Output resp.Field + Seed resp.Field + Temperature resp.Field + TopP resp.Field + Usage resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunOutputItemGetResponseSample) RawJSON() string { return r.JSON.raw } +func (r *EvalRunOutputItemGetResponseSample) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// An input message. +type EvalRunOutputItemGetResponseSampleInput struct { + // The content of the message. + Content string `json:"content,required"` + // The role of the message sender (e.g., system, user, developer). + Role string `json:"role,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Content resp.Field + Role resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunOutputItemGetResponseSampleInput) RawJSON() string { return r.JSON.raw } +func (r *EvalRunOutputItemGetResponseSampleInput) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type EvalRunOutputItemGetResponseSampleOutput struct { + // The content of the message. + Content string `json:"content"` + // The role of the message (e.g. "system", "assistant", "user"). + Role string `json:"role"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Content resp.Field + Role resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunOutputItemGetResponseSampleOutput) RawJSON() string { return r.JSON.raw } +func (r *EvalRunOutputItemGetResponseSampleOutput) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// Token usage details for the sample. +type EvalRunOutputItemGetResponseSampleUsage struct { + // The number of tokens retrieved from cache. + CachedTokens int64 `json:"cached_tokens,required"` + // The number of completion tokens generated. + CompletionTokens int64 `json:"completion_tokens,required"` + // The number of prompt tokens used. + PromptTokens int64 `json:"prompt_tokens,required"` + // The total number of tokens used. + TotalTokens int64 `json:"total_tokens,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + CachedTokens resp.Field + CompletionTokens resp.Field + PromptTokens resp.Field + TotalTokens resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunOutputItemGetResponseSampleUsage) RawJSON() string { return r.JSON.raw } +func (r *EvalRunOutputItemGetResponseSampleUsage) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// A schema representing an evaluation run output item. +type EvalRunOutputItemListResponse struct { + // Unique identifier for the evaluation run output item. + ID string `json:"id,required"` + // Unix timestamp (in seconds) when the evaluation run was created. + CreatedAt int64 `json:"created_at,required"` + // Details of the input data source item. + DatasourceItem map[string]interface{} `json:"datasource_item,required"` + // The identifier for the data source item. + DatasourceItemID int64 `json:"datasource_item_id,required"` + // The identifier of the evaluation group. + EvalID string `json:"eval_id,required"` + // The type of the object. Always "eval.run.output_item". + Object constant.EvalRunOutputItem `json:"object,required"` + // A list of results from the evaluation run. + Results []map[string]interface{} `json:"results,required"` + // The identifier of the evaluation run associated with this output item. + RunID string `json:"run_id,required"` + // A sample containing the input and output of the evaluation run. + Sample EvalRunOutputItemListResponseSample `json:"sample,required"` + // The status of the evaluation run. + Status string `json:"status,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + ID resp.Field + CreatedAt resp.Field + DatasourceItem resp.Field + DatasourceItemID resp.Field + EvalID resp.Field + Object resp.Field + Results resp.Field + RunID resp.Field + Sample resp.Field + Status resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunOutputItemListResponse) RawJSON() string { return r.JSON.raw } +func (r *EvalRunOutputItemListResponse) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// A sample containing the input and output of the evaluation run. +type EvalRunOutputItemListResponseSample struct { + // An object representing an error response from the Eval API. + Error EvalAPIError `json:"error,required"` + // The reason why the sample generation was finished. + FinishReason string `json:"finish_reason,required"` + // An array of input messages. + Input []EvalRunOutputItemListResponseSampleInput `json:"input,required"` + // The maximum number of tokens allowed for completion. + MaxCompletionTokens int64 `json:"max_completion_tokens,required"` + // The model used for generating the sample. + Model string `json:"model,required"` + // An array of output messages. + Output []EvalRunOutputItemListResponseSampleOutput `json:"output,required"` + // The seed used for generating the sample. + Seed int64 `json:"seed,required"` + // The sampling temperature used. + Temperature float64 `json:"temperature,required"` + // The top_p value used for sampling. + TopP float64 `json:"top_p,required"` + // Token usage details for the sample. + Usage EvalRunOutputItemListResponseSampleUsage `json:"usage,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Error resp.Field + FinishReason resp.Field + Input resp.Field + MaxCompletionTokens resp.Field + Model resp.Field + Output resp.Field + Seed resp.Field + Temperature resp.Field + TopP resp.Field + Usage resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunOutputItemListResponseSample) RawJSON() string { return r.JSON.raw } +func (r *EvalRunOutputItemListResponseSample) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// An input message. +type EvalRunOutputItemListResponseSampleInput struct { + // The content of the message. + Content string `json:"content,required"` + // The role of the message sender (e.g., system, user, developer). + Role string `json:"role,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Content resp.Field + Role resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunOutputItemListResponseSampleInput) RawJSON() string { return r.JSON.raw } +func (r *EvalRunOutputItemListResponseSampleInput) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type EvalRunOutputItemListResponseSampleOutput struct { + // The content of the message. + Content string `json:"content"` + // The role of the message (e.g. "system", "assistant", "user"). + Role string `json:"role"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Content resp.Field + Role resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunOutputItemListResponseSampleOutput) RawJSON() string { return r.JSON.raw } +func (r *EvalRunOutputItemListResponseSampleOutput) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// Token usage details for the sample. +type EvalRunOutputItemListResponseSampleUsage struct { + // The number of tokens retrieved from cache. + CachedTokens int64 `json:"cached_tokens,required"` + // The number of completion tokens generated. + CompletionTokens int64 `json:"completion_tokens,required"` + // The number of prompt tokens used. + PromptTokens int64 `json:"prompt_tokens,required"` + // The total number of tokens used. + TotalTokens int64 `json:"total_tokens,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + CachedTokens resp.Field + CompletionTokens resp.Field + PromptTokens resp.Field + TotalTokens resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r EvalRunOutputItemListResponseSampleUsage) RawJSON() string { return r.JSON.raw } +func (r *EvalRunOutputItemListResponseSampleUsage) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type EvalRunOutputItemListParams struct { + // Identifier for the last output item from the previous pagination request. + After param.Opt[string] `query:"after,omitzero" json:"-"` + // Number of output items to retrieve. + Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` + // Sort order for output items by timestamp. Use `asc` for ascending order or + // `desc` for descending order. Defaults to `asc`. + // + // Any of "asc", "desc". + Order EvalRunOutputItemListParamsOrder `query:"order,omitzero" json:"-"` + // Filter output items by status. Use `failed` to filter by failed output items or + // `pass` to filter by passed output items. + // + // Any of "fail", "pass". + Status EvalRunOutputItemListParamsStatus `query:"status,omitzero" json:"-"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f EvalRunOutputItemListParams) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() } + +// URLQuery serializes [EvalRunOutputItemListParams]'s query parameters as +// `url.Values`. +func (r EvalRunOutputItemListParams) URLQuery() (v url.Values, err error) { + return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ + ArrayFormat: apiquery.ArrayQueryFormatBrackets, + NestedFormat: apiquery.NestedQueryFormatBrackets, + }) +} + +// Sort order for output items by timestamp. Use `asc` for ascending order or +// `desc` for descending order. Defaults to `asc`. +type EvalRunOutputItemListParamsOrder string + +const ( + EvalRunOutputItemListParamsOrderAsc EvalRunOutputItemListParamsOrder = "asc" + EvalRunOutputItemListParamsOrderDesc EvalRunOutputItemListParamsOrder = "desc" +) + +// Filter output items by status. Use `failed` to filter by failed output items or +// `pass` to filter by passed output items. +type EvalRunOutputItemListParamsStatus string + +const ( + EvalRunOutputItemListParamsStatusFail EvalRunOutputItemListParamsStatus = "fail" + EvalRunOutputItemListParamsStatusPass EvalRunOutputItemListParamsStatus = "pass" +) diff --git a/evalrunoutputitem_test.go b/evalrunoutputitem_test.go new file mode 100644 index 00000000..44faed6f --- /dev/null +++ b/evalrunoutputitem_test.go @@ -0,0 +1,73 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package openai_test + +import ( + "context" + "errors" + "os" + "testing" + + "github.com/openai/openai-go" + "github.com/openai/openai-go/internal/testutil" + "github.com/openai/openai-go/option" +) + +func TestEvalRunOutputItemGet(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.Evals.Runs.OutputItems.Get( + context.TODO(), + "eval_id", + "run_id", + "output_item_id", + ) + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + +func TestEvalRunOutputItemListWithOptionalParams(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.Evals.Runs.OutputItems.List( + context.TODO(), + "eval_id", + "run_id", + openai.EvalRunOutputItemListParams{ + After: openai.String("after"), + Limit: openai.Int(0), + Order: openai.EvalRunOutputItemListParamsOrderAsc, + Status: openai.EvalRunOutputItemListParamsStatusFail, + }, + ) + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} diff --git a/finetuning.go b/finetuning.go index 873e33c7..9132df0f 100644 --- a/finetuning.go +++ b/finetuning.go @@ -13,8 +13,9 @@ import ( // automatically. You should not instantiate this service directly, and instead use // the [NewFineTuningService] method instead. type FineTuningService struct { - Options []option.RequestOption - Jobs FineTuningJobService + Options []option.RequestOption + Jobs FineTuningJobService + Checkpoints FineTuningCheckpointService } // NewFineTuningService generates a new service that applies the given options to @@ -24,5 +25,6 @@ func NewFineTuningService(opts ...option.RequestOption) (r FineTuningService) { r = FineTuningService{} r.Options = opts r.Jobs = NewFineTuningJobService(opts...) + r.Checkpoints = NewFineTuningCheckpointService(opts...) return } diff --git a/finetuningcheckpoint.go b/finetuningcheckpoint.go new file mode 100644 index 00000000..11a485e7 --- /dev/null +++ b/finetuningcheckpoint.go @@ -0,0 +1,28 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package openai + +import ( + "github.com/openai/openai-go/option" +) + +// FineTuningCheckpointService contains methods and other services that help with +// interacting with the openai API. +// +// Note, unlike clients, this service does not read variables from the environment +// automatically. You should not instantiate this service directly, and instead use +// the [NewFineTuningCheckpointService] method instead. +type FineTuningCheckpointService struct { + Options []option.RequestOption + Permissions FineTuningCheckpointPermissionService +} + +// NewFineTuningCheckpointService generates a new service that applies the given +// options to each request. These options are applied after the parent client's +// options (if there is one), and before any request-specific options. +func NewFineTuningCheckpointService(opts ...option.RequestOption) (r FineTuningCheckpointService) { + r = FineTuningCheckpointService{} + r.Options = opts + r.Permissions = NewFineTuningCheckpointPermissionService(opts...) + return +} diff --git a/finetuningcheckpointpermission.go b/finetuningcheckpointpermission.go new file mode 100644 index 00000000..0b52b68e --- /dev/null +++ b/finetuningcheckpointpermission.go @@ -0,0 +1,263 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package openai + +import ( + "context" + "errors" + "fmt" + "net/http" + "net/url" + + "github.com/openai/openai-go/internal/apijson" + "github.com/openai/openai-go/internal/apiquery" + "github.com/openai/openai-go/internal/requestconfig" + "github.com/openai/openai-go/option" + "github.com/openai/openai-go/packages/pagination" + "github.com/openai/openai-go/packages/param" + "github.com/openai/openai-go/packages/resp" + "github.com/openai/openai-go/shared/constant" +) + +// FineTuningCheckpointPermissionService contains methods and other services that +// help with interacting with the openai API. +// +// Note, unlike clients, this service does not read variables from the environment +// automatically. You should not instantiate this service directly, and instead use +// the [NewFineTuningCheckpointPermissionService] method instead. +type FineTuningCheckpointPermissionService struct { + Options []option.RequestOption +} + +// NewFineTuningCheckpointPermissionService generates a new service that applies +// the given options to each request. These options are applied after the parent +// client's options (if there is one), and before any request-specific options. +func NewFineTuningCheckpointPermissionService(opts ...option.RequestOption) (r FineTuningCheckpointPermissionService) { + r = FineTuningCheckpointPermissionService{} + r.Options = opts + return +} + +// **NOTE:** Calling this endpoint requires an [admin API key](../admin-api-keys). +// +// This enables organization owners to share fine-tuned models with other projects +// in their organization. +func (r *FineTuningCheckpointPermissionService) New(ctx context.Context, fineTunedModelCheckpoint string, body FineTuningCheckpointPermissionNewParams, opts ...option.RequestOption) (res *pagination.Page[FineTuningCheckpointPermissionNewResponse], err error) { + var raw *http.Response + opts = append(r.Options[:], opts...) + opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) + if fineTunedModelCheckpoint == "" { + err = errors.New("missing required fine_tuned_model_checkpoint parameter") + return + } + path := fmt.Sprintf("fine_tuning/checkpoints/%s/permissions", fineTunedModelCheckpoint) + cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodPost, path, body, &res, opts...) + if err != nil { + return nil, err + } + err = cfg.Execute() + if err != nil { + return nil, err + } + res.SetPageConfig(cfg, raw) + return res, nil +} + +// **NOTE:** Calling this endpoint requires an [admin API key](../admin-api-keys). +// +// This enables organization owners to share fine-tuned models with other projects +// in their organization. +func (r *FineTuningCheckpointPermissionService) NewAutoPaging(ctx context.Context, fineTunedModelCheckpoint string, body FineTuningCheckpointPermissionNewParams, opts ...option.RequestOption) *pagination.PageAutoPager[FineTuningCheckpointPermissionNewResponse] { + return pagination.NewPageAutoPager(r.New(ctx, fineTunedModelCheckpoint, body, opts...)) +} + +// **NOTE:** This endpoint requires an [admin API key](../admin-api-keys). +// +// Organization owners can use this endpoint to view all permissions for a +// fine-tuned model checkpoint. +func (r *FineTuningCheckpointPermissionService) Get(ctx context.Context, fineTunedModelCheckpoint string, query FineTuningCheckpointPermissionGetParams, opts ...option.RequestOption) (res *FineTuningCheckpointPermissionGetResponse, err error) { + opts = append(r.Options[:], opts...) + if fineTunedModelCheckpoint == "" { + err = errors.New("missing required fine_tuned_model_checkpoint parameter") + return + } + path := fmt.Sprintf("fine_tuning/checkpoints/%s/permissions", fineTunedModelCheckpoint) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...) + return +} + +// **NOTE:** This endpoint requires an [admin API key](../admin-api-keys). +// +// Organization owners can use this endpoint to delete a permission for a +// fine-tuned model checkpoint. +func (r *FineTuningCheckpointPermissionService) Delete(ctx context.Context, fineTunedModelCheckpoint string, opts ...option.RequestOption) (res *FineTuningCheckpointPermissionDeleteResponse, err error) { + opts = append(r.Options[:], opts...) + if fineTunedModelCheckpoint == "" { + err = errors.New("missing required fine_tuned_model_checkpoint parameter") + return + } + path := fmt.Sprintf("fine_tuning/checkpoints/%s/permissions", fineTunedModelCheckpoint) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...) + return +} + +// The `checkpoint.permission` object represents a permission for a fine-tuned +// model checkpoint. +type FineTuningCheckpointPermissionNewResponse struct { + // The permission identifier, which can be referenced in the API endpoints. + ID string `json:"id,required"` + // The Unix timestamp (in seconds) for when the permission was created. + CreatedAt int64 `json:"created_at,required"` + // The object type, which is always "checkpoint.permission". + Object constant.CheckpointPermission `json:"object,required"` + // The project identifier that the permission is for. + ProjectID string `json:"project_id,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + ID resp.Field + CreatedAt resp.Field + Object resp.Field + ProjectID resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r FineTuningCheckpointPermissionNewResponse) RawJSON() string { return r.JSON.raw } +func (r *FineTuningCheckpointPermissionNewResponse) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type FineTuningCheckpointPermissionGetResponse struct { + Data []FineTuningCheckpointPermissionGetResponseData `json:"data,required"` + HasMore bool `json:"has_more,required"` + Object constant.List `json:"object,required"` + FirstID string `json:"first_id,nullable"` + LastID string `json:"last_id,nullable"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + Data resp.Field + HasMore resp.Field + Object resp.Field + FirstID resp.Field + LastID resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r FineTuningCheckpointPermissionGetResponse) RawJSON() string { return r.JSON.raw } +func (r *FineTuningCheckpointPermissionGetResponse) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// The `checkpoint.permission` object represents a permission for a fine-tuned +// model checkpoint. +type FineTuningCheckpointPermissionGetResponseData struct { + // The permission identifier, which can be referenced in the API endpoints. + ID string `json:"id,required"` + // The Unix timestamp (in seconds) for when the permission was created. + CreatedAt int64 `json:"created_at,required"` + // The object type, which is always "checkpoint.permission". + Object constant.CheckpointPermission `json:"object,required"` + // The project identifier that the permission is for. + ProjectID string `json:"project_id,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + ID resp.Field + CreatedAt resp.Field + Object resp.Field + ProjectID resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r FineTuningCheckpointPermissionGetResponseData) RawJSON() string { return r.JSON.raw } +func (r *FineTuningCheckpointPermissionGetResponseData) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type FineTuningCheckpointPermissionDeleteResponse struct { + // The ID of the fine-tuned model checkpoint permission that was deleted. + ID string `json:"id,required"` + // Whether the fine-tuned model checkpoint permission was successfully deleted. + Deleted bool `json:"deleted,required"` + // The object type, which is always "checkpoint.permission". + Object constant.CheckpointPermission `json:"object,required"` + // Metadata for the response, check the presence of optional fields with the + // [resp.Field.IsPresent] method. + JSON struct { + ID resp.Field + Deleted resp.Field + Object resp.Field + ExtraFields map[string]resp.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r FineTuningCheckpointPermissionDeleteResponse) RawJSON() string { return r.JSON.raw } +func (r *FineTuningCheckpointPermissionDeleteResponse) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type FineTuningCheckpointPermissionNewParams struct { + // The project identifiers to grant access to. + ProjectIDs []string `json:"project_ids,omitzero,required"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f FineTuningCheckpointPermissionNewParams) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} + +func (r FineTuningCheckpointPermissionNewParams) MarshalJSON() (data []byte, err error) { + type shadow FineTuningCheckpointPermissionNewParams + return param.MarshalObject(r, (*shadow)(&r)) +} + +type FineTuningCheckpointPermissionGetParams struct { + // Identifier for the last permission ID from the previous pagination request. + After param.Opt[string] `query:"after,omitzero" json:"-"` + // Number of permissions to retrieve. + Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` + // The ID of the project to get permissions for. + ProjectID param.Opt[string] `query:"project_id,omitzero" json:"-"` + // The order in which to retrieve permissions. + // + // Any of "ascending", "descending". + Order FineTuningCheckpointPermissionGetParamsOrder `query:"order,omitzero" json:"-"` + paramObj +} + +// IsPresent returns true if the field's value is not omitted and not the JSON +// "null". To check if this field is omitted, use [param.IsOmitted]. +func (f FineTuningCheckpointPermissionGetParams) IsPresent() bool { + return !param.IsOmitted(f) && !f.IsNull() +} + +// URLQuery serializes [FineTuningCheckpointPermissionGetParams]'s query parameters +// as `url.Values`. +func (r FineTuningCheckpointPermissionGetParams) URLQuery() (v url.Values, err error) { + return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ + ArrayFormat: apiquery.ArrayQueryFormatBrackets, + NestedFormat: apiquery.NestedQueryFormatBrackets, + }) +} + +// The order in which to retrieve permissions. +type FineTuningCheckpointPermissionGetParamsOrder string + +const ( + FineTuningCheckpointPermissionGetParamsOrderAscending FineTuningCheckpointPermissionGetParamsOrder = "ascending" + FineTuningCheckpointPermissionGetParamsOrderDescending FineTuningCheckpointPermissionGetParamsOrder = "descending" +) diff --git a/finetuningcheckpointpermission_test.go b/finetuningcheckpointpermission_test.go new file mode 100644 index 00000000..651c732e --- /dev/null +++ b/finetuningcheckpointpermission_test.go @@ -0,0 +1,95 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package openai_test + +import ( + "context" + "errors" + "os" + "testing" + + "github.com/openai/openai-go" + "github.com/openai/openai-go/internal/testutil" + "github.com/openai/openai-go/option" +) + +func TestFineTuningCheckpointPermissionNew(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.FineTuning.Checkpoints.Permissions.New( + context.TODO(), + "ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd", + openai.FineTuningCheckpointPermissionNewParams{ + ProjectIDs: []string{"string"}, + }, + ) + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + +func TestFineTuningCheckpointPermissionGetWithOptionalParams(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.FineTuning.Checkpoints.Permissions.Get( + context.TODO(), + "ft-AF1WoRqd3aJAHsqc9NY7iL8F", + openai.FineTuningCheckpointPermissionGetParams{ + After: openai.String("after"), + Limit: openai.Int(0), + Order: openai.FineTuningCheckpointPermissionGetParamsOrderAscending, + ProjectID: openai.String("project_id"), + }, + ) + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + +func TestFineTuningCheckpointPermissionDelete(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.FineTuning.Checkpoints.Permissions.Delete(context.TODO(), "ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd") + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} diff --git a/responses/response.go b/responses/response.go index 89f6d237..b29f0d6b 100644 --- a/responses/response.go +++ b/responses/response.go @@ -5288,7 +5288,7 @@ const ( // The properties ID, Content, Role, Status, Type are required. type ResponseOutputMessageParam struct { // The unique ID of the output message. - ID string `json:"id,omitzero,required"` + ID string `json:"id,required"` // The content of the output message. Content []ResponseOutputMessageContentUnionParam `json:"content,omitzero,required"` // The status of the message input. One of `in_progress`, `completed`, or diff --git a/shared/constant/constants.go b/shared/constant/constants.go index 341ff23c..185b6267 100644 --- a/shared/constant/constants.go +++ b/shared/constant/constants.go @@ -26,6 +26,7 @@ type Batch string // Always "batch" type ChatCompletion string // Always "chat.completion" type ChatCompletionChunk string // Always "chat.completion.chunk" type ChatCompletionDeleted string // Always "chat.completion.deleted" +type CheckpointPermission string // Always "checkpoint.permission" type Click string // Always "click" type CodeInterpreter string // Always "code_interpreter" type CodeInterpreterCall string // Always "code_interpreter_call" @@ -33,13 +34,19 @@ type ComputerCallOutput string // Always "computer_call_out type ComputerScreenshot string // Always "computer_screenshot" type ComputerUsePreview string // Always "computer_use_preview" type Content string // Always "content" +type Custom string // Always "custom" type Developer string // Always "developer" type DoubleClick string // Always "double_click" type Drag string // Always "drag" type Embedding string // Always "embedding" type Error string // Always "error" +type Eval string // Always "eval" +type EvalRun string // Always "eval.run" +type EvalRunOutputItem string // Always "eval.run.output_item" type File string // Always "file" type FileCitation string // Always "file_citation" +type FileContent string // Always "file_content" +type FileID string // Always "file_id" type FilePath string // Always "file_path" type FileSearch string // Always "file_search" type FileSearchCall string // Always "file_search_call" @@ -60,7 +67,9 @@ type InputText string // Always "input_text" type ItemReference string // Always "item_reference" type JSONObject string // Always "json_object" type JSONSchema string // Always "json_schema" +type JSONL string // Always "jsonl" type Keypress string // Always "keypress" +type LabelModel string // Always "label_model" type LastActiveAt string // Always "last_active_at" type List string // Always "list" type Logs string // Always "logs" @@ -108,11 +117,15 @@ type ResponseWebSearchCallSearching string // Always "response.web_sear type Screenshot string // Always "screenshot" type Scroll string // Always "scroll" type Static string // Always "static" +type StoredCompletions string // Always "stored_completions" +type StringCheck string // Always "string_check" type SubmitToolOutputs string // Always "submit_tool_outputs" type SummaryText string // Always "summary_text" type System string // Always "system" +type Template string // Always "template" type Text string // Always "text" type TextCompletion string // Always "text_completion" +type TextSimilarity string // Always "text_similarity" type Thread string // Always "thread" type ThreadCreated string // Always "thread.created" type ThreadDeleted string // Always "thread.deleted" @@ -170,6 +183,7 @@ func (c Batch) Default() Batch { return "batch" func (c ChatCompletion) Default() ChatCompletion { return "chat.completion" } func (c ChatCompletionChunk) Default() ChatCompletionChunk { return "chat.completion.chunk" } func (c ChatCompletionDeleted) Default() ChatCompletionDeleted { return "chat.completion.deleted" } +func (c CheckpointPermission) Default() CheckpointPermission { return "checkpoint.permission" } func (c Click) Default() Click { return "click" } func (c CodeInterpreter) Default() CodeInterpreter { return "code_interpreter" } func (c CodeInterpreterCall) Default() CodeInterpreterCall { return "code_interpreter_call" } @@ -177,13 +191,19 @@ func (c ComputerCallOutput) Default() ComputerCallOutput { return "compute func (c ComputerScreenshot) Default() ComputerScreenshot { return "computer_screenshot" } func (c ComputerUsePreview) Default() ComputerUsePreview { return "computer_use_preview" } func (c Content) Default() Content { return "content" } +func (c Custom) Default() Custom { return "custom" } func (c Developer) Default() Developer { return "developer" } func (c DoubleClick) Default() DoubleClick { return "double_click" } func (c Drag) Default() Drag { return "drag" } func (c Embedding) Default() Embedding { return "embedding" } func (c Error) Default() Error { return "error" } +func (c Eval) Default() Eval { return "eval" } +func (c EvalRun) Default() EvalRun { return "eval.run" } +func (c EvalRunOutputItem) Default() EvalRunOutputItem { return "eval.run.output_item" } func (c File) Default() File { return "file" } func (c FileCitation) Default() FileCitation { return "file_citation" } +func (c FileContent) Default() FileContent { return "file_content" } +func (c FileID) Default() FileID { return "file_id" } func (c FilePath) Default() FilePath { return "file_path" } func (c FileSearch) Default() FileSearch { return "file_search" } func (c FileSearchCall) Default() FileSearchCall { return "file_search_call" } @@ -206,7 +226,9 @@ func (c InputText) Default() InputText { return "input_text" } func (c ItemReference) Default() ItemReference { return "item_reference" } func (c JSONObject) Default() JSONObject { return "json_object" } func (c JSONSchema) Default() JSONSchema { return "json_schema" } +func (c JSONL) Default() JSONL { return "jsonl" } func (c Keypress) Default() Keypress { return "keypress" } +func (c LabelModel) Default() LabelModel { return "label_model" } func (c LastActiveAt) Default() LastActiveAt { return "last_active_at" } func (c List) Default() List { return "list" } func (c Logs) Default() Logs { return "logs" } @@ -294,11 +316,15 @@ func (c ResponseWebSearchCallSearching) Default() ResponseWebSearchCallSearching func (c Screenshot) Default() Screenshot { return "screenshot" } func (c Scroll) Default() Scroll { return "scroll" } func (c Static) Default() Static { return "static" } +func (c StoredCompletions) Default() StoredCompletions { return "stored_completions" } +func (c StringCheck) Default() StringCheck { return "string_check" } func (c SubmitToolOutputs) Default() SubmitToolOutputs { return "submit_tool_outputs" } func (c SummaryText) Default() SummaryText { return "summary_text" } func (c System) Default() System { return "system" } +func (c Template) Default() Template { return "template" } func (c Text) Default() Text { return "text" } func (c TextCompletion) Default() TextCompletion { return "text_completion" } +func (c TextSimilarity) Default() TextSimilarity { return "text_similarity" } func (c Thread) Default() Thread { return "thread" } func (c ThreadCreated) Default() ThreadCreated { return "thread.created" } func (c ThreadDeleted) Default() ThreadDeleted { return "thread.deleted" } @@ -368,6 +394,7 @@ func (c Batch) MarshalJSON() ([]byte, error) { r func (c ChatCompletion) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c ChatCompletionChunk) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c ChatCompletionDeleted) MarshalJSON() ([]byte, error) { return marshalString(c) } +func (c CheckpointPermission) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c Click) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c CodeInterpreter) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c CodeInterpreterCall) MarshalJSON() ([]byte, error) { return marshalString(c) } @@ -375,13 +402,19 @@ func (c ComputerCallOutput) MarshalJSON() ([]byte, error) { r func (c ComputerScreenshot) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c ComputerUsePreview) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c Content) MarshalJSON() ([]byte, error) { return marshalString(c) } +func (c Custom) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c Developer) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c DoubleClick) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c Drag) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c Embedding) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c Error) MarshalJSON() ([]byte, error) { return marshalString(c) } +func (c Eval) MarshalJSON() ([]byte, error) { return marshalString(c) } +func (c EvalRun) MarshalJSON() ([]byte, error) { return marshalString(c) } +func (c EvalRunOutputItem) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c File) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c FileCitation) MarshalJSON() ([]byte, error) { return marshalString(c) } +func (c FileContent) MarshalJSON() ([]byte, error) { return marshalString(c) } +func (c FileID) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c FilePath) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c FileSearch) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c FileSearchCall) MarshalJSON() ([]byte, error) { return marshalString(c) } @@ -402,7 +435,9 @@ func (c InputText) MarshalJSON() ([]byte, error) { r func (c ItemReference) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c JSONObject) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c JSONSchema) MarshalJSON() ([]byte, error) { return marshalString(c) } +func (c JSONL) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c Keypress) MarshalJSON() ([]byte, error) { return marshalString(c) } +func (c LabelModel) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c LastActiveAt) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c List) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c Logs) MarshalJSON() ([]byte, error) { return marshalString(c) } @@ -452,11 +487,15 @@ func (c ResponseWebSearchCallSearching) MarshalJSON() ([]byte, error) { retu func (c Screenshot) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c Scroll) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c Static) MarshalJSON() ([]byte, error) { return marshalString(c) } +func (c StoredCompletions) MarshalJSON() ([]byte, error) { return marshalString(c) } +func (c StringCheck) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c SubmitToolOutputs) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c SummaryText) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c System) MarshalJSON() ([]byte, error) { return marshalString(c) } +func (c Template) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c Text) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c TextCompletion) MarshalJSON() ([]byte, error) { return marshalString(c) } +func (c TextSimilarity) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c Thread) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c ThreadCreated) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c ThreadDeleted) MarshalJSON() ([]byte, error) { return marshalString(c) } From 5e86f0f2734a9898584a250b5052403172f331ba Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 8 Apr 2025 19:44:34 +0000 Subject: [PATCH 6/9] chore(internal): fix examples (#361) --- .stats.yml | 4 +- eval_test.go | 141 +-------------------------------------------------- 2 files changed, 3 insertions(+), 142 deletions(-) diff --git a/.stats.yml b/.stats.yml index 43112911..50574f0d 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 95 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-472fe3036ea745365257fe870c0330917fb3153705c2826f49873cd631319b0a.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-32de3bc513663c5fac922c49be41c222b6ee8c0b841d8966bcdfa489d441daa3.yml openapi_spec_hash: ea86343b5e9858a74e85da8ab2c532f6 -config_hash: ef19d36c307306f14f2e1cd5c834a151 +config_hash: d6c61213488683418adb860a9ee1501b diff --git a/eval_test.go b/eval_test.go index 46da2cae..be4ce96e 100644 --- a/eval_test.go +++ b/eval_test.go @@ -30,146 +30,7 @@ func TestEvalNewWithOptionalParams(t *testing.T) { DataSourceConfig: openai.EvalNewParamsDataSourceConfigUnion{ OfCustom: &openai.EvalNewParamsDataSourceConfigCustom{ ItemSchema: map[string]interface{}{ - "0": "bar", - "1": "bar", - "2": "bar", - "3": "bar", - "4": "bar", - "5": "bar", - "6": "bar", - "7": "bar", - "8": "bar", - "9": "bar", - "10": "bar", - "11": "bar", - "12": "bar", - "13": "bar", - "14": "bar", - "15": "bar", - "16": "bar", - "17": "bar", - "18": "bar", - "19": "bar", - "20": "bar", - "21": "bar", - "22": "bar", - "23": "bar", - "24": "bar", - "25": "bar", - "26": "bar", - "27": "bar", - "28": "bar", - "29": "bar", - "30": "bar", - "31": "bar", - "32": "bar", - "33": "bar", - "34": "bar", - "35": "bar", - "36": "bar", - "37": "bar", - "38": "bar", - "39": "bar", - "40": "bar", - "41": "bar", - "42": "bar", - "43": "bar", - "44": "bar", - "45": "bar", - "46": "bar", - "47": "bar", - "48": "bar", - "49": "bar", - "50": "bar", - "51": "bar", - "52": "bar", - "53": "bar", - "54": "bar", - "55": "bar", - "56": "bar", - "57": "bar", - "58": "bar", - "59": "bar", - "60": "bar", - "61": "bar", - "62": "bar", - "63": "bar", - "64": "bar", - "65": "bar", - "66": "bar", - "67": "bar", - "68": "bar", - "69": "bar", - "70": "bar", - "71": "bar", - "72": "bar", - "73": "bar", - "74": "bar", - "75": "bar", - "76": "bar", - "77": "bar", - "78": "bar", - "79": "bar", - "80": "bar", - "81": "bar", - "82": "bar", - "83": "bar", - "84": "bar", - "85": "bar", - "86": "bar", - "87": "bar", - "88": "bar", - "89": "bar", - "90": "bar", - "91": "bar", - "92": "bar", - "93": "bar", - "94": "bar", - "95": "bar", - "96": "bar", - "97": "bar", - "98": "bar", - "99": "bar", - "100": "bar", - "101": "bar", - "102": "bar", - "103": "bar", - "104": "bar", - "105": "bar", - "106": "bar", - "107": "bar", - "108": "bar", - "109": "bar", - "110": "bar", - "111": "bar", - "112": "bar", - "113": "bar", - "114": "bar", - "115": "bar", - "116": "bar", - "117": "bar", - "118": "bar", - "119": "bar", - "120": "bar", - "121": "bar", - "122": "bar", - "123": "bar", - "124": "bar", - "125": "bar", - "126": "bar", - "127": "bar", - "128": "bar", - "129": "bar", - "130": "bar", - "131": "bar", - "132": "bar", - "133": "bar", - "134": "bar", - "135": "bar", - "136": "bar", - "137": "bar", - "138": "bar", - "139": "bar", + "foo": "bar", }, IncludeSampleSchema: openai.Bool(true), }, From 8599318b87e59ea0550da8c8451dd12c6716776f Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 8 Apr 2025 19:46:18 +0000 Subject: [PATCH 7/9] chore(internal): skip broken test (#362) --- .stats.yml | 2 +- finetuningcheckpointpermission_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.stats.yml b/.stats.yml index 50574f0d..71a56c4c 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 95 openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-32de3bc513663c5fac922c49be41c222b6ee8c0b841d8966bcdfa489d441daa3.yml openapi_spec_hash: ea86343b5e9858a74e85da8ab2c532f6 -config_hash: d6c61213488683418adb860a9ee1501b +config_hash: 43dc8df20ffec9d1503f91866cb2b7d9 diff --git a/finetuningcheckpointpermission_test.go b/finetuningcheckpointpermission_test.go index 651c732e..a094ac54 100644 --- a/finetuningcheckpointpermission_test.go +++ b/finetuningcheckpointpermission_test.go @@ -73,6 +73,7 @@ func TestFineTuningCheckpointPermissionGetWithOptionalParams(t *testing.T) { } func TestFineTuningCheckpointPermissionDelete(t *testing.T) { + t.Skip("OpenAPI spec is slightly incorrect") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { baseURL = envURL From 68c32a0aec380926b962ed74d4002a883d012dcd Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 8 Apr 2025 20:05:08 +0000 Subject: [PATCH 8/9] feat(api): manual updates (#363) --- .stats.yml | 4 ++-- responses/response.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.stats.yml b/.stats.yml index 71a56c4c..037cba0b 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 95 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-32de3bc513663c5fac922c49be41c222b6ee8c0b841d8966bcdfa489d441daa3.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-44b20fa9d24544217fe6bb48852037537030a1ad29b202936425110744fe66fb.yml openapi_spec_hash: ea86343b5e9858a74e85da8ab2c532f6 -config_hash: 43dc8df20ffec9d1503f91866cb2b7d9 +config_hash: 69e3afd56ccb0f0f822a7a9dc130fc99 diff --git a/responses/response.go b/responses/response.go index b29f0d6b..89f6d237 100644 --- a/responses/response.go +++ b/responses/response.go @@ -5288,7 +5288,7 @@ const ( // The properties ID, Content, Role, Status, Type are required. type ResponseOutputMessageParam struct { // The unique ID of the output message. - ID string `json:"id,required"` + ID string `json:"id,omitzero,required"` // The content of the output message. Content []ResponseOutputMessageContentUnionParam `json:"content,omitzero,required"` // The status of the message input. One of `in_progress`, `completed`, or From 0ae103de4e01e5239788a56fca3d7621b83460ab Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 9 Apr 2025 05:07:15 +0000 Subject: [PATCH 9/9] release: 0.1.0-beta.8 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 19 +++++++++++++++++++ README.md | 2 +- internal/version.go | 2 +- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 54d80883..f6be4b47 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.1.0-beta.7" + ".": "0.1.0-beta.8" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d01448d..dc0df6ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,24 @@ # Changelog +## 0.1.0-beta.8 (2025-04-09) + +Full Changelog: [v0.1.0-beta.7...v0.1.0-beta.8](https://github.com/openai/openai-go/compare/v0.1.0-beta.7...v0.1.0-beta.8) + +### Features + +* **api:** Add evalapi to sdk ([#360](https://github.com/openai/openai-go/issues/360)) ([88977d1](https://github.com/openai/openai-go/commit/88977d1868dbbe0060c56ba5dac8eb19773e4938)) +* **api:** manual updates ([#363](https://github.com/openai/openai-go/issues/363)) ([5d068e0](https://github.com/openai/openai-go/commit/5d068e0053172db7f5b75038aa215eee074eeeed)) +* **client:** add escape hatch to omit required param fields ([#354](https://github.com/openai/openai-go/issues/354)) ([9690d6b](https://github.com/openai/openai-go/commit/9690d6b49f8b00329afc038ec15116750853e620)) +* **client:** support custom http clients ([#357](https://github.com/openai/openai-go/issues/357)) ([b5a624f](https://github.com/openai/openai-go/commit/b5a624f658cad774094427b36b05e446b41e8c52)) + + +### Chores + +* **docs:** readme improvements ([#356](https://github.com/openai/openai-go/issues/356)) ([b2f8539](https://github.com/openai/openai-go/commit/b2f8539d6316e3443aa733be2c95926696119c13)) +* **internal:** fix examples ([#361](https://github.com/openai/openai-go/issues/361)) ([de398b4](https://github.com/openai/openai-go/commit/de398b453d398299eb80c15f8fdb2bcbef5eeed6)) +* **internal:** skip broken test ([#362](https://github.com/openai/openai-go/issues/362)) ([cccead9](https://github.com/openai/openai-go/commit/cccead9ba916142ac8fbe6e8926d706511e32ae3)) +* **tests:** improve enum examples ([#359](https://github.com/openai/openai-go/issues/359)) ([e0b9739](https://github.com/openai/openai-go/commit/e0b9739920114d6e991d3947b67fdf62cfaa09c7)) + ## 0.1.0-beta.7 (2025-04-07) Full Changelog: [v0.1.0-beta.6...v0.1.0-beta.7](https://github.com/openai/openai-go/compare/v0.1.0-beta.6...v0.1.0-beta.7) diff --git a/README.md b/README.md index f659b569..7e7e1586 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Or to pin the version: ```sh -go get -u 'github.com/openai/openai-go@v0.1.0-beta.7' +go get -u 'github.com/openai/openai-go@v0.1.0-beta.8' ``` diff --git a/internal/version.go b/internal/version.go index 200c4d35..dafc3dab 100644 --- a/internal/version.go +++ b/internal/version.go @@ -2,4 +2,4 @@ package internal -const PackageVersion = "0.1.0-beta.7" // x-release-please-version +const PackageVersion = "0.1.0-beta.8" // x-release-please-version