1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3package openai
4
5import (
6 "context"
7 "encoding/json"
8 "errors"
9 "fmt"
10 "net/http"
11 "net/url"
12
13 "github.com/openai/openai-go/internal/apijson"
14 "github.com/openai/openai-go/internal/apiquery"
15 "github.com/openai/openai-go/internal/requestconfig"
16 "github.com/openai/openai-go/option"
17 "github.com/openai/openai-go/packages/pagination"
18 "github.com/openai/openai-go/packages/param"
19 "github.com/openai/openai-go/packages/respjson"
20 "github.com/openai/openai-go/shared"
21 "github.com/openai/openai-go/shared/constant"
22)
23
24// BetaThreadRunStepService contains methods and other services that help with
25// interacting with the openai API.
26//
27// Note, unlike clients, this service does not read variables from the environment
28// automatically. You should not instantiate this service directly, and instead use
29// the [NewBetaThreadRunStepService] method instead.
30//
31// Deprecated: The Assistants API is deprecated in favor of the Responses API
32type BetaThreadRunStepService struct {
33 Options []option.RequestOption
34}
35
36// NewBetaThreadRunStepService generates a new service that applies the given
37// options to each request. These options are applied after the parent client's
38// options (if there is one), and before any request-specific options.
39func NewBetaThreadRunStepService(opts ...option.RequestOption) (r BetaThreadRunStepService) {
40 r = BetaThreadRunStepService{}
41 r.Options = opts
42 return
43}
44
45// Retrieves a run step.
46//
47// Deprecated: The Assistants API is deprecated in favor of the Responses API
48func (r *BetaThreadRunStepService) Get(ctx context.Context, threadID string, runID string, stepID string, query BetaThreadRunStepGetParams, opts ...option.RequestOption) (res *RunStep, err error) {
49 opts = append(r.Options[:], opts...)
50 opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
51 if threadID == "" {
52 err = errors.New("missing required thread_id parameter")
53 return
54 }
55 if runID == "" {
56 err = errors.New("missing required run_id parameter")
57 return
58 }
59 if stepID == "" {
60 err = errors.New("missing required step_id parameter")
61 return
62 }
63 path := fmt.Sprintf("threads/%s/runs/%s/steps/%s", threadID, runID, stepID)
64 err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
65 return
66}
67
68// Returns a list of run steps belonging to a run.
69//
70// Deprecated: The Assistants API is deprecated in favor of the Responses API
71func (r *BetaThreadRunStepService) List(ctx context.Context, threadID string, runID string, query BetaThreadRunStepListParams, opts ...option.RequestOption) (res *pagination.CursorPage[RunStep], err error) {
72 var raw *http.Response
73 opts = append(r.Options[:], opts...)
74 opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2"), option.WithResponseInto(&raw)}, opts...)
75 if threadID == "" {
76 err = errors.New("missing required thread_id parameter")
77 return
78 }
79 if runID == "" {
80 err = errors.New("missing required run_id parameter")
81 return
82 }
83 path := fmt.Sprintf("threads/%s/runs/%s/steps", threadID, runID)
84 cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
85 if err != nil {
86 return nil, err
87 }
88 err = cfg.Execute()
89 if err != nil {
90 return nil, err
91 }
92 res.SetPageConfig(cfg, raw)
93 return res, nil
94}
95
96// Returns a list of run steps belonging to a run.
97//
98// Deprecated: The Assistants API is deprecated in favor of the Responses API
99func (r *BetaThreadRunStepService) ListAutoPaging(ctx context.Context, threadID string, runID string, query BetaThreadRunStepListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[RunStep] {
100 return pagination.NewCursorPageAutoPager(r.List(ctx, threadID, runID, query, opts...))
101}
102
103// Text output from the Code Interpreter tool call as part of a run step.
104type CodeInterpreterLogs struct {
105 // The index of the output in the outputs array.
106 Index int64 `json:"index,required"`
107 // Always `logs`.
108 Type constant.Logs `json:"type,required"`
109 // The text output from the Code Interpreter tool call.
110 Logs string `json:"logs"`
111 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
112 JSON struct {
113 Index respjson.Field
114 Type respjson.Field
115 Logs respjson.Field
116 ExtraFields map[string]respjson.Field
117 raw string
118 } `json:"-"`
119}
120
121// Returns the unmodified JSON received from the API
122func (r CodeInterpreterLogs) RawJSON() string { return r.JSON.raw }
123func (r *CodeInterpreterLogs) UnmarshalJSON(data []byte) error {
124 return apijson.UnmarshalRoot(data, r)
125}
126
127type CodeInterpreterOutputImage struct {
128 // The index of the output in the outputs array.
129 Index int64 `json:"index,required"`
130 // Always `image`.
131 Type constant.Image `json:"type,required"`
132 Image CodeInterpreterOutputImageImage `json:"image"`
133 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
134 JSON struct {
135 Index respjson.Field
136 Type respjson.Field
137 Image respjson.Field
138 ExtraFields map[string]respjson.Field
139 raw string
140 } `json:"-"`
141}
142
143// Returns the unmodified JSON received from the API
144func (r CodeInterpreterOutputImage) RawJSON() string { return r.JSON.raw }
145func (r *CodeInterpreterOutputImage) UnmarshalJSON(data []byte) error {
146 return apijson.UnmarshalRoot(data, r)
147}
148
149type CodeInterpreterOutputImageImage struct {
150 // The [file](https://platform.openai.com/docs/api-reference/files) ID of the
151 // image.
152 FileID string `json:"file_id"`
153 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
154 JSON struct {
155 FileID respjson.Field
156 ExtraFields map[string]respjson.Field
157 raw string
158 } `json:"-"`
159}
160
161// Returns the unmodified JSON received from the API
162func (r CodeInterpreterOutputImageImage) RawJSON() string { return r.JSON.raw }
163func (r *CodeInterpreterOutputImageImage) UnmarshalJSON(data []byte) error {
164 return apijson.UnmarshalRoot(data, r)
165}
166
167// Details of the Code Interpreter tool call the run step was involved in.
168type CodeInterpreterToolCall struct {
169 // The ID of the tool call.
170 ID string `json:"id,required"`
171 // The Code Interpreter tool call definition.
172 CodeInterpreter CodeInterpreterToolCallCodeInterpreter `json:"code_interpreter,required"`
173 // The type of tool call. This is always going to be `code_interpreter` for this
174 // type of tool call.
175 Type constant.CodeInterpreter `json:"type,required"`
176 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
177 JSON struct {
178 ID respjson.Field
179 CodeInterpreter respjson.Field
180 Type respjson.Field
181 ExtraFields map[string]respjson.Field
182 raw string
183 } `json:"-"`
184}
185
186// Returns the unmodified JSON received from the API
187func (r CodeInterpreterToolCall) RawJSON() string { return r.JSON.raw }
188func (r *CodeInterpreterToolCall) UnmarshalJSON(data []byte) error {
189 return apijson.UnmarshalRoot(data, r)
190}
191
192// The Code Interpreter tool call definition.
193type CodeInterpreterToolCallCodeInterpreter struct {
194 // The input to the Code Interpreter tool call.
195 Input string `json:"input,required"`
196 // The outputs from the Code Interpreter tool call. Code Interpreter can output one
197 // or more items, including text (`logs`) or images (`image`). Each of these are
198 // represented by a different object type.
199 Outputs []CodeInterpreterToolCallCodeInterpreterOutputUnion `json:"outputs,required"`
200 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
201 JSON struct {
202 Input respjson.Field
203 Outputs respjson.Field
204 ExtraFields map[string]respjson.Field
205 raw string
206 } `json:"-"`
207}
208
209// Returns the unmodified JSON received from the API
210func (r CodeInterpreterToolCallCodeInterpreter) RawJSON() string { return r.JSON.raw }
211func (r *CodeInterpreterToolCallCodeInterpreter) UnmarshalJSON(data []byte) error {
212 return apijson.UnmarshalRoot(data, r)
213}
214
215// CodeInterpreterToolCallCodeInterpreterOutputUnion contains all possible
216// properties and values from [CodeInterpreterToolCallCodeInterpreterOutputLogs],
217// [CodeInterpreterToolCallCodeInterpreterOutputImage].
218//
219// Use the [CodeInterpreterToolCallCodeInterpreterOutputUnion.AsAny] method to
220// switch on the variant.
221//
222// Use the methods beginning with 'As' to cast the union to one of its variants.
223type CodeInterpreterToolCallCodeInterpreterOutputUnion struct {
224 // This field is from variant [CodeInterpreterToolCallCodeInterpreterOutputLogs].
225 Logs string `json:"logs"`
226 // Any of "logs", "image".
227 Type string `json:"type"`
228 // This field is from variant [CodeInterpreterToolCallCodeInterpreterOutputImage].
229 Image CodeInterpreterToolCallCodeInterpreterOutputImageImage `json:"image"`
230 JSON struct {
231 Logs respjson.Field
232 Type respjson.Field
233 Image respjson.Field
234 raw string
235 } `json:"-"`
236}
237
238// anyCodeInterpreterToolCallCodeInterpreterOutput is implemented by each variant
239// of [CodeInterpreterToolCallCodeInterpreterOutputUnion] to add type safety for
240// the return type of [CodeInterpreterToolCallCodeInterpreterOutputUnion.AsAny]
241type anyCodeInterpreterToolCallCodeInterpreterOutput interface {
242 implCodeInterpreterToolCallCodeInterpreterOutputUnion()
243}
244
245func (CodeInterpreterToolCallCodeInterpreterOutputLogs) implCodeInterpreterToolCallCodeInterpreterOutputUnion() {
246}
247func (CodeInterpreterToolCallCodeInterpreterOutputImage) implCodeInterpreterToolCallCodeInterpreterOutputUnion() {
248}
249
250// Use the following switch statement to find the correct variant
251//
252// switch variant := CodeInterpreterToolCallCodeInterpreterOutputUnion.AsAny().(type) {
253// case openai.CodeInterpreterToolCallCodeInterpreterOutputLogs:
254// case openai.CodeInterpreterToolCallCodeInterpreterOutputImage:
255// default:
256// fmt.Errorf("no variant present")
257// }
258func (u CodeInterpreterToolCallCodeInterpreterOutputUnion) AsAny() anyCodeInterpreterToolCallCodeInterpreterOutput {
259 switch u.Type {
260 case "logs":
261 return u.AsLogs()
262 case "image":
263 return u.AsImage()
264 }
265 return nil
266}
267
268func (u CodeInterpreterToolCallCodeInterpreterOutputUnion) AsLogs() (v CodeInterpreterToolCallCodeInterpreterOutputLogs) {
269 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
270 return
271}
272
273func (u CodeInterpreterToolCallCodeInterpreterOutputUnion) AsImage() (v CodeInterpreterToolCallCodeInterpreterOutputImage) {
274 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
275 return
276}
277
278// Returns the unmodified JSON received from the API
279func (u CodeInterpreterToolCallCodeInterpreterOutputUnion) RawJSON() string { return u.JSON.raw }
280
281func (r *CodeInterpreterToolCallCodeInterpreterOutputUnion) UnmarshalJSON(data []byte) error {
282 return apijson.UnmarshalRoot(data, r)
283}
284
285// Text output from the Code Interpreter tool call as part of a run step.
286type CodeInterpreterToolCallCodeInterpreterOutputLogs struct {
287 // The text output from the Code Interpreter tool call.
288 Logs string `json:"logs,required"`
289 // Always `logs`.
290 Type constant.Logs `json:"type,required"`
291 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
292 JSON struct {
293 Logs respjson.Field
294 Type respjson.Field
295 ExtraFields map[string]respjson.Field
296 raw string
297 } `json:"-"`
298}
299
300// Returns the unmodified JSON received from the API
301func (r CodeInterpreterToolCallCodeInterpreterOutputLogs) RawJSON() string { return r.JSON.raw }
302func (r *CodeInterpreterToolCallCodeInterpreterOutputLogs) UnmarshalJSON(data []byte) error {
303 return apijson.UnmarshalRoot(data, r)
304}
305
306type CodeInterpreterToolCallCodeInterpreterOutputImage struct {
307 Image CodeInterpreterToolCallCodeInterpreterOutputImageImage `json:"image,required"`
308 // Always `image`.
309 Type constant.Image `json:"type,required"`
310 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
311 JSON struct {
312 Image respjson.Field
313 Type respjson.Field
314 ExtraFields map[string]respjson.Field
315 raw string
316 } `json:"-"`
317}
318
319// Returns the unmodified JSON received from the API
320func (r CodeInterpreterToolCallCodeInterpreterOutputImage) RawJSON() string { return r.JSON.raw }
321func (r *CodeInterpreterToolCallCodeInterpreterOutputImage) UnmarshalJSON(data []byte) error {
322 return apijson.UnmarshalRoot(data, r)
323}
324
325type CodeInterpreterToolCallCodeInterpreterOutputImageImage struct {
326 // The [file](https://platform.openai.com/docs/api-reference/files) ID of the
327 // image.
328 FileID string `json:"file_id,required"`
329 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
330 JSON struct {
331 FileID respjson.Field
332 ExtraFields map[string]respjson.Field
333 raw string
334 } `json:"-"`
335}
336
337// Returns the unmodified JSON received from the API
338func (r CodeInterpreterToolCallCodeInterpreterOutputImageImage) RawJSON() string { return r.JSON.raw }
339func (r *CodeInterpreterToolCallCodeInterpreterOutputImageImage) UnmarshalJSON(data []byte) error {
340 return apijson.UnmarshalRoot(data, r)
341}
342
343// Details of the Code Interpreter tool call the run step was involved in.
344type CodeInterpreterToolCallDelta struct {
345 // The index of the tool call in the tool calls array.
346 Index int64 `json:"index,required"`
347 // The type of tool call. This is always going to be `code_interpreter` for this
348 // type of tool call.
349 Type constant.CodeInterpreter `json:"type,required"`
350 // The ID of the tool call.
351 ID string `json:"id"`
352 // The Code Interpreter tool call definition.
353 CodeInterpreter CodeInterpreterToolCallDeltaCodeInterpreter `json:"code_interpreter"`
354 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
355 JSON struct {
356 Index respjson.Field
357 Type respjson.Field
358 ID respjson.Field
359 CodeInterpreter respjson.Field
360 ExtraFields map[string]respjson.Field
361 raw string
362 } `json:"-"`
363}
364
365// Returns the unmodified JSON received from the API
366func (r CodeInterpreterToolCallDelta) RawJSON() string { return r.JSON.raw }
367func (r *CodeInterpreterToolCallDelta) UnmarshalJSON(data []byte) error {
368 return apijson.UnmarshalRoot(data, r)
369}
370
371// The Code Interpreter tool call definition.
372type CodeInterpreterToolCallDeltaCodeInterpreter struct {
373 // The input to the Code Interpreter tool call.
374 Input string `json:"input"`
375 // The outputs from the Code Interpreter tool call. Code Interpreter can output one
376 // or more items, including text (`logs`) or images (`image`). Each of these are
377 // represented by a different object type.
378 Outputs []CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion `json:"outputs"`
379 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
380 JSON struct {
381 Input respjson.Field
382 Outputs respjson.Field
383 ExtraFields map[string]respjson.Field
384 raw string
385 } `json:"-"`
386}
387
388// Returns the unmodified JSON received from the API
389func (r CodeInterpreterToolCallDeltaCodeInterpreter) RawJSON() string { return r.JSON.raw }
390func (r *CodeInterpreterToolCallDeltaCodeInterpreter) UnmarshalJSON(data []byte) error {
391 return apijson.UnmarshalRoot(data, r)
392}
393
394// CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion contains all possible
395// properties and values from [CodeInterpreterLogs], [CodeInterpreterOutputImage].
396//
397// Use the [CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion.AsAny] method to
398// switch on the variant.
399//
400// Use the methods beginning with 'As' to cast the union to one of its variants.
401type CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion struct {
402 Index int64 `json:"index"`
403 // Any of "logs", "image".
404 Type string `json:"type"`
405 // This field is from variant [CodeInterpreterLogs].
406 Logs string `json:"logs"`
407 // This field is from variant [CodeInterpreterOutputImage].
408 Image CodeInterpreterOutputImageImage `json:"image"`
409 JSON struct {
410 Index respjson.Field
411 Type respjson.Field
412 Logs respjson.Field
413 Image respjson.Field
414 raw string
415 } `json:"-"`
416}
417
418// anyCodeInterpreterToolCallDeltaCodeInterpreterOutput is implemented by each
419// variant of [CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion] to add type
420// safety for the return type of
421// [CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion.AsAny]
422type anyCodeInterpreterToolCallDeltaCodeInterpreterOutput interface {
423 implCodeInterpreterToolCallDeltaCodeInterpreterOutputUnion()
424}
425
426func (CodeInterpreterLogs) implCodeInterpreterToolCallDeltaCodeInterpreterOutputUnion() {}
427func (CodeInterpreterOutputImage) implCodeInterpreterToolCallDeltaCodeInterpreterOutputUnion() {}
428
429// Use the following switch statement to find the correct variant
430//
431// switch variant := CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion.AsAny().(type) {
432// case openai.CodeInterpreterLogs:
433// case openai.CodeInterpreterOutputImage:
434// default:
435// fmt.Errorf("no variant present")
436// }
437func (u CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion) AsAny() anyCodeInterpreterToolCallDeltaCodeInterpreterOutput {
438 switch u.Type {
439 case "logs":
440 return u.AsLogs()
441 case "image":
442 return u.AsImage()
443 }
444 return nil
445}
446
447func (u CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion) AsLogs() (v CodeInterpreterLogs) {
448 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
449 return
450}
451
452func (u CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion) AsImage() (v CodeInterpreterOutputImage) {
453 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
454 return
455}
456
457// Returns the unmodified JSON received from the API
458func (u CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion) RawJSON() string { return u.JSON.raw }
459
460func (r *CodeInterpreterToolCallDeltaCodeInterpreterOutputUnion) UnmarshalJSON(data []byte) error {
461 return apijson.UnmarshalRoot(data, r)
462}
463
464type FileSearchToolCall struct {
465 // The ID of the tool call object.
466 ID string `json:"id,required"`
467 // For now, this is always going to be an empty object.
468 FileSearch FileSearchToolCallFileSearch `json:"file_search,required"`
469 // The type of tool call. This is always going to be `file_search` for this type of
470 // tool call.
471 Type constant.FileSearch `json:"type,required"`
472 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
473 JSON struct {
474 ID respjson.Field
475 FileSearch respjson.Field
476 Type respjson.Field
477 ExtraFields map[string]respjson.Field
478 raw string
479 } `json:"-"`
480}
481
482// Returns the unmodified JSON received from the API
483func (r FileSearchToolCall) RawJSON() string { return r.JSON.raw }
484func (r *FileSearchToolCall) UnmarshalJSON(data []byte) error {
485 return apijson.UnmarshalRoot(data, r)
486}
487
488// For now, this is always going to be an empty object.
489type FileSearchToolCallFileSearch struct {
490 // The ranking options for the file search.
491 RankingOptions FileSearchToolCallFileSearchRankingOptions `json:"ranking_options"`
492 // The results of the file search.
493 Results []FileSearchToolCallFileSearchResult `json:"results"`
494 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
495 JSON struct {
496 RankingOptions respjson.Field
497 Results respjson.Field
498 ExtraFields map[string]respjson.Field
499 raw string
500 } `json:"-"`
501}
502
503// Returns the unmodified JSON received from the API
504func (r FileSearchToolCallFileSearch) RawJSON() string { return r.JSON.raw }
505func (r *FileSearchToolCallFileSearch) UnmarshalJSON(data []byte) error {
506 return apijson.UnmarshalRoot(data, r)
507}
508
509// The ranking options for the file search.
510type FileSearchToolCallFileSearchRankingOptions struct {
511 // The ranker to use for the file search. If not specified will use the `auto`
512 // ranker.
513 //
514 // Any of "auto", "default_2024_08_21".
515 Ranker string `json:"ranker,required"`
516 // The score threshold for the file search. All values must be a floating point
517 // number between 0 and 1.
518 ScoreThreshold float64 `json:"score_threshold,required"`
519 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
520 JSON struct {
521 Ranker respjson.Field
522 ScoreThreshold respjson.Field
523 ExtraFields map[string]respjson.Field
524 raw string
525 } `json:"-"`
526}
527
528// Returns the unmodified JSON received from the API
529func (r FileSearchToolCallFileSearchRankingOptions) RawJSON() string { return r.JSON.raw }
530func (r *FileSearchToolCallFileSearchRankingOptions) UnmarshalJSON(data []byte) error {
531 return apijson.UnmarshalRoot(data, r)
532}
533
534// A result instance of the file search.
535type FileSearchToolCallFileSearchResult struct {
536 // The ID of the file that result was found in.
537 FileID string `json:"file_id,required"`
538 // The name of the file that result was found in.
539 FileName string `json:"file_name,required"`
540 // The score of the result. All values must be a floating point number between 0
541 // and 1.
542 Score float64 `json:"score,required"`
543 // The content of the result that was found. The content is only included if
544 // requested via the include query parameter.
545 Content []FileSearchToolCallFileSearchResultContent `json:"content"`
546 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
547 JSON struct {
548 FileID respjson.Field
549 FileName respjson.Field
550 Score respjson.Field
551 Content respjson.Field
552 ExtraFields map[string]respjson.Field
553 raw string
554 } `json:"-"`
555}
556
557// Returns the unmodified JSON received from the API
558func (r FileSearchToolCallFileSearchResult) RawJSON() string { return r.JSON.raw }
559func (r *FileSearchToolCallFileSearchResult) UnmarshalJSON(data []byte) error {
560 return apijson.UnmarshalRoot(data, r)
561}
562
563type FileSearchToolCallFileSearchResultContent struct {
564 // The text content of the file.
565 Text string `json:"text"`
566 // The type of the content.
567 //
568 // Any of "text".
569 Type string `json:"type"`
570 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
571 JSON struct {
572 Text respjson.Field
573 Type respjson.Field
574 ExtraFields map[string]respjson.Field
575 raw string
576 } `json:"-"`
577}
578
579// Returns the unmodified JSON received from the API
580func (r FileSearchToolCallFileSearchResultContent) RawJSON() string { return r.JSON.raw }
581func (r *FileSearchToolCallFileSearchResultContent) UnmarshalJSON(data []byte) error {
582 return apijson.UnmarshalRoot(data, r)
583}
584
585type FileSearchToolCallDelta struct {
586 // For now, this is always going to be an empty object.
587 FileSearch any `json:"file_search,required"`
588 // The index of the tool call in the tool calls array.
589 Index int64 `json:"index,required"`
590 // The type of tool call. This is always going to be `file_search` for this type of
591 // tool call.
592 Type constant.FileSearch `json:"type,required"`
593 // The ID of the tool call object.
594 ID string `json:"id"`
595 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
596 JSON struct {
597 FileSearch respjson.Field
598 Index respjson.Field
599 Type respjson.Field
600 ID respjson.Field
601 ExtraFields map[string]respjson.Field
602 raw string
603 } `json:"-"`
604}
605
606// Returns the unmodified JSON received from the API
607func (r FileSearchToolCallDelta) RawJSON() string { return r.JSON.raw }
608func (r *FileSearchToolCallDelta) UnmarshalJSON(data []byte) error {
609 return apijson.UnmarshalRoot(data, r)
610}
611
612type FunctionToolCall struct {
613 // The ID of the tool call object.
614 ID string `json:"id,required"`
615 // The definition of the function that was called.
616 Function FunctionToolCallFunction `json:"function,required"`
617 // The type of tool call. This is always going to be `function` for this type of
618 // tool call.
619 Type constant.Function `json:"type,required"`
620 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
621 JSON struct {
622 ID respjson.Field
623 Function respjson.Field
624 Type respjson.Field
625 ExtraFields map[string]respjson.Field
626 raw string
627 } `json:"-"`
628}
629
630// Returns the unmodified JSON received from the API
631func (r FunctionToolCall) RawJSON() string { return r.JSON.raw }
632func (r *FunctionToolCall) UnmarshalJSON(data []byte) error {
633 return apijson.UnmarshalRoot(data, r)
634}
635
636// The definition of the function that was called.
637type FunctionToolCallFunction struct {
638 // The arguments passed to the function.
639 Arguments string `json:"arguments,required"`
640 // The name of the function.
641 Name string `json:"name,required"`
642 // The output of the function. This will be `null` if the outputs have not been
643 // [submitted](https://platform.openai.com/docs/api-reference/runs/submitToolOutputs)
644 // yet.
645 Output string `json:"output,required"`
646 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
647 JSON struct {
648 Arguments respjson.Field
649 Name respjson.Field
650 Output respjson.Field
651 ExtraFields map[string]respjson.Field
652 raw string
653 } `json:"-"`
654}
655
656// Returns the unmodified JSON received from the API
657func (r FunctionToolCallFunction) RawJSON() string { return r.JSON.raw }
658func (r *FunctionToolCallFunction) UnmarshalJSON(data []byte) error {
659 return apijson.UnmarshalRoot(data, r)
660}
661
662type FunctionToolCallDelta struct {
663 // The index of the tool call in the tool calls array.
664 Index int64 `json:"index,required"`
665 // The type of tool call. This is always going to be `function` for this type of
666 // tool call.
667 Type constant.Function `json:"type,required"`
668 // The ID of the tool call object.
669 ID string `json:"id"`
670 // The definition of the function that was called.
671 Function FunctionToolCallDeltaFunction `json:"function"`
672 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
673 JSON struct {
674 Index respjson.Field
675 Type respjson.Field
676 ID respjson.Field
677 Function respjson.Field
678 ExtraFields map[string]respjson.Field
679 raw string
680 } `json:"-"`
681}
682
683// Returns the unmodified JSON received from the API
684func (r FunctionToolCallDelta) RawJSON() string { return r.JSON.raw }
685func (r *FunctionToolCallDelta) UnmarshalJSON(data []byte) error {
686 return apijson.UnmarshalRoot(data, r)
687}
688
689// The definition of the function that was called.
690type FunctionToolCallDeltaFunction struct {
691 // The arguments passed to the function.
692 Arguments string `json:"arguments"`
693 // The name of the function.
694 Name string `json:"name"`
695 // The output of the function. This will be `null` if the outputs have not been
696 // [submitted](https://platform.openai.com/docs/api-reference/runs/submitToolOutputs)
697 // yet.
698 Output string `json:"output,nullable"`
699 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
700 JSON struct {
701 Arguments respjson.Field
702 Name respjson.Field
703 Output respjson.Field
704 ExtraFields map[string]respjson.Field
705 raw string
706 } `json:"-"`
707}
708
709// Returns the unmodified JSON received from the API
710func (r FunctionToolCallDeltaFunction) RawJSON() string { return r.JSON.raw }
711func (r *FunctionToolCallDeltaFunction) UnmarshalJSON(data []byte) error {
712 return apijson.UnmarshalRoot(data, r)
713}
714
715// Details of the message creation by the run step.
716type MessageCreationStepDetails struct {
717 MessageCreation MessageCreationStepDetailsMessageCreation `json:"message_creation,required"`
718 // Always `message_creation`.
719 Type constant.MessageCreation `json:"type,required"`
720 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
721 JSON struct {
722 MessageCreation respjson.Field
723 Type respjson.Field
724 ExtraFields map[string]respjson.Field
725 raw string
726 } `json:"-"`
727}
728
729// Returns the unmodified JSON received from the API
730func (r MessageCreationStepDetails) RawJSON() string { return r.JSON.raw }
731func (r *MessageCreationStepDetails) UnmarshalJSON(data []byte) error {
732 return apijson.UnmarshalRoot(data, r)
733}
734
735type MessageCreationStepDetailsMessageCreation struct {
736 // The ID of the message that was created by this run step.
737 MessageID string `json:"message_id,required"`
738 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
739 JSON struct {
740 MessageID respjson.Field
741 ExtraFields map[string]respjson.Field
742 raw string
743 } `json:"-"`
744}
745
746// Returns the unmodified JSON received from the API
747func (r MessageCreationStepDetailsMessageCreation) RawJSON() string { return r.JSON.raw }
748func (r *MessageCreationStepDetailsMessageCreation) UnmarshalJSON(data []byte) error {
749 return apijson.UnmarshalRoot(data, r)
750}
751
752// Represents a step in execution of a run.
753type RunStep struct {
754 // The identifier of the run step, which can be referenced in API endpoints.
755 ID string `json:"id,required"`
756 // The ID of the
757 // [assistant](https://platform.openai.com/docs/api-reference/assistants)
758 // associated with the run step.
759 AssistantID string `json:"assistant_id,required"`
760 // The Unix timestamp (in seconds) for when the run step was cancelled.
761 CancelledAt int64 `json:"cancelled_at,required"`
762 // The Unix timestamp (in seconds) for when the run step completed.
763 CompletedAt int64 `json:"completed_at,required"`
764 // The Unix timestamp (in seconds) for when the run step was created.
765 CreatedAt int64 `json:"created_at,required"`
766 // The Unix timestamp (in seconds) for when the run step expired. A step is
767 // considered expired if the parent run is expired.
768 ExpiredAt int64 `json:"expired_at,required"`
769 // The Unix timestamp (in seconds) for when the run step failed.
770 FailedAt int64 `json:"failed_at,required"`
771 // The last error associated with this run step. Will be `null` if there are no
772 // errors.
773 LastError RunStepLastError `json:"last_error,required"`
774 // Set of 16 key-value pairs that can be attached to an object. This can be useful
775 // for storing additional information about the object in a structured format, and
776 // querying for objects via API or the dashboard.
777 //
778 // Keys are strings with a maximum length of 64 characters. Values are strings with
779 // a maximum length of 512 characters.
780 Metadata shared.Metadata `json:"metadata,required"`
781 // The object type, which is always `thread.run.step`.
782 Object constant.ThreadRunStep `json:"object,required"`
783 // The ID of the [run](https://platform.openai.com/docs/api-reference/runs) that
784 // this run step is a part of.
785 RunID string `json:"run_id,required"`
786 // The status of the run step, which can be either `in_progress`, `cancelled`,
787 // `failed`, `completed`, or `expired`.
788 //
789 // Any of "in_progress", "cancelled", "failed", "completed", "expired".
790 Status RunStepStatus `json:"status,required"`
791 // The details of the run step.
792 StepDetails RunStepStepDetailsUnion `json:"step_details,required"`
793 // The ID of the [thread](https://platform.openai.com/docs/api-reference/threads)
794 // that was run.
795 ThreadID string `json:"thread_id,required"`
796 // The type of run step, which can be either `message_creation` or `tool_calls`.
797 //
798 // Any of "message_creation", "tool_calls".
799 Type RunStepType `json:"type,required"`
800 // Usage statistics related to the run step. This value will be `null` while the
801 // run step's status is `in_progress`.
802 Usage RunStepUsage `json:"usage,required"`
803 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
804 JSON struct {
805 ID respjson.Field
806 AssistantID respjson.Field
807 CancelledAt respjson.Field
808 CompletedAt respjson.Field
809 CreatedAt respjson.Field
810 ExpiredAt respjson.Field
811 FailedAt respjson.Field
812 LastError respjson.Field
813 Metadata respjson.Field
814 Object respjson.Field
815 RunID respjson.Field
816 Status respjson.Field
817 StepDetails respjson.Field
818 ThreadID respjson.Field
819 Type respjson.Field
820 Usage respjson.Field
821 ExtraFields map[string]respjson.Field
822 raw string
823 } `json:"-"`
824}
825
826// Returns the unmodified JSON received from the API
827func (r RunStep) RawJSON() string { return r.JSON.raw }
828func (r *RunStep) UnmarshalJSON(data []byte) error {
829 return apijson.UnmarshalRoot(data, r)
830}
831
832// The last error associated with this run step. Will be `null` if there are no
833// errors.
834type RunStepLastError struct {
835 // One of `server_error` or `rate_limit_exceeded`.
836 //
837 // Any of "server_error", "rate_limit_exceeded".
838 Code string `json:"code,required"`
839 // A human-readable description of the error.
840 Message string `json:"message,required"`
841 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
842 JSON struct {
843 Code respjson.Field
844 Message respjson.Field
845 ExtraFields map[string]respjson.Field
846 raw string
847 } `json:"-"`
848}
849
850// Returns the unmodified JSON received from the API
851func (r RunStepLastError) RawJSON() string { return r.JSON.raw }
852func (r *RunStepLastError) UnmarshalJSON(data []byte) error {
853 return apijson.UnmarshalRoot(data, r)
854}
855
856// The status of the run step, which can be either `in_progress`, `cancelled`,
857// `failed`, `completed`, or `expired`.
858type RunStepStatus string
859
860const (
861 RunStepStatusInProgress RunStepStatus = "in_progress"
862 RunStepStatusCancelled RunStepStatus = "cancelled"
863 RunStepStatusFailed RunStepStatus = "failed"
864 RunStepStatusCompleted RunStepStatus = "completed"
865 RunStepStatusExpired RunStepStatus = "expired"
866)
867
868// RunStepStepDetailsUnion contains all possible properties and values from
869// [MessageCreationStepDetails], [ToolCallsStepDetails].
870//
871// Use the [RunStepStepDetailsUnion.AsAny] method to switch on the variant.
872//
873// Use the methods beginning with 'As' to cast the union to one of its variants.
874type RunStepStepDetailsUnion struct {
875 // This field is from variant [MessageCreationStepDetails].
876 MessageCreation MessageCreationStepDetailsMessageCreation `json:"message_creation"`
877 // Any of "message_creation", "tool_calls".
878 Type string `json:"type"`
879 // This field is from variant [ToolCallsStepDetails].
880 ToolCalls []ToolCallUnion `json:"tool_calls"`
881 JSON struct {
882 MessageCreation respjson.Field
883 Type respjson.Field
884 ToolCalls respjson.Field
885 raw string
886 } `json:"-"`
887}
888
889// anyRunStepStepDetails is implemented by each variant of
890// [RunStepStepDetailsUnion] to add type safety for the return type of
891// [RunStepStepDetailsUnion.AsAny]
892type anyRunStepStepDetails interface {
893 implRunStepStepDetailsUnion()
894}
895
896func (MessageCreationStepDetails) implRunStepStepDetailsUnion() {}
897func (ToolCallsStepDetails) implRunStepStepDetailsUnion() {}
898
899// Use the following switch statement to find the correct variant
900//
901// switch variant := RunStepStepDetailsUnion.AsAny().(type) {
902// case openai.MessageCreationStepDetails:
903// case openai.ToolCallsStepDetails:
904// default:
905// fmt.Errorf("no variant present")
906// }
907func (u RunStepStepDetailsUnion) AsAny() anyRunStepStepDetails {
908 switch u.Type {
909 case "message_creation":
910 return u.AsMessageCreation()
911 case "tool_calls":
912 return u.AsToolCalls()
913 }
914 return nil
915}
916
917func (u RunStepStepDetailsUnion) AsMessageCreation() (v MessageCreationStepDetails) {
918 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
919 return
920}
921
922func (u RunStepStepDetailsUnion) AsToolCalls() (v ToolCallsStepDetails) {
923 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
924 return
925}
926
927// Returns the unmodified JSON received from the API
928func (u RunStepStepDetailsUnion) RawJSON() string { return u.JSON.raw }
929
930func (r *RunStepStepDetailsUnion) UnmarshalJSON(data []byte) error {
931 return apijson.UnmarshalRoot(data, r)
932}
933
934// The type of run step, which can be either `message_creation` or `tool_calls`.
935type RunStepType string
936
937const (
938 RunStepTypeMessageCreation RunStepType = "message_creation"
939 RunStepTypeToolCalls RunStepType = "tool_calls"
940)
941
942// Usage statistics related to the run step. This value will be `null` while the
943// run step's status is `in_progress`.
944type RunStepUsage struct {
945 // Number of completion tokens used over the course of the run step.
946 CompletionTokens int64 `json:"completion_tokens,required"`
947 // Number of prompt tokens used over the course of the run step.
948 PromptTokens int64 `json:"prompt_tokens,required"`
949 // Total number of tokens used (prompt + completion).
950 TotalTokens int64 `json:"total_tokens,required"`
951 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
952 JSON struct {
953 CompletionTokens respjson.Field
954 PromptTokens respjson.Field
955 TotalTokens respjson.Field
956 ExtraFields map[string]respjson.Field
957 raw string
958 } `json:"-"`
959}
960
961// Returns the unmodified JSON received from the API
962func (r RunStepUsage) RawJSON() string { return r.JSON.raw }
963func (r *RunStepUsage) UnmarshalJSON(data []byte) error {
964 return apijson.UnmarshalRoot(data, r)
965}
966
967// The delta containing the fields that have changed on the run step.
968type RunStepDelta struct {
969 // The details of the run step.
970 StepDetails RunStepDeltaStepDetailsUnion `json:"step_details"`
971 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
972 JSON struct {
973 StepDetails respjson.Field
974 ExtraFields map[string]respjson.Field
975 raw string
976 } `json:"-"`
977}
978
979// Returns the unmodified JSON received from the API
980func (r RunStepDelta) RawJSON() string { return r.JSON.raw }
981func (r *RunStepDelta) UnmarshalJSON(data []byte) error {
982 return apijson.UnmarshalRoot(data, r)
983}
984
985// RunStepDeltaStepDetailsUnion contains all possible properties and values from
986// [RunStepDeltaMessageDelta], [ToolCallDeltaObject].
987//
988// Use the [RunStepDeltaStepDetailsUnion.AsAny] method to switch on the variant.
989//
990// Use the methods beginning with 'As' to cast the union to one of its variants.
991type RunStepDeltaStepDetailsUnion struct {
992 // Any of "message_creation", "tool_calls".
993 Type string `json:"type"`
994 // This field is from variant [RunStepDeltaMessageDelta].
995 MessageCreation RunStepDeltaMessageDeltaMessageCreation `json:"message_creation"`
996 // This field is from variant [ToolCallDeltaObject].
997 ToolCalls []ToolCallDeltaUnion `json:"tool_calls"`
998 JSON struct {
999 Type respjson.Field
1000 MessageCreation respjson.Field
1001 ToolCalls respjson.Field
1002 raw string
1003 } `json:"-"`
1004}
1005
1006// anyRunStepDeltaStepDetails is implemented by each variant of
1007// [RunStepDeltaStepDetailsUnion] to add type safety for the return type of
1008// [RunStepDeltaStepDetailsUnion.AsAny]
1009type anyRunStepDeltaStepDetails interface {
1010 implRunStepDeltaStepDetailsUnion()
1011}
1012
1013func (RunStepDeltaMessageDelta) implRunStepDeltaStepDetailsUnion() {}
1014func (ToolCallDeltaObject) implRunStepDeltaStepDetailsUnion() {}
1015
1016// Use the following switch statement to find the correct variant
1017//
1018// switch variant := RunStepDeltaStepDetailsUnion.AsAny().(type) {
1019// case openai.RunStepDeltaMessageDelta:
1020// case openai.ToolCallDeltaObject:
1021// default:
1022// fmt.Errorf("no variant present")
1023// }
1024func (u RunStepDeltaStepDetailsUnion) AsAny() anyRunStepDeltaStepDetails {
1025 switch u.Type {
1026 case "message_creation":
1027 return u.AsMessageCreation()
1028 case "tool_calls":
1029 return u.AsToolCalls()
1030 }
1031 return nil
1032}
1033
1034func (u RunStepDeltaStepDetailsUnion) AsMessageCreation() (v RunStepDeltaMessageDelta) {
1035 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1036 return
1037}
1038
1039func (u RunStepDeltaStepDetailsUnion) AsToolCalls() (v ToolCallDeltaObject) {
1040 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1041 return
1042}
1043
1044// Returns the unmodified JSON received from the API
1045func (u RunStepDeltaStepDetailsUnion) RawJSON() string { return u.JSON.raw }
1046
1047func (r *RunStepDeltaStepDetailsUnion) UnmarshalJSON(data []byte) error {
1048 return apijson.UnmarshalRoot(data, r)
1049}
1050
1051// Represents a run step delta i.e. any changed fields on a run step during
1052// streaming.
1053type RunStepDeltaEvent struct {
1054 // The identifier of the run step, which can be referenced in API endpoints.
1055 ID string `json:"id,required"`
1056 // The delta containing the fields that have changed on the run step.
1057 Delta RunStepDelta `json:"delta,required"`
1058 // The object type, which is always `thread.run.step.delta`.
1059 Object constant.ThreadRunStepDelta `json:"object,required"`
1060 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1061 JSON struct {
1062 ID respjson.Field
1063 Delta respjson.Field
1064 Object respjson.Field
1065 ExtraFields map[string]respjson.Field
1066 raw string
1067 } `json:"-"`
1068}
1069
1070// Returns the unmodified JSON received from the API
1071func (r RunStepDeltaEvent) RawJSON() string { return r.JSON.raw }
1072func (r *RunStepDeltaEvent) UnmarshalJSON(data []byte) error {
1073 return apijson.UnmarshalRoot(data, r)
1074}
1075
1076// Details of the message creation by the run step.
1077type RunStepDeltaMessageDelta struct {
1078 // Always `message_creation`.
1079 Type constant.MessageCreation `json:"type,required"`
1080 MessageCreation RunStepDeltaMessageDeltaMessageCreation `json:"message_creation"`
1081 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1082 JSON struct {
1083 Type respjson.Field
1084 MessageCreation respjson.Field
1085 ExtraFields map[string]respjson.Field
1086 raw string
1087 } `json:"-"`
1088}
1089
1090// Returns the unmodified JSON received from the API
1091func (r RunStepDeltaMessageDelta) RawJSON() string { return r.JSON.raw }
1092func (r *RunStepDeltaMessageDelta) UnmarshalJSON(data []byte) error {
1093 return apijson.UnmarshalRoot(data, r)
1094}
1095
1096type RunStepDeltaMessageDeltaMessageCreation struct {
1097 // The ID of the message that was created by this run step.
1098 MessageID string `json:"message_id"`
1099 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1100 JSON struct {
1101 MessageID respjson.Field
1102 ExtraFields map[string]respjson.Field
1103 raw string
1104 } `json:"-"`
1105}
1106
1107// Returns the unmodified JSON received from the API
1108func (r RunStepDeltaMessageDeltaMessageCreation) RawJSON() string { return r.JSON.raw }
1109func (r *RunStepDeltaMessageDeltaMessageCreation) UnmarshalJSON(data []byte) error {
1110 return apijson.UnmarshalRoot(data, r)
1111}
1112
1113type RunStepInclude string
1114
1115const (
1116 RunStepIncludeStepDetailsToolCallsFileSearchResultsContent RunStepInclude = "step_details.tool_calls[*].file_search.results[*].content"
1117)
1118
1119// ToolCallUnion contains all possible properties and values from
1120// [CodeInterpreterToolCall], [FileSearchToolCall], [FunctionToolCall].
1121//
1122// Use the [ToolCallUnion.AsAny] method to switch on the variant.
1123//
1124// Use the methods beginning with 'As' to cast the union to one of its variants.
1125type ToolCallUnion struct {
1126 ID string `json:"id"`
1127 // This field is from variant [CodeInterpreterToolCall].
1128 CodeInterpreter CodeInterpreterToolCallCodeInterpreter `json:"code_interpreter"`
1129 // Any of "code_interpreter", "file_search", "function".
1130 Type string `json:"type"`
1131 // This field is from variant [FileSearchToolCall].
1132 FileSearch FileSearchToolCallFileSearch `json:"file_search"`
1133 // This field is from variant [FunctionToolCall].
1134 Function FunctionToolCallFunction `json:"function"`
1135 JSON struct {
1136 ID respjson.Field
1137 CodeInterpreter respjson.Field
1138 Type respjson.Field
1139 FileSearch respjson.Field
1140 Function respjson.Field
1141 raw string
1142 } `json:"-"`
1143}
1144
1145// anyToolCall is implemented by each variant of [ToolCallUnion] to add type safety
1146// for the return type of [ToolCallUnion.AsAny]
1147type anyToolCall interface {
1148 implToolCallUnion()
1149}
1150
1151func (CodeInterpreterToolCall) implToolCallUnion() {}
1152func (FileSearchToolCall) implToolCallUnion() {}
1153func (FunctionToolCall) implToolCallUnion() {}
1154
1155// Use the following switch statement to find the correct variant
1156//
1157// switch variant := ToolCallUnion.AsAny().(type) {
1158// case openai.CodeInterpreterToolCall:
1159// case openai.FileSearchToolCall:
1160// case openai.FunctionToolCall:
1161// default:
1162// fmt.Errorf("no variant present")
1163// }
1164func (u ToolCallUnion) AsAny() anyToolCall {
1165 switch u.Type {
1166 case "code_interpreter":
1167 return u.AsCodeInterpreter()
1168 case "file_search":
1169 return u.AsFileSearch()
1170 case "function":
1171 return u.AsFunction()
1172 }
1173 return nil
1174}
1175
1176func (u ToolCallUnion) AsCodeInterpreter() (v CodeInterpreterToolCall) {
1177 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1178 return
1179}
1180
1181func (u ToolCallUnion) AsFileSearch() (v FileSearchToolCall) {
1182 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1183 return
1184}
1185
1186func (u ToolCallUnion) AsFunction() (v FunctionToolCall) {
1187 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1188 return
1189}
1190
1191// Returns the unmodified JSON received from the API
1192func (u ToolCallUnion) RawJSON() string { return u.JSON.raw }
1193
1194func (r *ToolCallUnion) UnmarshalJSON(data []byte) error {
1195 return apijson.UnmarshalRoot(data, r)
1196}
1197
1198// ToolCallDeltaUnion contains all possible properties and values from
1199// [CodeInterpreterToolCallDelta], [FileSearchToolCallDelta],
1200// [FunctionToolCallDelta].
1201//
1202// Use the [ToolCallDeltaUnion.AsAny] method to switch on the variant.
1203//
1204// Use the methods beginning with 'As' to cast the union to one of its variants.
1205type ToolCallDeltaUnion struct {
1206 Index int64 `json:"index"`
1207 // Any of "code_interpreter", "file_search", "function".
1208 Type string `json:"type"`
1209 ID string `json:"id"`
1210 // This field is from variant [CodeInterpreterToolCallDelta].
1211 CodeInterpreter CodeInterpreterToolCallDeltaCodeInterpreter `json:"code_interpreter"`
1212 // This field is from variant [FileSearchToolCallDelta].
1213 FileSearch any `json:"file_search"`
1214 // This field is from variant [FunctionToolCallDelta].
1215 Function FunctionToolCallDeltaFunction `json:"function"`
1216 JSON struct {
1217 Index respjson.Field
1218 Type respjson.Field
1219 ID respjson.Field
1220 CodeInterpreter respjson.Field
1221 FileSearch respjson.Field
1222 Function respjson.Field
1223 raw string
1224 } `json:"-"`
1225}
1226
1227// anyToolCallDelta is implemented by each variant of [ToolCallDeltaUnion] to add
1228// type safety for the return type of [ToolCallDeltaUnion.AsAny]
1229type anyToolCallDelta interface {
1230 implToolCallDeltaUnion()
1231}
1232
1233func (CodeInterpreterToolCallDelta) implToolCallDeltaUnion() {}
1234func (FileSearchToolCallDelta) implToolCallDeltaUnion() {}
1235func (FunctionToolCallDelta) implToolCallDeltaUnion() {}
1236
1237// Use the following switch statement to find the correct variant
1238//
1239// switch variant := ToolCallDeltaUnion.AsAny().(type) {
1240// case openai.CodeInterpreterToolCallDelta:
1241// case openai.FileSearchToolCallDelta:
1242// case openai.FunctionToolCallDelta:
1243// default:
1244// fmt.Errorf("no variant present")
1245// }
1246func (u ToolCallDeltaUnion) AsAny() anyToolCallDelta {
1247 switch u.Type {
1248 case "code_interpreter":
1249 return u.AsCodeInterpreter()
1250 case "file_search":
1251 return u.AsFileSearch()
1252 case "function":
1253 return u.AsFunction()
1254 }
1255 return nil
1256}
1257
1258func (u ToolCallDeltaUnion) AsCodeInterpreter() (v CodeInterpreterToolCallDelta) {
1259 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1260 return
1261}
1262
1263func (u ToolCallDeltaUnion) AsFileSearch() (v FileSearchToolCallDelta) {
1264 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1265 return
1266}
1267
1268func (u ToolCallDeltaUnion) AsFunction() (v FunctionToolCallDelta) {
1269 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1270 return
1271}
1272
1273// Returns the unmodified JSON received from the API
1274func (u ToolCallDeltaUnion) RawJSON() string { return u.JSON.raw }
1275
1276func (r *ToolCallDeltaUnion) UnmarshalJSON(data []byte) error {
1277 return apijson.UnmarshalRoot(data, r)
1278}
1279
1280// Details of the tool call.
1281type ToolCallDeltaObject struct {
1282 // Always `tool_calls`.
1283 Type constant.ToolCalls `json:"type,required"`
1284 // An array of tool calls the run step was involved in. These can be associated
1285 // with one of three types of tools: `code_interpreter`, `file_search`, or
1286 // `function`.
1287 ToolCalls []ToolCallDeltaUnion `json:"tool_calls"`
1288 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1289 JSON struct {
1290 Type respjson.Field
1291 ToolCalls respjson.Field
1292 ExtraFields map[string]respjson.Field
1293 raw string
1294 } `json:"-"`
1295}
1296
1297// Returns the unmodified JSON received from the API
1298func (r ToolCallDeltaObject) RawJSON() string { return r.JSON.raw }
1299func (r *ToolCallDeltaObject) UnmarshalJSON(data []byte) error {
1300 return apijson.UnmarshalRoot(data, r)
1301}
1302
1303// Details of the tool call.
1304type ToolCallsStepDetails struct {
1305 // An array of tool calls the run step was involved in. These can be associated
1306 // with one of three types of tools: `code_interpreter`, `file_search`, or
1307 // `function`.
1308 ToolCalls []ToolCallUnion `json:"tool_calls,required"`
1309 // Always `tool_calls`.
1310 Type constant.ToolCalls `json:"type,required"`
1311 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1312 JSON struct {
1313 ToolCalls respjson.Field
1314 Type respjson.Field
1315 ExtraFields map[string]respjson.Field
1316 raw string
1317 } `json:"-"`
1318}
1319
1320// Returns the unmodified JSON received from the API
1321func (r ToolCallsStepDetails) RawJSON() string { return r.JSON.raw }
1322func (r *ToolCallsStepDetails) UnmarshalJSON(data []byte) error {
1323 return apijson.UnmarshalRoot(data, r)
1324}
1325
1326type BetaThreadRunStepGetParams struct {
1327 // A list of additional fields to include in the response. Currently the only
1328 // supported value is `step_details.tool_calls[*].file_search.results[*].content`
1329 // to fetch the file search result content.
1330 //
1331 // See the
1332 // [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)
1333 // for more information.
1334 Include []RunStepInclude `query:"include,omitzero" json:"-"`
1335 paramObj
1336}
1337
1338// URLQuery serializes [BetaThreadRunStepGetParams]'s query parameters as
1339// `url.Values`.
1340func (r BetaThreadRunStepGetParams) URLQuery() (v url.Values, err error) {
1341 return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
1342 ArrayFormat: apiquery.ArrayQueryFormatBrackets,
1343 NestedFormat: apiquery.NestedQueryFormatBrackets,
1344 })
1345}
1346
1347type BetaThreadRunStepListParams struct {
1348 // A cursor for use in pagination. `after` is an object ID that defines your place
1349 // in the list. For instance, if you make a list request and receive 100 objects,
1350 // ending with obj_foo, your subsequent call can include after=obj_foo in order to
1351 // fetch the next page of the list.
1352 After param.Opt[string] `query:"after,omitzero" json:"-"`
1353 // A cursor for use in pagination. `before` is an object ID that defines your place
1354 // in the list. For instance, if you make a list request and receive 100 objects,
1355 // starting with obj_foo, your subsequent call can include before=obj_foo in order
1356 // to fetch the previous page of the list.
1357 Before param.Opt[string] `query:"before,omitzero" json:"-"`
1358 // A limit on the number of objects to be returned. Limit can range between 1 and
1359 // 100, and the default is 20.
1360 Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
1361 // A list of additional fields to include in the response. Currently the only
1362 // supported value is `step_details.tool_calls[*].file_search.results[*].content`
1363 // to fetch the file search result content.
1364 //
1365 // See the
1366 // [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)
1367 // for more information.
1368 Include []RunStepInclude `query:"include,omitzero" json:"-"`
1369 // Sort order by the `created_at` timestamp of the objects. `asc` for ascending
1370 // order and `desc` for descending order.
1371 //
1372 // Any of "asc", "desc".
1373 Order BetaThreadRunStepListParamsOrder `query:"order,omitzero" json:"-"`
1374 paramObj
1375}
1376
1377// URLQuery serializes [BetaThreadRunStepListParams]'s query parameters as
1378// `url.Values`.
1379func (r BetaThreadRunStepListParams) URLQuery() (v url.Values, err error) {
1380 return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
1381 ArrayFormat: apiquery.ArrayQueryFormatBrackets,
1382 NestedFormat: apiquery.NestedQueryFormatBrackets,
1383 })
1384}
1385
1386// Sort order by the `created_at` timestamp of the objects. `asc` for ascending
1387// order and `desc` for descending order.
1388type BetaThreadRunStepListParamsOrder string
1389
1390const (
1391 BetaThreadRunStepListParamsOrderAsc BetaThreadRunStepListParamsOrder = "asc"
1392 BetaThreadRunStepListParamsOrderDesc BetaThreadRunStepListParamsOrder = "desc"
1393)