Skip to content

Commit 236906d

Browse files
feat: introduce /admin API for stack administration and operations
1 parent 50d6580 commit 236906d

File tree

8 files changed

+472
-142
lines changed

8 files changed

+472
-142
lines changed

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 103
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/llamastack%2Fllama-stack-client-8e37e023855aa0a93d09eb2b5365aae5203273d01db0532ba0dc58d2a1f94692.yml
3-
openapi_spec_hash: a2f9d306a6594d5ff915ce30da498892
4-
config_hash: 39578cfdeb4a10121f2cb3fa3e4d5e20
1+
configured_endpoints: 108
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/llamastack%2Fllama-stack-client-5b5c7384ecc87cd37cdcfef47628d88ae84c366452114e8891d5d9cf4fde810c.yml
3+
openapi_spec_hash: 9774340e22da2895556cf845f044a69a
4+
config_hash: aa28e451064c13a38ddc44df99ebf52a

alpha.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type AlphaService struct {
2424
PostTraining AlphaPostTrainingService
2525
Benchmarks AlphaBenchmarkService
2626
Eval AlphaEvalService
27+
Admin AlphaAdminService
2728
}
2829

2930
// NewAlphaService generates a new service that applies the given options to each
@@ -36,5 +37,6 @@ func NewAlphaService(opts ...option.RequestOption) (r AlphaService) {
3637
r.PostTraining = NewAlphaPostTrainingService(opts...)
3738
r.Benchmarks = NewAlphaBenchmarkService(opts...)
3839
r.Eval = NewAlphaEvalService(opts...)
40+
r.Admin = NewAlphaAdminService(opts...)
3941
return
4042
}

alphaadmin.go

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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+
}

alphaadmin_test.go

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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_test
10+
11+
import (
12+
"context"
13+
"errors"
14+
"os"
15+
"testing"
16+
17+
"github.com/llamastack/llama-stack-client-go"
18+
"github.com/llamastack/llama-stack-client-go/internal/testutil"
19+
"github.com/llamastack/llama-stack-client-go/option"
20+
)
21+
22+
func TestAlphaAdminHealth(t *testing.T) {
23+
baseURL := "http://localhost:4010"
24+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
25+
baseURL = envURL
26+
}
27+
if !testutil.CheckTestServer(t, baseURL) {
28+
return
29+
}
30+
client := llamastackclient.NewClient(
31+
option.WithBaseURL(baseURL),
32+
)
33+
_, err := client.Alpha.Admin.Health(context.TODO())
34+
if err != nil {
35+
var apierr *llamastackclient.Error
36+
if errors.As(err, &apierr) {
37+
t.Log(string(apierr.DumpRequest(true)))
38+
}
39+
t.Fatalf("err should be nil: %s", err.Error())
40+
}
41+
}
42+
43+
func TestAlphaAdminInspectProvider(t *testing.T) {
44+
baseURL := "http://localhost:4010"
45+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
46+
baseURL = envURL
47+
}
48+
if !testutil.CheckTestServer(t, baseURL) {
49+
return
50+
}
51+
client := llamastackclient.NewClient(
52+
option.WithBaseURL(baseURL),
53+
)
54+
_, err := client.Alpha.Admin.InspectProvider(context.TODO(), "provider_id")
55+
if err != nil {
56+
var apierr *llamastackclient.Error
57+
if errors.As(err, &apierr) {
58+
t.Log(string(apierr.DumpRequest(true)))
59+
}
60+
t.Fatalf("err should be nil: %s", err.Error())
61+
}
62+
}
63+
64+
func TestAlphaAdminListProviders(t *testing.T) {
65+
baseURL := "http://localhost:4010"
66+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
67+
baseURL = envURL
68+
}
69+
if !testutil.CheckTestServer(t, baseURL) {
70+
return
71+
}
72+
client := llamastackclient.NewClient(
73+
option.WithBaseURL(baseURL),
74+
)
75+
_, err := client.Alpha.Admin.ListProviders(context.TODO())
76+
if err != nil {
77+
var apierr *llamastackclient.Error
78+
if errors.As(err, &apierr) {
79+
t.Log(string(apierr.DumpRequest(true)))
80+
}
81+
t.Fatalf("err should be nil: %s", err.Error())
82+
}
83+
}
84+
85+
func TestAlphaAdminListRoutesWithOptionalParams(t *testing.T) {
86+
baseURL := "http://localhost:4010"
87+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
88+
baseURL = envURL
89+
}
90+
if !testutil.CheckTestServer(t, baseURL) {
91+
return
92+
}
93+
client := llamastackclient.NewClient(
94+
option.WithBaseURL(baseURL),
95+
)
96+
_, err := client.Alpha.Admin.ListRoutes(context.TODO(), llamastackclient.AlphaAdminListRoutesParams{
97+
APIFilter: llamastackclient.AlphaAdminListRoutesParamsAPIFilterV1,
98+
})
99+
if err != nil {
100+
var apierr *llamastackclient.Error
101+
if errors.As(err, &apierr) {
102+
t.Log(string(apierr.DumpRequest(true)))
103+
}
104+
t.Fatalf("err should be nil: %s", err.Error())
105+
}
106+
}
107+
108+
func TestAlphaAdminVersion(t *testing.T) {
109+
baseURL := "http://localhost:4010"
110+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
111+
baseURL = envURL
112+
}
113+
if !testutil.CheckTestServer(t, baseURL) {
114+
return
115+
}
116+
client := llamastackclient.NewClient(
117+
option.WithBaseURL(baseURL),
118+
)
119+
_, err := client.Alpha.Admin.Version(context.TODO())
120+
if err != nil {
121+
var apierr *llamastackclient.Error
122+
if errors.As(err, &apierr) {
123+
t.Log(string(apierr.DumpRequest(true)))
124+
}
125+
t.Fatalf("err should be nil: %s", err.Error())
126+
}
127+
}

0 commit comments

Comments
 (0)