1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3package openai
4
5import (
6 "encoding/json"
7
8 "github.com/openai/openai-go/internal/apijson"
9 "github.com/openai/openai-go/option"
10 "github.com/openai/openai-go/packages/param"
11 "github.com/openai/openai-go/packages/respjson"
12 "github.com/openai/openai-go/responses"
13 "github.com/openai/openai-go/shared/constant"
14)
15
16// GraderGraderModelService contains methods and other services that help with
17// interacting with the openai API.
18//
19// Note, unlike clients, this service does not read variables from the environment
20// automatically. You should not instantiate this service directly, and instead use
21// the [NewGraderGraderModelService] method instead.
22type GraderGraderModelService struct {
23 Options []option.RequestOption
24}
25
26// NewGraderGraderModelService generates a new service that applies the given
27// options to each request. These options are applied after the parent client's
28// options (if there is one), and before any request-specific options.
29func NewGraderGraderModelService(opts ...option.RequestOption) (r GraderGraderModelService) {
30 r = GraderGraderModelService{}
31 r.Options = opts
32 return
33}
34
35// A LabelModelGrader object which uses a model to assign labels to each item in
36// the evaluation.
37type LabelModelGrader struct {
38 Input []LabelModelGraderInput `json:"input,required"`
39 // The labels to assign to each item in the evaluation.
40 Labels []string `json:"labels,required"`
41 // The model to use for the evaluation. Must support structured outputs.
42 Model string `json:"model,required"`
43 // The name of the grader.
44 Name string `json:"name,required"`
45 // The labels that indicate a passing result. Must be a subset of labels.
46 PassingLabels []string `json:"passing_labels,required"`
47 // The object type, which is always `label_model`.
48 Type constant.LabelModel `json:"type,required"`
49 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
50 JSON struct {
51 Input respjson.Field
52 Labels respjson.Field
53 Model respjson.Field
54 Name respjson.Field
55 PassingLabels respjson.Field
56 Type respjson.Field
57 ExtraFields map[string]respjson.Field
58 raw string
59 } `json:"-"`
60}
61
62// Returns the unmodified JSON received from the API
63func (r LabelModelGrader) RawJSON() string { return r.JSON.raw }
64func (r *LabelModelGrader) UnmarshalJSON(data []byte) error {
65 return apijson.UnmarshalRoot(data, r)
66}
67
68// ToParam converts this LabelModelGrader to a LabelModelGraderParam.
69//
70// Warning: the fields of the param type will not be present. ToParam should only
71// be used at the last possible moment before sending a request. Test for this with
72// LabelModelGraderParam.Overrides()
73func (r LabelModelGrader) ToParam() LabelModelGraderParam {
74 return param.Override[LabelModelGraderParam](json.RawMessage(r.RawJSON()))
75}
76
77// A message input to the model with a role indicating instruction following
78// hierarchy. Instructions given with the `developer` or `system` role take
79// precedence over instructions given with the `user` role. Messages with the
80// `assistant` role are presumed to have been generated by the model in previous
81// interactions.
82type LabelModelGraderInput struct {
83 // Text inputs to the model - can contain template strings.
84 Content LabelModelGraderInputContentUnion `json:"content,required"`
85 // The role of the message input. One of `user`, `assistant`, `system`, or
86 // `developer`.
87 //
88 // Any of "user", "assistant", "system", "developer".
89 Role string `json:"role,required"`
90 // The type of the message input. Always `message`.
91 //
92 // Any of "message".
93 Type string `json:"type"`
94 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
95 JSON struct {
96 Content respjson.Field
97 Role respjson.Field
98 Type respjson.Field
99 ExtraFields map[string]respjson.Field
100 raw string
101 } `json:"-"`
102}
103
104// Returns the unmodified JSON received from the API
105func (r LabelModelGraderInput) RawJSON() string { return r.JSON.raw }
106func (r *LabelModelGraderInput) UnmarshalJSON(data []byte) error {
107 return apijson.UnmarshalRoot(data, r)
108}
109
110// LabelModelGraderInputContentUnion contains all possible properties and values
111// from [string], [responses.ResponseInputText],
112// [LabelModelGraderInputContentOutputText].
113//
114// Use the methods beginning with 'As' to cast the union to one of its variants.
115//
116// If the underlying value is not a json object, one of the following properties
117// will be valid: OfString]
118type LabelModelGraderInputContentUnion struct {
119 // This field will be present if the value is a [string] instead of an object.
120 OfString string `json:",inline"`
121 Text string `json:"text"`
122 Type string `json:"type"`
123 JSON struct {
124 OfString respjson.Field
125 Text respjson.Field
126 Type respjson.Field
127 raw string
128 } `json:"-"`
129}
130
131func (u LabelModelGraderInputContentUnion) AsString() (v string) {
132 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
133 return
134}
135
136func (u LabelModelGraderInputContentUnion) AsInputText() (v responses.ResponseInputText) {
137 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
138 return
139}
140
141func (u LabelModelGraderInputContentUnion) AsOutputText() (v LabelModelGraderInputContentOutputText) {
142 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
143 return
144}
145
146// Returns the unmodified JSON received from the API
147func (u LabelModelGraderInputContentUnion) RawJSON() string { return u.JSON.raw }
148
149func (r *LabelModelGraderInputContentUnion) UnmarshalJSON(data []byte) error {
150 return apijson.UnmarshalRoot(data, r)
151}
152
153// A text output from the model.
154type LabelModelGraderInputContentOutputText struct {
155 // The text output from the model.
156 Text string `json:"text,required"`
157 // The type of the output text. Always `output_text`.
158 Type constant.OutputText `json:"type,required"`
159 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
160 JSON struct {
161 Text respjson.Field
162 Type respjson.Field
163 ExtraFields map[string]respjson.Field
164 raw string
165 } `json:"-"`
166}
167
168// Returns the unmodified JSON received from the API
169func (r LabelModelGraderInputContentOutputText) RawJSON() string { return r.JSON.raw }
170func (r *LabelModelGraderInputContentOutputText) UnmarshalJSON(data []byte) error {
171 return apijson.UnmarshalRoot(data, r)
172}
173
174// A LabelModelGrader object which uses a model to assign labels to each item in
175// the evaluation.
176//
177// The properties Input, Labels, Model, Name, PassingLabels, Type are required.
178type LabelModelGraderParam struct {
179 Input []LabelModelGraderInputParam `json:"input,omitzero,required"`
180 // The labels to assign to each item in the evaluation.
181 Labels []string `json:"labels,omitzero,required"`
182 // The model to use for the evaluation. Must support structured outputs.
183 Model string `json:"model,required"`
184 // The name of the grader.
185 Name string `json:"name,required"`
186 // The labels that indicate a passing result. Must be a subset of labels.
187 PassingLabels []string `json:"passing_labels,omitzero,required"`
188 // The object type, which is always `label_model`.
189 //
190 // This field can be elided, and will marshal its zero value as "label_model".
191 Type constant.LabelModel `json:"type,required"`
192 paramObj
193}
194
195func (r LabelModelGraderParam) MarshalJSON() (data []byte, err error) {
196 type shadow LabelModelGraderParam
197 return param.MarshalObject(r, (*shadow)(&r))
198}
199func (r *LabelModelGraderParam) UnmarshalJSON(data []byte) error {
200 return apijson.UnmarshalRoot(data, r)
201}
202
203// A message input to the model with a role indicating instruction following
204// hierarchy. Instructions given with the `developer` or `system` role take
205// precedence over instructions given with the `user` role. Messages with the
206// `assistant` role are presumed to have been generated by the model in previous
207// interactions.
208//
209// The properties Content, Role are required.
210type LabelModelGraderInputParam struct {
211 // Text inputs to the model - can contain template strings.
212 Content LabelModelGraderInputContentUnionParam `json:"content,omitzero,required"`
213 // The role of the message input. One of `user`, `assistant`, `system`, or
214 // `developer`.
215 //
216 // Any of "user", "assistant", "system", "developer".
217 Role string `json:"role,omitzero,required"`
218 // The type of the message input. Always `message`.
219 //
220 // Any of "message".
221 Type string `json:"type,omitzero"`
222 paramObj
223}
224
225func (r LabelModelGraderInputParam) MarshalJSON() (data []byte, err error) {
226 type shadow LabelModelGraderInputParam
227 return param.MarshalObject(r, (*shadow)(&r))
228}
229func (r *LabelModelGraderInputParam) UnmarshalJSON(data []byte) error {
230 return apijson.UnmarshalRoot(data, r)
231}
232
233func init() {
234 apijson.RegisterFieldValidator[LabelModelGraderInputParam](
235 "role", "user", "assistant", "system", "developer",
236 )
237 apijson.RegisterFieldValidator[LabelModelGraderInputParam](
238 "type", "message",
239 )
240}
241
242// Only one field can be non-zero.
243//
244// Use [param.IsOmitted] to confirm if a field is set.
245type LabelModelGraderInputContentUnionParam struct {
246 OfString param.Opt[string] `json:",omitzero,inline"`
247 OfInputText *responses.ResponseInputTextParam `json:",omitzero,inline"`
248 OfOutputText *LabelModelGraderInputContentOutputTextParam `json:",omitzero,inline"`
249 paramUnion
250}
251
252func (u LabelModelGraderInputContentUnionParam) MarshalJSON() ([]byte, error) {
253 return param.MarshalUnion(u, u.OfString, u.OfInputText, u.OfOutputText)
254}
255func (u *LabelModelGraderInputContentUnionParam) UnmarshalJSON(data []byte) error {
256 return apijson.UnmarshalRoot(data, u)
257}
258
259func (u *LabelModelGraderInputContentUnionParam) asAny() any {
260 if !param.IsOmitted(u.OfString) {
261 return &u.OfString.Value
262 } else if !param.IsOmitted(u.OfInputText) {
263 return u.OfInputText
264 } else if !param.IsOmitted(u.OfOutputText) {
265 return u.OfOutputText
266 }
267 return nil
268}
269
270// Returns a pointer to the underlying variant's property, if present.
271func (u LabelModelGraderInputContentUnionParam) GetText() *string {
272 if vt := u.OfInputText; vt != nil {
273 return (*string)(&vt.Text)
274 } else if vt := u.OfOutputText; vt != nil {
275 return (*string)(&vt.Text)
276 }
277 return nil
278}
279
280// Returns a pointer to the underlying variant's property, if present.
281func (u LabelModelGraderInputContentUnionParam) GetType() *string {
282 if vt := u.OfInputText; vt != nil {
283 return (*string)(&vt.Type)
284 } else if vt := u.OfOutputText; vt != nil {
285 return (*string)(&vt.Type)
286 }
287 return nil
288}
289
290// A text output from the model.
291//
292// The properties Text, Type are required.
293type LabelModelGraderInputContentOutputTextParam struct {
294 // The text output from the model.
295 Text string `json:"text,required"`
296 // The type of the output text. Always `output_text`.
297 //
298 // This field can be elided, and will marshal its zero value as "output_text".
299 Type constant.OutputText `json:"type,required"`
300 paramObj
301}
302
303func (r LabelModelGraderInputContentOutputTextParam) MarshalJSON() (data []byte, err error) {
304 type shadow LabelModelGraderInputContentOutputTextParam
305 return param.MarshalObject(r, (*shadow)(&r))
306}
307func (r *LabelModelGraderInputContentOutputTextParam) UnmarshalJSON(data []byte) error {
308 return apijson.UnmarshalRoot(data, r)
309}
310
311// A MultiGrader object combines the output of multiple graders to produce a single
312// score.
313type MultiGrader struct {
314 // A formula to calculate the output based on grader results.
315 CalculateOutput string `json:"calculate_output,required"`
316 // A StringCheckGrader object that performs a string comparison between input and
317 // reference using a specified operation.
318 Graders MultiGraderGradersUnion `json:"graders,required"`
319 // The name of the grader.
320 Name string `json:"name,required"`
321 // The object type, which is always `multi`.
322 Type constant.Multi `json:"type,required"`
323 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
324 JSON struct {
325 CalculateOutput respjson.Field
326 Graders respjson.Field
327 Name respjson.Field
328 Type respjson.Field
329 ExtraFields map[string]respjson.Field
330 raw string
331 } `json:"-"`
332}
333
334// Returns the unmodified JSON received from the API
335func (r MultiGrader) RawJSON() string { return r.JSON.raw }
336func (r *MultiGrader) UnmarshalJSON(data []byte) error {
337 return apijson.UnmarshalRoot(data, r)
338}
339
340// ToParam converts this MultiGrader to a MultiGraderParam.
341//
342// Warning: the fields of the param type will not be present. ToParam should only
343// be used at the last possible moment before sending a request. Test for this with
344// MultiGraderParam.Overrides()
345func (r MultiGrader) ToParam() MultiGraderParam {
346 return param.Override[MultiGraderParam](json.RawMessage(r.RawJSON()))
347}
348
349// MultiGraderGradersUnion contains all possible properties and values from
350// [StringCheckGrader], [TextSimilarityGrader], [PythonGrader], [ScoreModelGrader],
351// [LabelModelGrader].
352//
353// Use the methods beginning with 'As' to cast the union to one of its variants.
354type MultiGraderGradersUnion struct {
355 // This field is a union of [string], [string], [[]ScoreModelGraderInput],
356 // [[]LabelModelGraderInput]
357 Input MultiGraderGradersUnionInput `json:"input"`
358 Name string `json:"name"`
359 // This field is from variant [StringCheckGrader].
360 Operation StringCheckGraderOperation `json:"operation"`
361 Reference string `json:"reference"`
362 Type string `json:"type"`
363 // This field is from variant [TextSimilarityGrader].
364 EvaluationMetric TextSimilarityGraderEvaluationMetric `json:"evaluation_metric"`
365 // This field is from variant [PythonGrader].
366 Source string `json:"source"`
367 // This field is from variant [PythonGrader].
368 ImageTag string `json:"image_tag"`
369 Model string `json:"model"`
370 // This field is from variant [ScoreModelGrader].
371 Range []float64 `json:"range"`
372 // This field is from variant [ScoreModelGrader].
373 SamplingParams any `json:"sampling_params"`
374 // This field is from variant [LabelModelGrader].
375 Labels []string `json:"labels"`
376 // This field is from variant [LabelModelGrader].
377 PassingLabels []string `json:"passing_labels"`
378 JSON struct {
379 Input respjson.Field
380 Name respjson.Field
381 Operation respjson.Field
382 Reference respjson.Field
383 Type respjson.Field
384 EvaluationMetric respjson.Field
385 Source respjson.Field
386 ImageTag respjson.Field
387 Model respjson.Field
388 Range respjson.Field
389 SamplingParams respjson.Field
390 Labels respjson.Field
391 PassingLabels respjson.Field
392 raw string
393 } `json:"-"`
394}
395
396func (u MultiGraderGradersUnion) AsStringCheckGrader() (v StringCheckGrader) {
397 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
398 return
399}
400
401func (u MultiGraderGradersUnion) AsTextSimilarityGrader() (v TextSimilarityGrader) {
402 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
403 return
404}
405
406func (u MultiGraderGradersUnion) AsPythonGrader() (v PythonGrader) {
407 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
408 return
409}
410
411func (u MultiGraderGradersUnion) AsScoreModelGrader() (v ScoreModelGrader) {
412 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
413 return
414}
415
416func (u MultiGraderGradersUnion) AsLabelModelGrader() (v LabelModelGrader) {
417 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
418 return
419}
420
421// Returns the unmodified JSON received from the API
422func (u MultiGraderGradersUnion) RawJSON() string { return u.JSON.raw }
423
424func (r *MultiGraderGradersUnion) UnmarshalJSON(data []byte) error {
425 return apijson.UnmarshalRoot(data, r)
426}
427
428// MultiGraderGradersUnionInput is an implicit subunion of
429// [MultiGraderGradersUnion]. MultiGraderGradersUnionInput provides convenient
430// access to the sub-properties of the union.
431//
432// For type safety it is recommended to directly use a variant of the
433// [MultiGraderGradersUnion].
434//
435// If the underlying value is not a json object, one of the following properties
436// will be valid: OfString OfScoreModelGraderInputArray
437// OfLabelModelGraderInputArray]
438type MultiGraderGradersUnionInput struct {
439 // This field will be present if the value is a [string] instead of an object.
440 OfString string `json:",inline"`
441 // This field will be present if the value is a [[]ScoreModelGraderInput] instead
442 // of an object.
443 OfScoreModelGraderInputArray []ScoreModelGraderInput `json:",inline"`
444 // This field will be present if the value is a [[]LabelModelGraderInput] instead
445 // of an object.
446 OfLabelModelGraderInputArray []LabelModelGraderInput `json:",inline"`
447 JSON struct {
448 OfString respjson.Field
449 OfScoreModelGraderInputArray respjson.Field
450 OfLabelModelGraderInputArray respjson.Field
451 raw string
452 } `json:"-"`
453}
454
455func (r *MultiGraderGradersUnionInput) UnmarshalJSON(data []byte) error {
456 return apijson.UnmarshalRoot(data, r)
457}
458
459// A MultiGrader object combines the output of multiple graders to produce a single
460// score.
461//
462// The properties CalculateOutput, Graders, Name, Type are required.
463type MultiGraderParam struct {
464 // A formula to calculate the output based on grader results.
465 CalculateOutput string `json:"calculate_output,required"`
466 // A StringCheckGrader object that performs a string comparison between input and
467 // reference using a specified operation.
468 Graders MultiGraderGradersUnionParam `json:"graders,omitzero,required"`
469 // The name of the grader.
470 Name string `json:"name,required"`
471 // The object type, which is always `multi`.
472 //
473 // This field can be elided, and will marshal its zero value as "multi".
474 Type constant.Multi `json:"type,required"`
475 paramObj
476}
477
478func (r MultiGraderParam) MarshalJSON() (data []byte, err error) {
479 type shadow MultiGraderParam
480 return param.MarshalObject(r, (*shadow)(&r))
481}
482func (r *MultiGraderParam) UnmarshalJSON(data []byte) error {
483 return apijson.UnmarshalRoot(data, r)
484}
485
486// Only one field can be non-zero.
487//
488// Use [param.IsOmitted] to confirm if a field is set.
489type MultiGraderGradersUnionParam struct {
490 OfStringCheckGrader *StringCheckGraderParam `json:",omitzero,inline"`
491 OfTextSimilarityGrader *TextSimilarityGraderParam `json:",omitzero,inline"`
492 OfPythonGrader *PythonGraderParam `json:",omitzero,inline"`
493 OfScoreModelGrader *ScoreModelGraderParam `json:",omitzero,inline"`
494 OfLabelModelGrader *LabelModelGraderParam `json:",omitzero,inline"`
495 paramUnion
496}
497
498func (u MultiGraderGradersUnionParam) MarshalJSON() ([]byte, error) {
499 return param.MarshalUnion(u, u.OfStringCheckGrader,
500 u.OfTextSimilarityGrader,
501 u.OfPythonGrader,
502 u.OfScoreModelGrader,
503 u.OfLabelModelGrader)
504}
505func (u *MultiGraderGradersUnionParam) UnmarshalJSON(data []byte) error {
506 return apijson.UnmarshalRoot(data, u)
507}
508
509func (u *MultiGraderGradersUnionParam) asAny() any {
510 if !param.IsOmitted(u.OfStringCheckGrader) {
511 return u.OfStringCheckGrader
512 } else if !param.IsOmitted(u.OfTextSimilarityGrader) {
513 return u.OfTextSimilarityGrader
514 } else if !param.IsOmitted(u.OfPythonGrader) {
515 return u.OfPythonGrader
516 } else if !param.IsOmitted(u.OfScoreModelGrader) {
517 return u.OfScoreModelGrader
518 } else if !param.IsOmitted(u.OfLabelModelGrader) {
519 return u.OfLabelModelGrader
520 }
521 return nil
522}
523
524// Returns a pointer to the underlying variant's property, if present.
525func (u MultiGraderGradersUnionParam) GetOperation() *string {
526 if vt := u.OfStringCheckGrader; vt != nil {
527 return (*string)(&vt.Operation)
528 }
529 return nil
530}
531
532// Returns a pointer to the underlying variant's property, if present.
533func (u MultiGraderGradersUnionParam) GetEvaluationMetric() *string {
534 if vt := u.OfTextSimilarityGrader; vt != nil {
535 return (*string)(&vt.EvaluationMetric)
536 }
537 return nil
538}
539
540// Returns a pointer to the underlying variant's property, if present.
541func (u MultiGraderGradersUnionParam) GetSource() *string {
542 if vt := u.OfPythonGrader; vt != nil {
543 return &vt.Source
544 }
545 return nil
546}
547
548// Returns a pointer to the underlying variant's property, if present.
549func (u MultiGraderGradersUnionParam) GetImageTag() *string {
550 if vt := u.OfPythonGrader; vt != nil && vt.ImageTag.Valid() {
551 return &vt.ImageTag.Value
552 }
553 return nil
554}
555
556// Returns a pointer to the underlying variant's property, if present.
557func (u MultiGraderGradersUnionParam) GetRange() []float64 {
558 if vt := u.OfScoreModelGrader; vt != nil {
559 return vt.Range
560 }
561 return nil
562}
563
564// Returns a pointer to the underlying variant's property, if present.
565func (u MultiGraderGradersUnionParam) GetSamplingParams() *any {
566 if vt := u.OfScoreModelGrader; vt != nil {
567 return &vt.SamplingParams
568 }
569 return nil
570}
571
572// Returns a pointer to the underlying variant's property, if present.
573func (u MultiGraderGradersUnionParam) GetLabels() []string {
574 if vt := u.OfLabelModelGrader; vt != nil {
575 return vt.Labels
576 }
577 return nil
578}
579
580// Returns a pointer to the underlying variant's property, if present.
581func (u MultiGraderGradersUnionParam) GetPassingLabels() []string {
582 if vt := u.OfLabelModelGrader; vt != nil {
583 return vt.PassingLabels
584 }
585 return nil
586}
587
588// Returns a pointer to the underlying variant's property, if present.
589func (u MultiGraderGradersUnionParam) GetName() *string {
590 if vt := u.OfStringCheckGrader; vt != nil {
591 return (*string)(&vt.Name)
592 } else if vt := u.OfTextSimilarityGrader; vt != nil {
593 return (*string)(&vt.Name)
594 } else if vt := u.OfPythonGrader; vt != nil {
595 return (*string)(&vt.Name)
596 } else if vt := u.OfScoreModelGrader; vt != nil {
597 return (*string)(&vt.Name)
598 } else if vt := u.OfLabelModelGrader; vt != nil {
599 return (*string)(&vt.Name)
600 }
601 return nil
602}
603
604// Returns a pointer to the underlying variant's property, if present.
605func (u MultiGraderGradersUnionParam) GetReference() *string {
606 if vt := u.OfStringCheckGrader; vt != nil {
607 return (*string)(&vt.Reference)
608 } else if vt := u.OfTextSimilarityGrader; vt != nil {
609 return (*string)(&vt.Reference)
610 }
611 return nil
612}
613
614// Returns a pointer to the underlying variant's property, if present.
615func (u MultiGraderGradersUnionParam) GetType() *string {
616 if vt := u.OfStringCheckGrader; vt != nil {
617 return (*string)(&vt.Type)
618 } else if vt := u.OfTextSimilarityGrader; vt != nil {
619 return (*string)(&vt.Type)
620 } else if vt := u.OfPythonGrader; vt != nil {
621 return (*string)(&vt.Type)
622 } else if vt := u.OfScoreModelGrader; vt != nil {
623 return (*string)(&vt.Type)
624 } else if vt := u.OfLabelModelGrader; vt != nil {
625 return (*string)(&vt.Type)
626 }
627 return nil
628}
629
630// Returns a pointer to the underlying variant's property, if present.
631func (u MultiGraderGradersUnionParam) GetModel() *string {
632 if vt := u.OfScoreModelGrader; vt != nil {
633 return (*string)(&vt.Model)
634 } else if vt := u.OfLabelModelGrader; vt != nil {
635 return (*string)(&vt.Model)
636 }
637 return nil
638}
639
640// Returns a subunion which exports methods to access subproperties
641//
642// Or use AsAny() to get the underlying value
643func (u MultiGraderGradersUnionParam) GetInput() (res multiGraderGradersUnionParamInput) {
644 if vt := u.OfStringCheckGrader; vt != nil {
645 res.any = &vt.Input
646 } else if vt := u.OfTextSimilarityGrader; vt != nil {
647 res.any = &vt.Input
648 } else if vt := u.OfScoreModelGrader; vt != nil {
649 res.any = &vt.Input
650 } else if vt := u.OfLabelModelGrader; vt != nil {
651 res.any = &vt.Input
652 }
653 return
654}
655
656// Can have the runtime types [*string], [_[]ScoreModelGraderInputParam],
657// [_[]LabelModelGraderInputParam]
658type multiGraderGradersUnionParamInput struct{ any }
659
660// Use the following switch statement to get the type of the union:
661//
662// switch u.AsAny().(type) {
663// case *string:
664// case *[]openai.ScoreModelGraderInputParam:
665// case *[]openai.LabelModelGraderInputParam:
666// default:
667// fmt.Errorf("not present")
668// }
669func (u multiGraderGradersUnionParamInput) AsAny() any { return u.any }
670
671// A PythonGrader object that runs a python script on the input.
672type PythonGrader struct {
673 // The name of the grader.
674 Name string `json:"name,required"`
675 // The source code of the python script.
676 Source string `json:"source,required"`
677 // The object type, which is always `python`.
678 Type constant.Python `json:"type,required"`
679 // The image tag to use for the python script.
680 ImageTag string `json:"image_tag"`
681 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
682 JSON struct {
683 Name respjson.Field
684 Source respjson.Field
685 Type respjson.Field
686 ImageTag respjson.Field
687 ExtraFields map[string]respjson.Field
688 raw string
689 } `json:"-"`
690}
691
692// Returns the unmodified JSON received from the API
693func (r PythonGrader) RawJSON() string { return r.JSON.raw }
694func (r *PythonGrader) UnmarshalJSON(data []byte) error {
695 return apijson.UnmarshalRoot(data, r)
696}
697
698// ToParam converts this PythonGrader to a PythonGraderParam.
699//
700// Warning: the fields of the param type will not be present. ToParam should only
701// be used at the last possible moment before sending a request. Test for this with
702// PythonGraderParam.Overrides()
703func (r PythonGrader) ToParam() PythonGraderParam {
704 return param.Override[PythonGraderParam](json.RawMessage(r.RawJSON()))
705}
706
707// A PythonGrader object that runs a python script on the input.
708//
709// The properties Name, Source, Type are required.
710type PythonGraderParam struct {
711 // The name of the grader.
712 Name string `json:"name,required"`
713 // The source code of the python script.
714 Source string `json:"source,required"`
715 // The image tag to use for the python script.
716 ImageTag param.Opt[string] `json:"image_tag,omitzero"`
717 // The object type, which is always `python`.
718 //
719 // This field can be elided, and will marshal its zero value as "python".
720 Type constant.Python `json:"type,required"`
721 paramObj
722}
723
724func (r PythonGraderParam) MarshalJSON() (data []byte, err error) {
725 type shadow PythonGraderParam
726 return param.MarshalObject(r, (*shadow)(&r))
727}
728func (r *PythonGraderParam) UnmarshalJSON(data []byte) error {
729 return apijson.UnmarshalRoot(data, r)
730}
731
732// A ScoreModelGrader object that uses a model to assign a score to the input.
733type ScoreModelGrader struct {
734 // The input text. This may include template strings.
735 Input []ScoreModelGraderInput `json:"input,required"`
736 // The model to use for the evaluation.
737 Model string `json:"model,required"`
738 // The name of the grader.
739 Name string `json:"name,required"`
740 // The object type, which is always `score_model`.
741 Type constant.ScoreModel `json:"type,required"`
742 // The range of the score. Defaults to `[0, 1]`.
743 Range []float64 `json:"range"`
744 // The sampling parameters for the model.
745 SamplingParams any `json:"sampling_params"`
746 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
747 JSON struct {
748 Input respjson.Field
749 Model respjson.Field
750 Name respjson.Field
751 Type respjson.Field
752 Range respjson.Field
753 SamplingParams respjson.Field
754 ExtraFields map[string]respjson.Field
755 raw string
756 } `json:"-"`
757}
758
759// Returns the unmodified JSON received from the API
760func (r ScoreModelGrader) RawJSON() string { return r.JSON.raw }
761func (r *ScoreModelGrader) UnmarshalJSON(data []byte) error {
762 return apijson.UnmarshalRoot(data, r)
763}
764
765// ToParam converts this ScoreModelGrader to a ScoreModelGraderParam.
766//
767// Warning: the fields of the param type will not be present. ToParam should only
768// be used at the last possible moment before sending a request. Test for this with
769// ScoreModelGraderParam.Overrides()
770func (r ScoreModelGrader) ToParam() ScoreModelGraderParam {
771 return param.Override[ScoreModelGraderParam](json.RawMessage(r.RawJSON()))
772}
773
774// A message input to the model with a role indicating instruction following
775// hierarchy. Instructions given with the `developer` or `system` role take
776// precedence over instructions given with the `user` role. Messages with the
777// `assistant` role are presumed to have been generated by the model in previous
778// interactions.
779type ScoreModelGraderInput struct {
780 // Text inputs to the model - can contain template strings.
781 Content ScoreModelGraderInputContentUnion `json:"content,required"`
782 // The role of the message input. One of `user`, `assistant`, `system`, or
783 // `developer`.
784 //
785 // Any of "user", "assistant", "system", "developer".
786 Role string `json:"role,required"`
787 // The type of the message input. Always `message`.
788 //
789 // Any of "message".
790 Type string `json:"type"`
791 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
792 JSON struct {
793 Content respjson.Field
794 Role respjson.Field
795 Type respjson.Field
796 ExtraFields map[string]respjson.Field
797 raw string
798 } `json:"-"`
799}
800
801// Returns the unmodified JSON received from the API
802func (r ScoreModelGraderInput) RawJSON() string { return r.JSON.raw }
803func (r *ScoreModelGraderInput) UnmarshalJSON(data []byte) error {
804 return apijson.UnmarshalRoot(data, r)
805}
806
807// ScoreModelGraderInputContentUnion contains all possible properties and values
808// from [string], [responses.ResponseInputText],
809// [ScoreModelGraderInputContentOutputText].
810//
811// Use the methods beginning with 'As' to cast the union to one of its variants.
812//
813// If the underlying value is not a json object, one of the following properties
814// will be valid: OfString]
815type ScoreModelGraderInputContentUnion struct {
816 // This field will be present if the value is a [string] instead of an object.
817 OfString string `json:",inline"`
818 Text string `json:"text"`
819 Type string `json:"type"`
820 JSON struct {
821 OfString respjson.Field
822 Text respjson.Field
823 Type respjson.Field
824 raw string
825 } `json:"-"`
826}
827
828func (u ScoreModelGraderInputContentUnion) AsString() (v string) {
829 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
830 return
831}
832
833func (u ScoreModelGraderInputContentUnion) AsInputText() (v responses.ResponseInputText) {
834 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
835 return
836}
837
838func (u ScoreModelGraderInputContentUnion) AsOutputText() (v ScoreModelGraderInputContentOutputText) {
839 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
840 return
841}
842
843// Returns the unmodified JSON received from the API
844func (u ScoreModelGraderInputContentUnion) RawJSON() string { return u.JSON.raw }
845
846func (r *ScoreModelGraderInputContentUnion) UnmarshalJSON(data []byte) error {
847 return apijson.UnmarshalRoot(data, r)
848}
849
850// A text output from the model.
851type ScoreModelGraderInputContentOutputText struct {
852 // The text output from the model.
853 Text string `json:"text,required"`
854 // The type of the output text. Always `output_text`.
855 Type constant.OutputText `json:"type,required"`
856 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
857 JSON struct {
858 Text respjson.Field
859 Type respjson.Field
860 ExtraFields map[string]respjson.Field
861 raw string
862 } `json:"-"`
863}
864
865// Returns the unmodified JSON received from the API
866func (r ScoreModelGraderInputContentOutputText) RawJSON() string { return r.JSON.raw }
867func (r *ScoreModelGraderInputContentOutputText) UnmarshalJSON(data []byte) error {
868 return apijson.UnmarshalRoot(data, r)
869}
870
871// A ScoreModelGrader object that uses a model to assign a score to the input.
872//
873// The properties Input, Model, Name, Type are required.
874type ScoreModelGraderParam struct {
875 // The input text. This may include template strings.
876 Input []ScoreModelGraderInputParam `json:"input,omitzero,required"`
877 // The model to use for the evaluation.
878 Model string `json:"model,required"`
879 // The name of the grader.
880 Name string `json:"name,required"`
881 // The range of the score. Defaults to `[0, 1]`.
882 Range []float64 `json:"range,omitzero"`
883 // The sampling parameters for the model.
884 SamplingParams any `json:"sampling_params,omitzero"`
885 // The object type, which is always `score_model`.
886 //
887 // This field can be elided, and will marshal its zero value as "score_model".
888 Type constant.ScoreModel `json:"type,required"`
889 paramObj
890}
891
892func (r ScoreModelGraderParam) MarshalJSON() (data []byte, err error) {
893 type shadow ScoreModelGraderParam
894 return param.MarshalObject(r, (*shadow)(&r))
895}
896func (r *ScoreModelGraderParam) UnmarshalJSON(data []byte) error {
897 return apijson.UnmarshalRoot(data, r)
898}
899
900// A message input to the model with a role indicating instruction following
901// hierarchy. Instructions given with the `developer` or `system` role take
902// precedence over instructions given with the `user` role. Messages with the
903// `assistant` role are presumed to have been generated by the model in previous
904// interactions.
905//
906// The properties Content, Role are required.
907type ScoreModelGraderInputParam struct {
908 // Text inputs to the model - can contain template strings.
909 Content ScoreModelGraderInputContentUnionParam `json:"content,omitzero,required"`
910 // The role of the message input. One of `user`, `assistant`, `system`, or
911 // `developer`.
912 //
913 // Any of "user", "assistant", "system", "developer".
914 Role string `json:"role,omitzero,required"`
915 // The type of the message input. Always `message`.
916 //
917 // Any of "message".
918 Type string `json:"type,omitzero"`
919 paramObj
920}
921
922func (r ScoreModelGraderInputParam) MarshalJSON() (data []byte, err error) {
923 type shadow ScoreModelGraderInputParam
924 return param.MarshalObject(r, (*shadow)(&r))
925}
926func (r *ScoreModelGraderInputParam) UnmarshalJSON(data []byte) error {
927 return apijson.UnmarshalRoot(data, r)
928}
929
930func init() {
931 apijson.RegisterFieldValidator[ScoreModelGraderInputParam](
932 "role", "user", "assistant", "system", "developer",
933 )
934 apijson.RegisterFieldValidator[ScoreModelGraderInputParam](
935 "type", "message",
936 )
937}
938
939// Only one field can be non-zero.
940//
941// Use [param.IsOmitted] to confirm if a field is set.
942type ScoreModelGraderInputContentUnionParam struct {
943 OfString param.Opt[string] `json:",omitzero,inline"`
944 OfInputText *responses.ResponseInputTextParam `json:",omitzero,inline"`
945 OfOutputText *ScoreModelGraderInputContentOutputTextParam `json:",omitzero,inline"`
946 paramUnion
947}
948
949func (u ScoreModelGraderInputContentUnionParam) MarshalJSON() ([]byte, error) {
950 return param.MarshalUnion(u, u.OfString, u.OfInputText, u.OfOutputText)
951}
952func (u *ScoreModelGraderInputContentUnionParam) UnmarshalJSON(data []byte) error {
953 return apijson.UnmarshalRoot(data, u)
954}
955
956func (u *ScoreModelGraderInputContentUnionParam) asAny() any {
957 if !param.IsOmitted(u.OfString) {
958 return &u.OfString.Value
959 } else if !param.IsOmitted(u.OfInputText) {
960 return u.OfInputText
961 } else if !param.IsOmitted(u.OfOutputText) {
962 return u.OfOutputText
963 }
964 return nil
965}
966
967// Returns a pointer to the underlying variant's property, if present.
968func (u ScoreModelGraderInputContentUnionParam) GetText() *string {
969 if vt := u.OfInputText; vt != nil {
970 return (*string)(&vt.Text)
971 } else if vt := u.OfOutputText; vt != nil {
972 return (*string)(&vt.Text)
973 }
974 return nil
975}
976
977// Returns a pointer to the underlying variant's property, if present.
978func (u ScoreModelGraderInputContentUnionParam) GetType() *string {
979 if vt := u.OfInputText; vt != nil {
980 return (*string)(&vt.Type)
981 } else if vt := u.OfOutputText; vt != nil {
982 return (*string)(&vt.Type)
983 }
984 return nil
985}
986
987// A text output from the model.
988//
989// The properties Text, Type are required.
990type ScoreModelGraderInputContentOutputTextParam struct {
991 // The text output from the model.
992 Text string `json:"text,required"`
993 // The type of the output text. Always `output_text`.
994 //
995 // This field can be elided, and will marshal its zero value as "output_text".
996 Type constant.OutputText `json:"type,required"`
997 paramObj
998}
999
1000func (r ScoreModelGraderInputContentOutputTextParam) MarshalJSON() (data []byte, err error) {
1001 type shadow ScoreModelGraderInputContentOutputTextParam
1002 return param.MarshalObject(r, (*shadow)(&r))
1003}
1004func (r *ScoreModelGraderInputContentOutputTextParam) UnmarshalJSON(data []byte) error {
1005 return apijson.UnmarshalRoot(data, r)
1006}
1007
1008// A StringCheckGrader object that performs a string comparison between input and
1009// reference using a specified operation.
1010type StringCheckGrader struct {
1011 // The input text. This may include template strings.
1012 Input string `json:"input,required"`
1013 // The name of the grader.
1014 Name string `json:"name,required"`
1015 // The string check operation to perform. One of `eq`, `ne`, `like`, or `ilike`.
1016 //
1017 // Any of "eq", "ne", "like", "ilike".
1018 Operation StringCheckGraderOperation `json:"operation,required"`
1019 // The reference text. This may include template strings.
1020 Reference string `json:"reference,required"`
1021 // The object type, which is always `string_check`.
1022 Type constant.StringCheck `json:"type,required"`
1023 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1024 JSON struct {
1025 Input respjson.Field
1026 Name respjson.Field
1027 Operation respjson.Field
1028 Reference respjson.Field
1029 Type respjson.Field
1030 ExtraFields map[string]respjson.Field
1031 raw string
1032 } `json:"-"`
1033}
1034
1035// Returns the unmodified JSON received from the API
1036func (r StringCheckGrader) RawJSON() string { return r.JSON.raw }
1037func (r *StringCheckGrader) UnmarshalJSON(data []byte) error {
1038 return apijson.UnmarshalRoot(data, r)
1039}
1040
1041// ToParam converts this StringCheckGrader to a StringCheckGraderParam.
1042//
1043// Warning: the fields of the param type will not be present. ToParam should only
1044// be used at the last possible moment before sending a request. Test for this with
1045// StringCheckGraderParam.Overrides()
1046func (r StringCheckGrader) ToParam() StringCheckGraderParam {
1047 return param.Override[StringCheckGraderParam](json.RawMessage(r.RawJSON()))
1048}
1049
1050// The string check operation to perform. One of `eq`, `ne`, `like`, or `ilike`.
1051type StringCheckGraderOperation string
1052
1053const (
1054 StringCheckGraderOperationEq StringCheckGraderOperation = "eq"
1055 StringCheckGraderOperationNe StringCheckGraderOperation = "ne"
1056 StringCheckGraderOperationLike StringCheckGraderOperation = "like"
1057 StringCheckGraderOperationIlike StringCheckGraderOperation = "ilike"
1058)
1059
1060// A StringCheckGrader object that performs a string comparison between input and
1061// reference using a specified operation.
1062//
1063// The properties Input, Name, Operation, Reference, Type are required.
1064type StringCheckGraderParam struct {
1065 // The input text. This may include template strings.
1066 Input string `json:"input,required"`
1067 // The name of the grader.
1068 Name string `json:"name,required"`
1069 // The string check operation to perform. One of `eq`, `ne`, `like`, or `ilike`.
1070 //
1071 // Any of "eq", "ne", "like", "ilike".
1072 Operation StringCheckGraderOperation `json:"operation,omitzero,required"`
1073 // The reference text. This may include template strings.
1074 Reference string `json:"reference,required"`
1075 // The object type, which is always `string_check`.
1076 //
1077 // This field can be elided, and will marshal its zero value as "string_check".
1078 Type constant.StringCheck `json:"type,required"`
1079 paramObj
1080}
1081
1082func (r StringCheckGraderParam) MarshalJSON() (data []byte, err error) {
1083 type shadow StringCheckGraderParam
1084 return param.MarshalObject(r, (*shadow)(&r))
1085}
1086func (r *StringCheckGraderParam) UnmarshalJSON(data []byte) error {
1087 return apijson.UnmarshalRoot(data, r)
1088}
1089
1090// A TextSimilarityGrader object which grades text based on similarity metrics.
1091type TextSimilarityGrader struct {
1092 // The evaluation metric to use. One of `fuzzy_match`, `bleu`, `gleu`, `meteor`,
1093 // `rouge_1`, `rouge_2`, `rouge_3`, `rouge_4`, `rouge_5`, or `rouge_l`.
1094 //
1095 // Any of "fuzzy_match", "bleu", "gleu", "meteor", "rouge_1", "rouge_2", "rouge_3",
1096 // "rouge_4", "rouge_5", "rouge_l".
1097 EvaluationMetric TextSimilarityGraderEvaluationMetric `json:"evaluation_metric,required"`
1098 // The text being graded.
1099 Input string `json:"input,required"`
1100 // The name of the grader.
1101 Name string `json:"name,required"`
1102 // The text being graded against.
1103 Reference string `json:"reference,required"`
1104 // The type of grader.
1105 Type constant.TextSimilarity `json:"type,required"`
1106 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1107 JSON struct {
1108 EvaluationMetric respjson.Field
1109 Input respjson.Field
1110 Name respjson.Field
1111 Reference respjson.Field
1112 Type respjson.Field
1113 ExtraFields map[string]respjson.Field
1114 raw string
1115 } `json:"-"`
1116}
1117
1118// Returns the unmodified JSON received from the API
1119func (r TextSimilarityGrader) RawJSON() string { return r.JSON.raw }
1120func (r *TextSimilarityGrader) UnmarshalJSON(data []byte) error {
1121 return apijson.UnmarshalRoot(data, r)
1122}
1123
1124// ToParam converts this TextSimilarityGrader to a TextSimilarityGraderParam.
1125//
1126// Warning: the fields of the param type will not be present. ToParam should only
1127// be used at the last possible moment before sending a request. Test for this with
1128// TextSimilarityGraderParam.Overrides()
1129func (r TextSimilarityGrader) ToParam() TextSimilarityGraderParam {
1130 return param.Override[TextSimilarityGraderParam](json.RawMessage(r.RawJSON()))
1131}
1132
1133// The evaluation metric to use. One of `fuzzy_match`, `bleu`, `gleu`, `meteor`,
1134// `rouge_1`, `rouge_2`, `rouge_3`, `rouge_4`, `rouge_5`, or `rouge_l`.
1135type TextSimilarityGraderEvaluationMetric string
1136
1137const (
1138 TextSimilarityGraderEvaluationMetricFuzzyMatch TextSimilarityGraderEvaluationMetric = "fuzzy_match"
1139 TextSimilarityGraderEvaluationMetricBleu TextSimilarityGraderEvaluationMetric = "bleu"
1140 TextSimilarityGraderEvaluationMetricGleu TextSimilarityGraderEvaluationMetric = "gleu"
1141 TextSimilarityGraderEvaluationMetricMeteor TextSimilarityGraderEvaluationMetric = "meteor"
1142 TextSimilarityGraderEvaluationMetricRouge1 TextSimilarityGraderEvaluationMetric = "rouge_1"
1143 TextSimilarityGraderEvaluationMetricRouge2 TextSimilarityGraderEvaluationMetric = "rouge_2"
1144 TextSimilarityGraderEvaluationMetricRouge3 TextSimilarityGraderEvaluationMetric = "rouge_3"
1145 TextSimilarityGraderEvaluationMetricRouge4 TextSimilarityGraderEvaluationMetric = "rouge_4"
1146 TextSimilarityGraderEvaluationMetricRouge5 TextSimilarityGraderEvaluationMetric = "rouge_5"
1147 TextSimilarityGraderEvaluationMetricRougeL TextSimilarityGraderEvaluationMetric = "rouge_l"
1148)
1149
1150// A TextSimilarityGrader object which grades text based on similarity metrics.
1151//
1152// The properties EvaluationMetric, Input, Name, Reference, Type are required.
1153type TextSimilarityGraderParam struct {
1154 // The evaluation metric to use. One of `fuzzy_match`, `bleu`, `gleu`, `meteor`,
1155 // `rouge_1`, `rouge_2`, `rouge_3`, `rouge_4`, `rouge_5`, or `rouge_l`.
1156 //
1157 // Any of "fuzzy_match", "bleu", "gleu", "meteor", "rouge_1", "rouge_2", "rouge_3",
1158 // "rouge_4", "rouge_5", "rouge_l".
1159 EvaluationMetric TextSimilarityGraderEvaluationMetric `json:"evaluation_metric,omitzero,required"`
1160 // The text being graded.
1161 Input string `json:"input,required"`
1162 // The name of the grader.
1163 Name string `json:"name,required"`
1164 // The text being graded against.
1165 Reference string `json:"reference,required"`
1166 // The type of grader.
1167 //
1168 // This field can be elided, and will marshal its zero value as "text_similarity".
1169 Type constant.TextSimilarity `json:"type,required"`
1170 paramObj
1171}
1172
1173func (r TextSimilarityGraderParam) MarshalJSON() (data []byte, err error) {
1174 type shadow TextSimilarityGraderParam
1175 return param.MarshalObject(r, (*shadow)(&r))
1176}
1177func (r *TextSimilarityGraderParam) UnmarshalJSON(data []byte) error {
1178 return apijson.UnmarshalRoot(data, r)
1179}