From 9a3268eec5c8126fbe65dbbfc9f8eb918dc2f0d0 Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Mon, 17 Apr 2023 19:50:47 -0700 Subject: [PATCH] refactor model names --- api_history.go | 172 +++++++++++++++++++++++------------------------ client/client.go | 9 +++ types/types.go | 115 ++++++++++--------------------- 3 files changed, 129 insertions(+), 167 deletions(-) create mode 100644 client/client.go diff --git a/api_history.go b/api_history.go index f6fbdfa..22ca83e 100644 --- a/api_history.go +++ b/api_history.go @@ -1,4 +1,3 @@ - /* * ElevenLabs API Documentation * @@ -11,12 +10,14 @@ package swagger import ( "context" + "fmt" "io/ioutil" "net/http" "net/url" "strings" - "fmt" + "github.com/antihax/optional" + "github.com/taigrr/elevenlabs/types" ) // Linger please @@ -24,7 +25,6 @@ var ( _ context.Context ) -type HistoryApiService service /* HistoryApiService Delete History Item Delete a history item by its ID @@ -35,16 +35,12 @@ Delete a history item by its ID @return Object */ -type HistoryApiDeleteHistoryItemV1HistoryHistoryItemIdDeleteOpts struct { - XiApiKey optional.String -} - func (a *HistoryApiService) DeleteHistoryItemV1HistoryHistoryItemIdDelete(ctx context.Context, historyItemId string, localVarOptionals *HistoryApiDeleteHistoryItemV1HistoryHistoryItemIdDeleteOpts) (Object, *http.Response, error) { var ( - localVarHttpMethod = strings.ToUpper("Delete") - localVarPostBody interface{} - localVarFileName string - localVarFileBytes []byte + localVarHttpMethod = strings.ToUpper("Delete") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte localVarReturnValue Object ) @@ -94,42 +90,43 @@ func (a *HistoryApiService) DeleteHistoryItemV1HistoryHistoryItemIdDelete(ctx co if localVarHttpResponse.StatusCode < 300 { // If we succeed, return the data, otherwise pass on to decode error. - err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); - if err == nil { + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if err == nil { return localVarReturnValue, localVarHttpResponse, err } } if localVarHttpResponse.StatusCode >= 300 { newErr := GenericSwaggerError{ - body: localVarBody, + body: localVarBody, error: localVarHttpResponse.Status, } if localVarHttpResponse.StatusCode == 200 { var v Object - err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); - if err != nil { - newErr.error = err.Error() - return localVarReturnValue, localVarHttpResponse, newErr - } - newErr.model = v + err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() return localVarReturnValue, localVarHttpResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHttpResponse, newErr } if localVarHttpResponse.StatusCode == 422 { var v HttpValidationError - err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); - if err != nil { - newErr.error = err.Error() - return localVarReturnValue, localVarHttpResponse, newErr - } - newErr.model = v + err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() return localVarReturnValue, localVarHttpResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHttpResponse, newErr } return localVarReturnValue, localVarHttpResponse, newErr } return localVarReturnValue, localVarHttpResponse, nil } + /* HistoryApiService Delete History Items Delete a number of history items by their IDs. @@ -141,15 +138,15 @@ Delete a number of history items by their IDs. */ type HistoryApiDeleteHistoryItemsV1HistoryDeletePostOpts struct { - XiApiKey optional.String + XiApiKey optional.String } func (a *HistoryApiService) DeleteHistoryItemsV1HistoryDeletePost(ctx context.Context, body BodyDeleteHistoryItemsV1HistoryDeletePost, localVarOptionals *HistoryApiDeleteHistoryItemsV1HistoryDeletePostOpts) (Object, *http.Response, error) { var ( - localVarHttpMethod = strings.ToUpper("Post") - localVarPostBody interface{} - localVarFileName string - localVarFileBytes []byte + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte localVarReturnValue Object ) @@ -200,42 +197,43 @@ func (a *HistoryApiService) DeleteHistoryItemsV1HistoryDeletePost(ctx context.Co if localVarHttpResponse.StatusCode < 300 { // If we succeed, return the data, otherwise pass on to decode error. - err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); - if err == nil { + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if err == nil { return localVarReturnValue, localVarHttpResponse, err } } if localVarHttpResponse.StatusCode >= 300 { newErr := GenericSwaggerError{ - body: localVarBody, + body: localVarBody, error: localVarHttpResponse.Status, } if localVarHttpResponse.StatusCode == 200 { var v Object - err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); - if err != nil { - newErr.error = err.Error() - return localVarReturnValue, localVarHttpResponse, newErr - } - newErr.model = v + err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() return localVarReturnValue, localVarHttpResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHttpResponse, newErr } if localVarHttpResponse.StatusCode == 422 { var v HttpValidationError - err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); - if err != nil { - newErr.error = err.Error() - return localVarReturnValue, localVarHttpResponse, newErr - } - newErr.model = v + err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() return localVarReturnValue, localVarHttpResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHttpResponse, newErr } return localVarReturnValue, localVarHttpResponse, newErr } return localVarReturnValue, localVarHttpResponse, nil } + /* HistoryApiService Download History Items Download one or more history items. If one history item ID is provided, we will return a single audio file. If more than one history item IDs are provided, we will provide the history items packed into a .zip file. @@ -247,7 +245,7 @@ Download one or more history items. If one history item ID is provided, we will */ type HistoryApiDownloadHistoryItemsV1HistoryDownloadPostOpts struct { - XiApiKey optional.String + XiApiKey optional.String } func (a *HistoryApiService) DownloadHistoryItemsV1HistoryDownloadPost(ctx context.Context, body BodyDownloadHistoryItemsV1HistoryDownloadPost, localVarOptionals *HistoryApiDownloadHistoryItemsV1HistoryDownloadPostOpts) (*http.Response, error) { @@ -256,7 +254,6 @@ func (a *HistoryApiService) DownloadHistoryItemsV1HistoryDownloadPost(ctx contex localVarPostBody interface{} localVarFileName string localVarFileBytes []byte - ) // create path and map variables @@ -304,27 +301,27 @@ func (a *HistoryApiService) DownloadHistoryItemsV1HistoryDownloadPost(ctx contex return localVarHttpResponse, err } - if localVarHttpResponse.StatusCode >= 300 { newErr := GenericSwaggerError{ - body: localVarBody, + body: localVarBody, error: localVarHttpResponse.Status, } if localVarHttpResponse.StatusCode == 422 { var v HttpValidationError - err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); - if err != nil { - newErr.error = err.Error() - return localVarHttpResponse, newErr - } - newErr.model = v + err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() return localVarHttpResponse, newErr + } + newErr.model = v + return localVarHttpResponse, newErr } return localVarHttpResponse, newErr } return localVarHttpResponse, nil } + /* HistoryApiService Get Audio From History Item Returns the audio of an history item. @@ -336,7 +333,7 @@ Returns the audio of an history item. */ type HistoryApiGetAudioFromHistoryItemV1HistoryHistoryItemIdAudioGetOpts struct { - XiApiKey optional.String + XiApiKey optional.String } func (a *HistoryApiService) GetAudioFromHistoryItemV1HistoryHistoryItemIdAudioGet(ctx context.Context, historyItemId string, localVarOptionals *HistoryApiGetAudioFromHistoryItemV1HistoryHistoryItemIdAudioGetOpts) (*http.Response, error) { @@ -345,7 +342,6 @@ func (a *HistoryApiService) GetAudioFromHistoryItemV1HistoryHistoryItemIdAudioGe localVarPostBody interface{} localVarFileName string localVarFileBytes []byte - ) // create path and map variables @@ -392,27 +388,27 @@ func (a *HistoryApiService) GetAudioFromHistoryItemV1HistoryHistoryItemIdAudioGe return localVarHttpResponse, err } - if localVarHttpResponse.StatusCode >= 300 { newErr := GenericSwaggerError{ - body: localVarBody, + body: localVarBody, error: localVarHttpResponse.Status, } if localVarHttpResponse.StatusCode == 422 { var v HttpValidationError - err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); - if err != nil { - newErr.error = err.Error() - return localVarHttpResponse, newErr - } - newErr.model = v + err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() return localVarHttpResponse, newErr + } + newErr.model = v + return localVarHttpResponse, newErr } return localVarHttpResponse, newErr } return localVarHttpResponse, nil } + /* HistoryApiService Get Generated Items Returns metadata about all your generated audio. @@ -423,16 +419,16 @@ Returns metadata about all your generated audio. */ type HistoryApiGetGeneratedItemsV1HistoryGetOpts struct { - XiApiKey optional.String + XiApiKey optional.String } -func (a *HistoryApiService) GetGeneratedItemsV1HistoryGet(ctx context.Context, localVarOptionals *HistoryApiGetGeneratedItemsV1HistoryGetOpts) (GetHistoryResponseModel, *http.Response, error) { +func GetGeneratedItemsV1HistoryGet(ctx context.Context, localVarOptionals *HistoryApiGetGeneratedItemsV1HistoryGetOpts) (types.GetHistoryResponseModel, *http.Response, error) { var ( - localVarHttpMethod = strings.ToUpper("Get") - localVarPostBody interface{} - localVarFileName string - localVarFileBytes []byte - localVarReturnValue GetHistoryResponseModel + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + localVarReturnValue types.GetHistoryResponseModel ) // create path and map variables @@ -480,36 +476,36 @@ func (a *HistoryApiService) GetGeneratedItemsV1HistoryGet(ctx context.Context, l if localVarHttpResponse.StatusCode < 300 { // If we succeed, return the data, otherwise pass on to decode error. - err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); - if err == nil { + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if err == nil { return localVarReturnValue, localVarHttpResponse, err } } if localVarHttpResponse.StatusCode >= 300 { newErr := GenericSwaggerError{ - body: localVarBody, + body: localVarBody, error: localVarHttpResponse.Status, } if localVarHttpResponse.StatusCode == 200 { var v GetHistoryResponseModel - err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); - if err != nil { - newErr.error = err.Error() - return localVarReturnValue, localVarHttpResponse, newErr - } - newErr.model = v + err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() return localVarReturnValue, localVarHttpResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHttpResponse, newErr } if localVarHttpResponse.StatusCode == 422 { var v HttpValidationError - err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); - if err != nil { - newErr.error = err.Error() - return localVarReturnValue, localVarHttpResponse, newErr - } - newErr.model = v + err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() return localVarReturnValue, localVarHttpResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHttpResponse, newErr } return localVarReturnValue, localVarHttpResponse, newErr } diff --git a/client/client.go b/client/client.go new file mode 100644 index 0000000..5964707 --- /dev/null +++ b/client/client.go @@ -0,0 +1,9 @@ +package client + +type Client struct { + apiKey string +} + +func New(apiKey string) Client { + return Client{apiKey: apiKey} +} diff --git a/types/types.go b/types/types.go index 6f4c667..832c980 100644 --- a/types/types.go +++ b/types/types.go @@ -2,65 +2,31 @@ package types import "os" -type AddVoiceResponseModel struct { - VoiceId string `json:"voice_id"` -} - -// Voice settings overriding stored setttings for the given voice. They are applied only on the given TTS request. -type AllOfBodyTextToSpeechV1TextToSpeechVoiceIdPostVoiceSettings struct { - Stability float64 `json:"stability"` - SimilarityBoost float64 `json:"similarity_boost"` -} - -// Voice settings overriding stored setttings for the given voice. They are applied only on the given TTS request. -type AllOfBodyTextToSpeechV1TextToSpeechVoiceIdStreamPostVoiceSettings struct { - Stability float64 `json:"stability"` - SimilarityBoost float64 `json:"similarity_boost"` +type AddVoiceResponse struct { + VoiceID string `json:"voice_id"` } type AnyOfValidationErrorLocItems struct{} -type BodyAddVoiceV1VoicesAddPost struct { - // The name that identifies this voice. This will be displayed in the dropdown of the website. - Name string `json:"name"` - // One or more audio files to clone the voice from - Files []*os.File `json:"files"` - // How would you describe the voice? - Description string `json:"description,omitempty"` - // Serialized labels dictionary for the voice. - Labels string `json:"labels,omitempty"` +type HistoryPost struct { + HistoryItemIds []string `json:"history_item_ids"` +} +type Voice struct { + Name string `json:"name"` // The name that identifies this voice. This will be displayed in the dropdown of the website. + Files []*os.File `json:"files,omitempty"` // Audio files to add to the voice + Description string `json:"description,omitempty"` // How would you describe the voice? + Labels string `json:"labels,omitempty"` // Serialized labels dictionary for the voice. +} +type TTS struct { + Text string `json:"text"` // The text that will get converted into speech. Currently only English text is supported. + VoiceSettings SynthesisOptions `json:"voice_settings,omitempty"` // Voice settings are applied only on the given TTS request. } -type BodyDeleteHistoryItemsV1HistoryDeletePost struct { - // A list of history items to remove, you can get IDs of history items and other metadata using the GET https://api.elevenlabs.io/v1/history endpoint. - HistoryItemIds []string `json:"history_item_ids"` -} -type BodyDownloadHistoryItemsV1HistoryDownloadPost struct { - // A list of history items to download, you can get IDs of history items and other metadata using the GET https://api.elevenlabs.io/v1/history endpoint. - HistoryItemIds []string `json:"history_item_ids"` -} -type BodyEditVoiceV1VoicesVoiceIdEditPost struct { - // The name that identifies this voice. This will be displayed in the dropdown of the website. - Name string `json:"name"` - // Audio files to add to the voice - Files []*os.File `json:"files,omitempty"` - // How would you describe the voice? - Description string `json:"description,omitempty"` - // Serialized labels dictionary for the voice. - Labels string `json:"labels,omitempty"` -} -type BodyTextToSpeechV1TextToSpeechVoiceIdPost struct { - // The text that will get converted into speech. Currently only English text is supported. - Text string `json:"text"` - // Voice settings overriding stored setttings for the given voice. They are applied only on the given TTS request. - VoiceSettings *AllOfBodyTextToSpeechV1TextToSpeechVoiceIdPostVoiceSettings `json:"voice_settings,omitempty"` -} -type BodyTextToSpeechV1TextToSpeechVoiceIdStreamPost struct { - // The text that will get converted into speech. Currently only English text is supported. - Text string `json:"text"` - // Voice settings overriding stored setttings for the given voice. They are applied only on the given TTS request. - VoiceSettings *AllOfBodyTextToSpeechV1TextToSpeechVoiceIdStreamPostVoiceSettings `json:"voice_settings,omitempty"` +type SynthesisOptions struct { + Stability float64 `json:"stability"` + SimilarityBoost float64 `json:"similarity_boost"` } + type ExtendedSubscriptionResponseModel struct { Tier string `json:"tier"` CharacterCount int32 `json:"character_count"` @@ -77,7 +43,7 @@ type ExtendedSubscriptionResponseModel struct { CanUseDelayedPaymentMethods bool `json:"can_use_delayed_payment_methods"` Currency string `json:"currency"` Status string `json:"status"` - NextInvoice *InvoiceResponseModel `json:"next_invoice"` + NextInvoice InvoiceResponseModel `json:"next_invoice"` } type FeedbackResponseModel struct { ThumbsUp bool `json:"thumbs_up"` @@ -90,7 +56,7 @@ type FeedbackResponseModel struct { ReviewStatus string `json:"review_status,omitempty"` } type FineTuningResponseModel struct { - ModelId string `json:"model_id"` + ModelID string `json:"model_id"` IsAllowedToFineTune bool `json:"is_allowed_to_fine_tune"` FineTuningRequested bool `json:"fine_tuning_requested"` FinetuningState string `json:"finetuning_state"` @@ -122,7 +88,7 @@ type HistoryItemResponseModel struct { type HttpValidationError struct { Detail []ValidationError `json:"detail,omitempty"` } -type InvoiceResponseModel struct { +type Invoice struct { AmountDueCents int32 `json:"amount_due_cents"` NextPaymentAttemptUnix int32 `json:"next_payment_attempt_unix"` } @@ -137,7 +103,7 @@ type RecordingResponseModel struct { UploadDateUnix int32 `json:"upload_date_unix"` Transcription string `json:"transcription"` } -type SampleResponseModel struct { +type Sample struct { SampleId string `json:"sample_id"` FileName string `json:"file_name"` MimeType string `json:"mime_type"` @@ -145,12 +111,7 @@ type SampleResponseModel struct { Hash string `json:"hash"` } -// The settings for a specific voice. -type Settings struct { - Stability float64 `json:"stability"` - SimilarityBoost float64 `json:"similarity_boost"` -} -type SubscriptionResponseModel struct { +type Subscription struct { Tier string `json:"tier"` CharacterCount int32 `json:"character_count"` CharacterLimit int32 `json:"character_limit"` @@ -173,9 +134,9 @@ type TtsModelResponseModel struct { SupportedLanguage []LanguageResponseModel `json:"supported_language"` } type UserResponseModel struct { - Subscription *SubscriptionResponseModel `json:"subscription"` - IsNewUser bool `json:"is_new_user"` - XiApiKey string `json:"xi_api_key"` + Subscription Subscription `json:"subscription"` + IsNewUser bool `json:"is_new_user"` + XiAPIKey string `json:"xi_api_key"` } type ValidationError struct { Loc []AnyOfValidationErrorLocItems `json:"loc"` @@ -191,18 +152,14 @@ type VerificationAttemptResponseModel struct { Recording *RecordingResponseModel `json:"recording"` } type VoiceResponseModel struct { - VoiceId string `json:"voice_id"` - Name string `json:"name"` - Samples []SampleResponseModel `json:"samples"` - Category string `json:"category"` - FineTuning *FineTuningResponseModel `json:"fine_tuning"` - Labels map[string]string `json:"labels"` - Description string `json:"description"` - PreviewUrl string `json:"preview_url"` - AvailableForTiers []string `json:"available_for_tiers"` - Settings *VoiceSettingsResponseModel `json:"settings"` -} -type VoiceSettingsResponseModel struct { - Stability float64 `json:"stability"` - SimilarityBoost float64 `json:"similarity_boost"` + VoiceId string `json:"voice_id"` + Name string `json:"name"` + Samples []Sample `json:"samples"` + Category string `json:"category"` + FineTuning FineTuningResponseModel `json:"fine_tuning"` + Labels map[string]string `json:"labels"` + Description string `json:"description"` + PreviewUrl string `json:"preview_url"` + AvailableForTiers []string `json:"available_for_tiers"` + Settings SynthesisOptions `json:"settings"` }