inputitem.go

  1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  2
  3package responses
  4
  5import (
  6	"context"
  7	"errors"
  8	"fmt"
  9	"net/http"
 10	"net/url"
 11
 12	"github.com/openai/openai-go/internal/apijson"
 13	"github.com/openai/openai-go/internal/apiquery"
 14	"github.com/openai/openai-go/internal/requestconfig"
 15	"github.com/openai/openai-go/option"
 16	"github.com/openai/openai-go/packages/pagination"
 17	"github.com/openai/openai-go/packages/param"
 18	"github.com/openai/openai-go/packages/respjson"
 19	"github.com/openai/openai-go/shared/constant"
 20)
 21
 22// InputItemService contains methods and other services that help with interacting
 23// with the openai API.
 24//
 25// Note, unlike clients, this service does not read variables from the environment
 26// automatically. You should not instantiate this service directly, and instead use
 27// the [NewInputItemService] method instead.
 28type InputItemService struct {
 29	Options []option.RequestOption
 30}
 31
 32// NewInputItemService generates a new service that applies the given options to
 33// each request. These options are applied after the parent client's options (if
 34// there is one), and before any request-specific options.
 35func NewInputItemService(opts ...option.RequestOption) (r InputItemService) {
 36	r = InputItemService{}
 37	r.Options = opts
 38	return
 39}
 40
 41// Returns a list of input items for a given response.
 42func (r *InputItemService) List(ctx context.Context, responseID string, query InputItemListParams, opts ...option.RequestOption) (res *pagination.CursorPage[ResponseItemUnion], err error) {
 43	var raw *http.Response
 44	opts = append(r.Options[:], opts...)
 45	opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
 46	if responseID == "" {
 47		err = errors.New("missing required response_id parameter")
 48		return
 49	}
 50	path := fmt.Sprintf("responses/%s/input_items", responseID)
 51	cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
 52	if err != nil {
 53		return nil, err
 54	}
 55	err = cfg.Execute()
 56	if err != nil {
 57		return nil, err
 58	}
 59	res.SetPageConfig(cfg, raw)
 60	return res, nil
 61}
 62
 63// Returns a list of input items for a given response.
 64func (r *InputItemService) ListAutoPaging(ctx context.Context, responseID string, query InputItemListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[ResponseItemUnion] {
 65	return pagination.NewCursorPageAutoPager(r.List(ctx, responseID, query, opts...))
 66}
 67
 68// A list of Response items.
 69type ResponseItemList struct {
 70	// A list of items used to generate this response.
 71	Data []ResponseItemUnion `json:"data,required"`
 72	// The ID of the first item in the list.
 73	FirstID string `json:"first_id,required"`
 74	// Whether there are more items available.
 75	HasMore bool `json:"has_more,required"`
 76	// The ID of the last item in the list.
 77	LastID string `json:"last_id,required"`
 78	// The type of object returned, must be `list`.
 79	Object constant.List `json:"object,required"`
 80	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
 81	JSON struct {
 82		Data        respjson.Field
 83		FirstID     respjson.Field
 84		HasMore     respjson.Field
 85		LastID      respjson.Field
 86		Object      respjson.Field
 87		ExtraFields map[string]respjson.Field
 88		raw         string
 89	} `json:"-"`
 90}
 91
 92// Returns the unmodified JSON received from the API
 93func (r ResponseItemList) RawJSON() string { return r.JSON.raw }
 94func (r *ResponseItemList) UnmarshalJSON(data []byte) error {
 95	return apijson.UnmarshalRoot(data, r)
 96}
 97
 98type InputItemListParams struct {
 99	// An item ID to list items after, used in pagination.
100	After param.Opt[string] `query:"after,omitzero" json:"-"`
101	// An item ID to list items before, used in pagination.
102	Before param.Opt[string] `query:"before,omitzero" json:"-"`
103	// A limit on the number of objects to be returned. Limit can range between 1 and
104	// 100, and the default is 20.
105	Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
106	// Additional fields to include in the response. See the `include` parameter for
107	// Response creation above for more information.
108	Include []ResponseIncludable `query:"include,omitzero" json:"-"`
109	// The order to return the input items in. Default is `desc`.
110	//
111	// - `asc`: Return the input items in ascending order.
112	// - `desc`: Return the input items in descending order.
113	//
114	// Any of "asc", "desc".
115	Order InputItemListParamsOrder `query:"order,omitzero" json:"-"`
116	paramObj
117}
118
119// URLQuery serializes [InputItemListParams]'s query parameters as `url.Values`.
120func (r InputItemListParams) URLQuery() (v url.Values, err error) {
121	return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
122		ArrayFormat:  apiquery.ArrayQueryFormatBrackets,
123		NestedFormat: apiquery.NestedQueryFormatBrackets,
124	})
125}
126
127// The order to return the input items in. Default is `desc`.
128//
129// - `asc`: Return the input items in ascending order.
130// - `desc`: Return the input items in descending order.
131type InputItemListParamsOrder string
132
133const (
134	InputItemListParamsOrderAsc  InputItemListParamsOrder = "asc"
135	InputItemListParamsOrderDesc InputItemListParamsOrder = "desc"
136)