|
| 1 | +// Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | +// All rights reserved. |
| 3 | +// |
| 4 | +// This source code is licensed under the terms described in the LICENSE file in |
| 5 | +// the root directory of this source tree. |
| 6 | +// |
| 7 | +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 8 | + |
| 9 | +package llamastackclient |
| 10 | + |
| 11 | +import ( |
| 12 | + "context" |
| 13 | + "errors" |
| 14 | + "fmt" |
| 15 | + "net/http" |
| 16 | + "net/url" |
| 17 | + "slices" |
| 18 | + |
| 19 | + "github.com/llamastack/llama-stack-client-go/internal/apijson" |
| 20 | + "github.com/llamastack/llama-stack-client-go/internal/apiquery" |
| 21 | + "github.com/llamastack/llama-stack-client-go/internal/requestconfig" |
| 22 | + "github.com/llamastack/llama-stack-client-go/option" |
| 23 | + "github.com/llamastack/llama-stack-client-go/packages/respjson" |
| 24 | +) |
| 25 | + |
| 26 | +// AlphaAdminService contains methods and other services that help with interacting |
| 27 | +// with the llama-stack-client API. |
| 28 | +// |
| 29 | +// Note, unlike clients, this service does not read variables from the environment |
| 30 | +// automatically. You should not instantiate this service directly, and instead use |
| 31 | +// the [NewAlphaAdminService] method instead. |
| 32 | +type AlphaAdminService struct { |
| 33 | + Options []option.RequestOption |
| 34 | +} |
| 35 | + |
| 36 | +// NewAlphaAdminService generates a new service that applies the given options to |
| 37 | +// each request. These options are applied after the parent client's options (if |
| 38 | +// there is one), and before any request-specific options. |
| 39 | +func NewAlphaAdminService(opts ...option.RequestOption) (r AlphaAdminService) { |
| 40 | + r = AlphaAdminService{} |
| 41 | + r.Options = opts |
| 42 | + return |
| 43 | +} |
| 44 | + |
| 45 | +// Get the current health status of the service. |
| 46 | +func (r *AlphaAdminService) Health(ctx context.Context, opts ...option.RequestOption) (res *HealthInfo, err error) { |
| 47 | + opts = slices.Concat(r.Options, opts) |
| 48 | + path := "v1alpha/admin/health" |
| 49 | + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) |
| 50 | + return |
| 51 | +} |
| 52 | + |
| 53 | +// Get detailed information about a specific provider. |
| 54 | +func (r *AlphaAdminService) InspectProvider(ctx context.Context, providerID string, opts ...option.RequestOption) (res *ProviderInfo, err error) { |
| 55 | + opts = slices.Concat(r.Options, opts) |
| 56 | + if providerID == "" { |
| 57 | + err = errors.New("missing required provider_id parameter") |
| 58 | + return |
| 59 | + } |
| 60 | + path := fmt.Sprintf("v1alpha/admin/providers/%s", providerID) |
| 61 | + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) |
| 62 | + return |
| 63 | +} |
| 64 | + |
| 65 | +// List all available providers with their configuration and health status. |
| 66 | +func (r *AlphaAdminService) ListProviders(ctx context.Context, opts ...option.RequestOption) (res *[]ProviderInfo, err error) { |
| 67 | + var env ListProvidersResponse |
| 68 | + opts = slices.Concat(r.Options, opts) |
| 69 | + path := "v1alpha/admin/providers" |
| 70 | + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...) |
| 71 | + if err != nil { |
| 72 | + return |
| 73 | + } |
| 74 | + res = &env.Data |
| 75 | + return |
| 76 | +} |
| 77 | + |
| 78 | +// List all available API routes with their methods and implementing providers. |
| 79 | +func (r *AlphaAdminService) ListRoutes(ctx context.Context, query AlphaAdminListRoutesParams, opts ...option.RequestOption) (res *[]RouteInfo, err error) { |
| 80 | + var env ListRoutesResponse |
| 81 | + opts = slices.Concat(r.Options, opts) |
| 82 | + path := "v1alpha/admin/inspect/routes" |
| 83 | + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &env, opts...) |
| 84 | + if err != nil { |
| 85 | + return |
| 86 | + } |
| 87 | + res = &env.Data |
| 88 | + return |
| 89 | +} |
| 90 | + |
| 91 | +// Get the version of the service. |
| 92 | +func (r *AlphaAdminService) Version(ctx context.Context, opts ...option.RequestOption) (res *VersionInfo, err error) { |
| 93 | + opts = slices.Concat(r.Options, opts) |
| 94 | + path := "v1alpha/admin/version" |
| 95 | + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) |
| 96 | + return |
| 97 | +} |
| 98 | + |
| 99 | +// Response containing a list of all available providers. |
| 100 | +type ListProvidersResponse struct { |
| 101 | + // List of provider information objects |
| 102 | + Data []ProviderInfo `json:"data,required"` |
| 103 | + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. |
| 104 | + JSON struct { |
| 105 | + Data respjson.Field |
| 106 | + ExtraFields map[string]respjson.Field |
| 107 | + raw string |
| 108 | + } `json:"-"` |
| 109 | +} |
| 110 | + |
| 111 | +// Returns the unmodified JSON received from the API |
| 112 | +func (r ListProvidersResponse) RawJSON() string { return r.JSON.raw } |
| 113 | +func (r *ListProvidersResponse) UnmarshalJSON(data []byte) error { |
| 114 | + return apijson.UnmarshalRoot(data, r) |
| 115 | +} |
| 116 | + |
| 117 | +type AlphaAdminListRoutesParams struct { |
| 118 | + // Filter to control which routes are returned. Can be an API level ('v1', |
| 119 | + // 'v1alpha', 'v1beta') to show non-deprecated routes at that level, or |
| 120 | + // 'deprecated' to show deprecated routes across all levels. If not specified, |
| 121 | + // returns all non-deprecated routes. |
| 122 | + // |
| 123 | + // Any of "v1", "v1alpha", "v1beta", "deprecated". |
| 124 | + APIFilter AlphaAdminListRoutesParamsAPIFilter `query:"api_filter,omitzero" json:"-"` |
| 125 | + paramObj |
| 126 | +} |
| 127 | + |
| 128 | +// URLQuery serializes [AlphaAdminListRoutesParams]'s query parameters as |
| 129 | +// `url.Values`. |
| 130 | +func (r AlphaAdminListRoutesParams) URLQuery() (v url.Values, err error) { |
| 131 | + return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ |
| 132 | + ArrayFormat: apiquery.ArrayQueryFormatComma, |
| 133 | + NestedFormat: apiquery.NestedQueryFormatBrackets, |
| 134 | + }) |
| 135 | +} |
| 136 | + |
| 137 | +// Filter to control which routes are returned. Can be an API level ('v1', |
| 138 | +// 'v1alpha', 'v1beta') to show non-deprecated routes at that level, or |
| 139 | +// 'deprecated' to show deprecated routes across all levels. If not specified, |
| 140 | +// returns all non-deprecated routes. |
| 141 | +type AlphaAdminListRoutesParamsAPIFilter string |
| 142 | + |
| 143 | +const ( |
| 144 | + AlphaAdminListRoutesParamsAPIFilterV1 AlphaAdminListRoutesParamsAPIFilter = "v1" |
| 145 | + AlphaAdminListRoutesParamsAPIFilterV1alpha AlphaAdminListRoutesParamsAPIFilter = "v1alpha" |
| 146 | + AlphaAdminListRoutesParamsAPIFilterV1beta AlphaAdminListRoutesParamsAPIFilter = "v1beta" |
| 147 | + AlphaAdminListRoutesParamsAPIFilterDeprecated AlphaAdminListRoutesParamsAPIFilter = "deprecated" |
| 148 | +) |
| 149 | + |
| 150 | +// Response containing a list of all available API routes. |
| 151 | +type ListRoutesResponse struct { |
| 152 | + // List of available API routes |
| 153 | + Data []RouteInfo `json:"data,required"` |
| 154 | + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. |
| 155 | + JSON struct { |
| 156 | + Data respjson.Field |
| 157 | + ExtraFields map[string]respjson.Field |
| 158 | + raw string |
| 159 | + } `json:"-"` |
| 160 | +} |
| 161 | + |
| 162 | +// Returns the unmodified JSON received from the API |
| 163 | +func (r ListRoutesResponse) RawJSON() string { return r.JSON.raw } |
| 164 | +func (r *ListRoutesResponse) UnmarshalJSON(data []byte) error { |
| 165 | + return apijson.UnmarshalRoot(data, r) |
| 166 | +} |
0 commit comments