Skip to content

Commit 0aacf5d

Browse files
feat(api): Add audio.voices.list sdk
1 parent 22538fe commit 0aacf5d

File tree

5 files changed

+145
-2
lines changed

5 files changed

+145
-2
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 44
1+
configured_endpoints: 45
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/togetherai%2Ftogetherai-e63ffcd87a8f3f9a97e523c95927843e7e4ce8e2788aec58a16313759eb4cee8.yml
33
openapi_spec_hash: 2772702ed4747586ac0776fcd227e41f
4-
config_hash: acbe45d94a426c68447621ec5213405e
4+
config_hash: 5e9563faf41fd9a91bea97783683bdb2

api.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,16 @@ Methods:
177177

178178
- <code title="post /audio/speech">client.Audio.<a href="https://pkg.go.dev/github.com/togethercomputer/together-go#AudioService.New">New</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/togethercomputer/together-go">together</a>.<a href="https://pkg.go.dev/github.com/togethercomputer/together-go#AudioNewParams">AudioNewParams</a>) (http.Response, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
179179

180+
## Voices
181+
182+
Response Types:
183+
184+
- <a href="https://pkg.go.dev/github.com/togethercomputer/together-go">together</a>.<a href="https://pkg.go.dev/github.com/togethercomputer/together-go#AudioVoiceListResponse">AudioVoiceListResponse</a>
185+
186+
Methods:
187+
188+
- <code title="get /voices">client.Audio.Voices.<a href="https://pkg.go.dev/github.com/togethercomputer/together-go#AudioVoiceService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>) (<a href="https://pkg.go.dev/github.com/togethercomputer/together-go">together</a>.<a href="https://pkg.go.dev/github.com/togethercomputer/together-go#AudioVoiceListResponse">AudioVoiceListResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
189+
180190
## Transcriptions
181191

182192
Response Types:

audio.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
// the [NewAudioService] method instead.
2424
type AudioService struct {
2525
Options []option.RequestOption
26+
Voices AudioVoiceService
2627
Transcriptions AudioTranscriptionService
2728
Translations AudioTranslationService
2829
}
@@ -33,6 +34,7 @@ type AudioService struct {
3334
func NewAudioService(opts ...option.RequestOption) (r AudioService) {
3435
r = AudioService{}
3536
r.Options = opts
37+
r.Voices = NewAudioVoiceService(opts...)
3638
r.Transcriptions = NewAudioTranscriptionService(opts...)
3739
r.Translations = NewAudioTranslationService(opts...)
3840
return

audiovoice.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package together
4+
5+
import (
6+
"context"
7+
"net/http"
8+
"slices"
9+
10+
"github.com/togethercomputer/together-go/internal/apijson"
11+
"github.com/togethercomputer/together-go/internal/requestconfig"
12+
"github.com/togethercomputer/together-go/option"
13+
"github.com/togethercomputer/together-go/packages/respjson"
14+
)
15+
16+
// AudioVoiceService contains methods and other services that help with interacting
17+
// with the together 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 [NewAudioVoiceService] method instead.
22+
type AudioVoiceService struct {
23+
Options []option.RequestOption
24+
}
25+
26+
// NewAudioVoiceService generates a new service that applies the given options to
27+
// each request. These options are applied after the parent client's options (if
28+
// there is one), and before any request-specific options.
29+
func NewAudioVoiceService(opts ...option.RequestOption) (r AudioVoiceService) {
30+
r = AudioVoiceService{}
31+
r.Options = opts
32+
return
33+
}
34+
35+
// Fetch available voices for each model
36+
func (r *AudioVoiceService) List(ctx context.Context, opts ...option.RequestOption) (res *AudioVoiceListResponse, err error) {
37+
opts = slices.Concat(r.Options, opts)
38+
path := "voices"
39+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
40+
return
41+
}
42+
43+
// Response containing a list of models and their available voices.
44+
type AudioVoiceListResponse struct {
45+
Data []AudioVoiceListResponseData `json:"data,required"`
46+
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
47+
JSON struct {
48+
Data respjson.Field
49+
ExtraFields map[string]respjson.Field
50+
raw string
51+
} `json:"-"`
52+
}
53+
54+
// Returns the unmodified JSON received from the API
55+
func (r AudioVoiceListResponse) RawJSON() string { return r.JSON.raw }
56+
func (r *AudioVoiceListResponse) UnmarshalJSON(data []byte) error {
57+
return apijson.UnmarshalRoot(data, r)
58+
}
59+
60+
// Represents a model with its available voices.
61+
type AudioVoiceListResponseData struct {
62+
Model string `json:"model,required"`
63+
Voices []AudioVoiceListResponseDataVoice `json:"voices,required"`
64+
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
65+
JSON struct {
66+
Model respjson.Field
67+
Voices respjson.Field
68+
ExtraFields map[string]respjson.Field
69+
raw string
70+
} `json:"-"`
71+
}
72+
73+
// Returns the unmodified JSON received from the API
74+
func (r AudioVoiceListResponseData) RawJSON() string { return r.JSON.raw }
75+
func (r *AudioVoiceListResponseData) UnmarshalJSON(data []byte) error {
76+
return apijson.UnmarshalRoot(data, r)
77+
}
78+
79+
type AudioVoiceListResponseDataVoice struct {
80+
ID string `json:"id,required"`
81+
Name string `json:"name,required"`
82+
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
83+
JSON struct {
84+
ID respjson.Field
85+
Name respjson.Field
86+
ExtraFields map[string]respjson.Field
87+
raw string
88+
} `json:"-"`
89+
}
90+
91+
// Returns the unmodified JSON received from the API
92+
func (r AudioVoiceListResponseDataVoice) RawJSON() string { return r.JSON.raw }
93+
func (r *AudioVoiceListResponseDataVoice) UnmarshalJSON(data []byte) error {
94+
return apijson.UnmarshalRoot(data, r)
95+
}

audiovoice_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package together_test
4+
5+
import (
6+
"context"
7+
"errors"
8+
"os"
9+
"testing"
10+
11+
"github.com/togethercomputer/together-go"
12+
"github.com/togethercomputer/together-go/internal/testutil"
13+
"github.com/togethercomputer/together-go/option"
14+
)
15+
16+
func TestAudioVoiceList(t *testing.T) {
17+
baseURL := "http://localhost:4010"
18+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
19+
baseURL = envURL
20+
}
21+
if !testutil.CheckTestServer(t, baseURL) {
22+
return
23+
}
24+
client := together.NewClient(
25+
option.WithBaseURL(baseURL),
26+
option.WithAPIKey("My API Key"),
27+
)
28+
_, err := client.Audio.Voices.List(context.TODO())
29+
if err != nil {
30+
var apierr *together.Error
31+
if errors.As(err, &apierr) {
32+
t.Log(string(apierr.DumpRequest(true)))
33+
}
34+
t.Fatalf("err should be nil: %s", err.Error())
35+
}
36+
}

0 commit comments

Comments
 (0)