together 1.5.17__py3-none-any.whl → 2.0.0a8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. together/__init__.py +101 -63
  2. together/_base_client.py +1995 -0
  3. together/_client.py +1033 -0
  4. together/_compat.py +219 -0
  5. together/_constants.py +14 -0
  6. together/_exceptions.py +108 -0
  7. together/_files.py +123 -0
  8. together/_models.py +857 -0
  9. together/_qs.py +150 -0
  10. together/_resource.py +43 -0
  11. together/_response.py +830 -0
  12. together/_streaming.py +370 -0
  13. together/_types.py +260 -0
  14. together/_utils/__init__.py +64 -0
  15. together/_utils/_compat.py +45 -0
  16. together/_utils/_datetime_parse.py +136 -0
  17. together/_utils/_logs.py +25 -0
  18. together/_utils/_proxy.py +65 -0
  19. together/_utils/_reflection.py +42 -0
  20. together/_utils/_resources_proxy.py +24 -0
  21. together/_utils/_streams.py +12 -0
  22. together/_utils/_sync.py +58 -0
  23. together/_utils/_transform.py +457 -0
  24. together/_utils/_typing.py +156 -0
  25. together/_utils/_utils.py +421 -0
  26. together/_version.py +4 -0
  27. together/lib/.keep +4 -0
  28. together/lib/__init__.py +23 -0
  29. together/{cli → lib/cli}/api/endpoints.py +108 -75
  30. together/lib/cli/api/evals.py +588 -0
  31. together/{cli → lib/cli}/api/files.py +20 -17
  32. together/{cli/api/finetune.py → lib/cli/api/fine_tuning.py} +161 -120
  33. together/lib/cli/api/models.py +140 -0
  34. together/{cli → lib/cli}/api/utils.py +6 -7
  35. together/{cli → lib/cli}/cli.py +16 -24
  36. together/{constants.py → lib/constants.py} +17 -12
  37. together/lib/resources/__init__.py +11 -0
  38. together/lib/resources/files.py +999 -0
  39. together/lib/resources/fine_tuning.py +280 -0
  40. together/lib/resources/models.py +35 -0
  41. together/lib/types/__init__.py +13 -0
  42. together/lib/types/error.py +9 -0
  43. together/lib/types/fine_tuning.py +455 -0
  44. together/{utils → lib/utils}/__init__.py +6 -14
  45. together/{utils → lib/utils}/_log.py +11 -16
  46. together/lib/utils/files.py +628 -0
  47. together/lib/utils/serializer.py +10 -0
  48. together/{utils → lib/utils}/tools.py +19 -55
  49. together/resources/__init__.py +225 -33
  50. together/resources/audio/__init__.py +72 -21
  51. together/resources/audio/audio.py +198 -0
  52. together/resources/audio/speech.py +574 -122
  53. together/resources/audio/transcriptions.py +282 -0
  54. together/resources/audio/translations.py +256 -0
  55. together/resources/audio/voices.py +135 -0
  56. together/resources/batches.py +417 -0
  57. together/resources/chat/__init__.py +30 -21
  58. together/resources/chat/chat.py +102 -0
  59. together/resources/chat/completions.py +1063 -263
  60. together/resources/code_interpreter/__init__.py +33 -0
  61. together/resources/code_interpreter/code_interpreter.py +258 -0
  62. together/resources/code_interpreter/sessions.py +135 -0
  63. together/resources/completions.py +884 -225
  64. together/resources/embeddings.py +172 -68
  65. together/resources/endpoints.py +598 -395
  66. together/resources/evals.py +452 -0
  67. together/resources/files.py +398 -121
  68. together/resources/fine_tuning.py +1033 -0
  69. together/resources/hardware.py +181 -0
  70. together/resources/images.py +256 -108
  71. together/resources/jobs.py +214 -0
  72. together/resources/models.py +238 -90
  73. together/resources/rerank.py +190 -92
  74. together/resources/videos.py +374 -0
  75. together/types/__init__.py +65 -109
  76. together/types/audio/__init__.py +10 -0
  77. together/types/audio/speech_create_params.py +75 -0
  78. together/types/audio/transcription_create_params.py +54 -0
  79. together/types/audio/transcription_create_response.py +111 -0
  80. together/types/audio/translation_create_params.py +40 -0
  81. together/types/audio/translation_create_response.py +70 -0
  82. together/types/audio/voice_list_response.py +23 -0
  83. together/types/audio_speech_stream_chunk.py +16 -0
  84. together/types/autoscaling.py +13 -0
  85. together/types/autoscaling_param.py +15 -0
  86. together/types/batch_create_params.py +24 -0
  87. together/types/batch_create_response.py +14 -0
  88. together/types/batch_job.py +45 -0
  89. together/types/batch_list_response.py +10 -0
  90. together/types/chat/__init__.py +18 -0
  91. together/types/chat/chat_completion.py +60 -0
  92. together/types/chat/chat_completion_chunk.py +61 -0
  93. together/types/chat/chat_completion_structured_message_image_url_param.py +18 -0
  94. together/types/chat/chat_completion_structured_message_text_param.py +13 -0
  95. together/types/chat/chat_completion_structured_message_video_url_param.py +18 -0
  96. together/types/chat/chat_completion_usage.py +13 -0
  97. together/types/chat/chat_completion_warning.py +9 -0
  98. together/types/chat/completion_create_params.py +329 -0
  99. together/types/code_interpreter/__init__.py +5 -0
  100. together/types/code_interpreter/session_list_response.py +31 -0
  101. together/types/code_interpreter_execute_params.py +45 -0
  102. together/types/completion.py +42 -0
  103. together/types/completion_chunk.py +66 -0
  104. together/types/completion_create_params.py +138 -0
  105. together/types/dedicated_endpoint.py +44 -0
  106. together/types/embedding.py +24 -0
  107. together/types/embedding_create_params.py +31 -0
  108. together/types/endpoint_create_params.py +43 -0
  109. together/types/endpoint_list_avzones_response.py +11 -0
  110. together/types/endpoint_list_params.py +18 -0
  111. together/types/endpoint_list_response.py +41 -0
  112. together/types/endpoint_update_params.py +27 -0
  113. together/types/eval_create_params.py +263 -0
  114. together/types/eval_create_response.py +16 -0
  115. together/types/eval_list_params.py +21 -0
  116. together/types/eval_list_response.py +10 -0
  117. together/types/eval_status_response.py +100 -0
  118. together/types/evaluation_job.py +139 -0
  119. together/types/execute_response.py +108 -0
  120. together/types/file_delete_response.py +13 -0
  121. together/types/file_list.py +12 -0
  122. together/types/file_purpose.py +9 -0
  123. together/types/file_response.py +31 -0
  124. together/types/file_type.py +7 -0
  125. together/types/fine_tuning_cancel_response.py +194 -0
  126. together/types/fine_tuning_content_params.py +24 -0
  127. together/types/fine_tuning_delete_params.py +11 -0
  128. together/types/fine_tuning_delete_response.py +12 -0
  129. together/types/fine_tuning_list_checkpoints_response.py +21 -0
  130. together/types/fine_tuning_list_events_response.py +12 -0
  131. together/types/fine_tuning_list_response.py +199 -0
  132. together/types/finetune_event.py +41 -0
  133. together/types/finetune_event_type.py +33 -0
  134. together/types/finetune_response.py +177 -0
  135. together/types/hardware_list_params.py +16 -0
  136. together/types/hardware_list_response.py +58 -0
  137. together/types/image_data_b64.py +15 -0
  138. together/types/image_data_url.py +15 -0
  139. together/types/image_file.py +23 -0
  140. together/types/image_generate_params.py +85 -0
  141. together/types/job_list_response.py +47 -0
  142. together/types/job_retrieve_response.py +43 -0
  143. together/types/log_probs.py +18 -0
  144. together/types/model_list_response.py +10 -0
  145. together/types/model_object.py +42 -0
  146. together/types/model_upload_params.py +36 -0
  147. together/types/model_upload_response.py +23 -0
  148. together/types/rerank_create_params.py +36 -0
  149. together/types/rerank_create_response.py +36 -0
  150. together/types/tool_choice.py +23 -0
  151. together/types/tool_choice_param.py +23 -0
  152. together/types/tools_param.py +23 -0
  153. together/types/training_method_dpo.py +22 -0
  154. together/types/training_method_sft.py +18 -0
  155. together/types/video_create_params.py +86 -0
  156. together/types/video_job.py +57 -0
  157. together-2.0.0a8.dist-info/METADATA +680 -0
  158. together-2.0.0a8.dist-info/RECORD +164 -0
  159. {together-1.5.17.dist-info → together-2.0.0a8.dist-info}/WHEEL +1 -1
  160. together-2.0.0a8.dist-info/entry_points.txt +2 -0
  161. {together-1.5.17.dist-info → together-2.0.0a8.dist-info/licenses}/LICENSE +1 -1
  162. together/abstract/api_requestor.py +0 -729
  163. together/cli/api/chat.py +0 -276
  164. together/cli/api/completions.py +0 -119
  165. together/cli/api/images.py +0 -93
  166. together/cli/api/models.py +0 -55
  167. together/client.py +0 -176
  168. together/error.py +0 -194
  169. together/filemanager.py +0 -389
  170. together/legacy/__init__.py +0 -0
  171. together/legacy/base.py +0 -27
  172. together/legacy/complete.py +0 -93
  173. together/legacy/embeddings.py +0 -27
  174. together/legacy/files.py +0 -146
  175. together/legacy/finetune.py +0 -177
  176. together/legacy/images.py +0 -27
  177. together/legacy/models.py +0 -44
  178. together/resources/batch.py +0 -136
  179. together/resources/code_interpreter.py +0 -82
  180. together/resources/finetune.py +0 -1064
  181. together/together_response.py +0 -50
  182. together/types/abstract.py +0 -26
  183. together/types/audio_speech.py +0 -110
  184. together/types/batch.py +0 -53
  185. together/types/chat_completions.py +0 -197
  186. together/types/code_interpreter.py +0 -57
  187. together/types/common.py +0 -66
  188. together/types/completions.py +0 -107
  189. together/types/embeddings.py +0 -35
  190. together/types/endpoints.py +0 -123
  191. together/types/error.py +0 -16
  192. together/types/files.py +0 -90
  193. together/types/finetune.py +0 -398
  194. together/types/images.py +0 -44
  195. together/types/models.py +0 -45
  196. together/types/rerank.py +0 -43
  197. together/utils/api_helpers.py +0 -124
  198. together/utils/files.py +0 -425
  199. together/version.py +0 -6
  200. together-1.5.17.dist-info/METADATA +0 -525
  201. together-1.5.17.dist-info/RECORD +0 -69
  202. together-1.5.17.dist-info/entry_points.txt +0 -3
  203. /together/{abstract → lib/cli}/__init__.py +0 -0
  204. /together/{cli → lib/cli/api}/__init__.py +0 -0
  205. /together/{cli/api/__init__.py → py.typed} +0 -0
@@ -1,153 +1,605 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
1
3
  from __future__ import annotations
2
4
 
3
- from typing import Any, AsyncGenerator, Dict, Iterator, List, Union
4
-
5
- from together.abstract import api_requestor
6
- from together.together_response import TogetherResponse
7
- from together.types import (
8
- AudioSpeechRequest,
9
- AudioResponseFormat,
10
- AudioLanguage,
11
- AudioResponseEncoding,
12
- AudioSpeechStreamChunk,
13
- AudioSpeechStreamEvent,
14
- AudioSpeechStreamResponse,
15
- TogetherClient,
16
- TogetherRequest,
5
+ from typing import Union
6
+ from typing_extensions import Literal, overload
7
+
8
+ import httpx
9
+
10
+ from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
11
+ from ..._utils import required_args, maybe_transform, async_maybe_transform
12
+ from ..._compat import cached_property
13
+ from ..._resource import SyncAPIResource, AsyncAPIResource
14
+ from ..._response import (
15
+ BinaryAPIResponse,
16
+ AsyncBinaryAPIResponse,
17
+ StreamedBinaryAPIResponse,
18
+ AsyncStreamedBinaryAPIResponse,
19
+ to_custom_raw_response_wrapper,
20
+ to_custom_streamed_response_wrapper,
21
+ async_to_custom_raw_response_wrapper,
22
+ async_to_custom_streamed_response_wrapper,
17
23
  )
24
+ from ..._streaming import Stream, AsyncStream
25
+ from ...types.audio import speech_create_params
26
+ from ..._base_client import make_request_options
27
+ from ...types.audio_speech_stream_chunk import AudioSpeechStreamChunk
28
+
29
+ __all__ = ["SpeechResource", "AsyncSpeechResource"]
30
+
18
31
 
32
+ class SpeechResource(SyncAPIResource):
33
+ @cached_property
34
+ def with_raw_response(self) -> SpeechResourceWithRawResponse:
35
+ """
36
+ This property can be used as a prefix for any HTTP method call to return
37
+ the raw response object instead of the parsed content.
38
+
39
+ For more information, see https://www.github.com/togethercomputer/together-py#accessing-raw-response-data-eg-headers
40
+ """
41
+ return SpeechResourceWithRawResponse(self)
42
+
43
+ @cached_property
44
+ def with_streaming_response(self) -> SpeechResourceWithStreamingResponse:
45
+ """
46
+ An alternative to `.with_raw_response` that doesn't eagerly read the response body.
19
47
 
20
- class Speech:
21
- def __init__(self, client: TogetherClient) -> None:
22
- self._client = client
48
+ For more information, see https://www.github.com/togethercomputer/together-py#with_streaming_response
49
+ """
50
+ return SpeechResourceWithStreamingResponse(self)
23
51
 
52
+ @overload
24
53
  def create(
25
54
  self,
26
55
  *,
27
- model: str,
28
56
  input: str,
29
- voice: str | None = None,
30
- response_format: str = "wav",
31
- language: str = "en",
32
- response_encoding: str = "pcm_f32le",
33
- sample_rate: int = 44100,
34
- stream: bool = False,
35
- **kwargs: Any,
36
- ) -> AudioSpeechStreamResponse:
57
+ model: Union[Literal["cartesia/sonic", "hexgrad/Kokoro-82M", "canopylabs/orpheus-3b-0.1-ft"], str],
58
+ voice: str,
59
+ language: Literal["en", "de", "fr", "es", "hi", "it", "ja", "ko", "nl", "pl", "pt", "ru", "sv", "tr", "zh"]
60
+ | Omit = omit,
61
+ response_encoding: Literal["pcm_f32le", "pcm_s16le", "pcm_mulaw", "pcm_alaw"] | Omit = omit,
62
+ response_format: Literal["mp3", "wav", "raw"] | Omit = omit,
63
+ sample_rate: int | Omit = omit,
64
+ stream: Literal[False] | Omit = omit,
65
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
66
+ # The extra values given here take precedence over values defined on the client or passed to this method.
67
+ extra_headers: Headers | None = None,
68
+ extra_query: Query | None = None,
69
+ extra_body: Body | None = None,
70
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
71
+ ) -> BinaryAPIResponse:
37
72
  """
38
- Method to generate audio from input text using a specified model.
73
+ Generate audio from input text
39
74
 
40
75
  Args:
41
- model (str): The name of the model to query.
42
- input (str): Input text to generate the audio for.
43
- voice (str, optional): The voice to use for generating the audio.
44
- Defaults to None.
45
- response_format (str, optional): The format of audio output.
46
- Defaults to "wav".
47
- language (str, optional): Language of input text.
48
- Defaults to "en".
49
- response_encoding (str, optional): Audio encoding of response.
50
- Defaults to "pcm_f32le".
51
- sample_rate (int, optional): Sampling rate to use for the output audio.
52
- Defaults to 44100.
53
- stream (bool, optional): If true, output is streamed for several characters at a time.
54
- Defaults to False.
55
-
56
- Returns:
57
- Union[bytes, Iterator[AudioSpeechStreamChunk]]: The generated audio as bytes or an iterator over audio stream chunks.
58
- """
59
-
60
- requestor = api_requestor.APIRequestor(
61
- client=self._client,
62
- )
76
+ input: Input text to generate the audio for
77
+
78
+ model: The name of the model to query.
79
+
80
+ [See all of Together AI's chat models](https://docs.together.ai/docs/serverless-models#audio-models)
81
+ The current supported tts models are: - cartesia/sonic - hexgrad/Kokoro-82M -
82
+ canopylabs/orpheus-3b-0.1-ft
83
+
84
+ voice: The voice to use for generating the audio. The voices supported are different
85
+ for each model. For eg - for canopylabs/orpheus-3b-0.1-ft, one of the voices
86
+ supported is tara, for hexgrad/Kokoro-82M, one of the voices supported is
87
+ af_alloy and for cartesia/sonic, one of the voices supported is "friendly
88
+ sidekick".
89
+
90
+ You can view the voices supported for each model using the /v1/voices endpoint
91
+ sending the model name as the query parameter.
92
+ [View all supported voices here](https://docs.together.ai/docs/text-to-speech#voices-available).
93
+
94
+ language: Language of input text.
95
+
96
+ response_encoding: Audio encoding of response
97
+
98
+ response_format: The format of audio output. Supported formats are mp3, wav, raw if streaming is
99
+ false. If streaming is true, the only supported format is raw.
100
+
101
+ sample_rate: Sampling rate to use for the output audio. The default sampling rate for
102
+ canopylabs/orpheus-3b-0.1-ft and hexgrad/Kokoro-82M is 24000 and for
103
+ cartesia/sonic is 44100.
104
+
105
+ stream: If true, output is streamed for several characters at a time instead of waiting
106
+ for the full response. The stream terminates with `data: [DONE]`. If false,
107
+ return the encoded audio as octet stream
108
+
109
+ extra_headers: Send extra headers
110
+
111
+ extra_query: Add additional query parameters to the request
112
+
113
+ extra_body: Add additional JSON properties to the request
114
+
115
+ timeout: Override the client-level default timeout for this request, in seconds
116
+ """
117
+ ...
118
+
119
+ @overload
120
+ def create(
121
+ self,
122
+ *,
123
+ input: str,
124
+ model: Union[Literal["cartesia/sonic", "hexgrad/Kokoro-82M", "canopylabs/orpheus-3b-0.1-ft"], str],
125
+ stream: Literal[True],
126
+ voice: str,
127
+ language: Literal["en", "de", "fr", "es", "hi", "it", "ja", "ko", "nl", "pl", "pt", "ru", "sv", "tr", "zh"]
128
+ | Omit = omit,
129
+ response_encoding: Literal["pcm_f32le", "pcm_s16le", "pcm_mulaw", "pcm_alaw"] | Omit = omit,
130
+ response_format: Literal["mp3", "wav", "raw"] | Omit = omit,
131
+ sample_rate: int | Omit = omit,
132
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
133
+ # The extra values given here take precedence over values defined on the client or passed to this method.
134
+ extra_headers: Headers | None = None,
135
+ extra_query: Query | None = None,
136
+ extra_body: Body | None = None,
137
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
138
+ ) -> Stream[AudioSpeechStreamChunk]:
139
+ """
140
+ Generate audio from input text
141
+
142
+ Args:
143
+ input: Input text to generate the audio for
144
+
145
+ model: The name of the model to query.
146
+
147
+ [See all of Together AI's chat models](https://docs.together.ai/docs/serverless-models#audio-models)
148
+ The current supported tts models are: - cartesia/sonic - hexgrad/Kokoro-82M -
149
+ canopylabs/orpheus-3b-0.1-ft
150
+
151
+ stream: If true, output is streamed for several characters at a time instead of waiting
152
+ for the full response. The stream terminates with `data: [DONE]`. If false,
153
+ return the encoded audio as octet stream
154
+
155
+ voice: The voice to use for generating the audio. The voices supported are different
156
+ for each model. For eg - for canopylabs/orpheus-3b-0.1-ft, one of the voices
157
+ supported is tara, for hexgrad/Kokoro-82M, one of the voices supported is
158
+ af_alloy and for cartesia/sonic, one of the voices supported is "friendly
159
+ sidekick".
160
+
161
+ You can view the voices supported for each model using the /v1/voices endpoint
162
+ sending the model name as the query parameter.
163
+ [View all supported voices here](https://docs.together.ai/docs/text-to-speech#voices-available).
164
+
165
+ language: Language of input text.
63
166
 
64
- parameter_payload = AudioSpeechRequest(
65
- model=model,
66
- input=input,
67
- voice=voice,
68
- response_format=AudioResponseFormat(response_format),
69
- language=AudioLanguage(language),
70
- response_encoding=AudioResponseEncoding(response_encoding),
71
- sample_rate=sample_rate,
72
- stream=stream,
73
- **kwargs,
74
- ).model_dump(exclude_none=True)
75
-
76
- response, streamed, _ = requestor.request(
77
- options=TogetherRequest(
78
- method="POST",
79
- url="audio/speech",
80
- params=parameter_payload,
167
+ response_encoding: Audio encoding of response
168
+
169
+ response_format: The format of audio output. Supported formats are mp3, wav, raw if streaming is
170
+ false. If streaming is true, the only supported format is raw.
171
+
172
+ sample_rate: Sampling rate to use for the output audio. The default sampling rate for
173
+ canopylabs/orpheus-3b-0.1-ft and hexgrad/Kokoro-82M is 24000 and for
174
+ cartesia/sonic is 44100.
175
+
176
+ extra_headers: Send extra headers
177
+
178
+ extra_query: Add additional query parameters to the request
179
+
180
+ extra_body: Add additional JSON properties to the request
181
+
182
+ timeout: Override the client-level default timeout for this request, in seconds
183
+ """
184
+ ...
185
+
186
+ @overload
187
+ def create(
188
+ self,
189
+ *,
190
+ input: str,
191
+ model: Union[Literal["cartesia/sonic", "hexgrad/Kokoro-82M", "canopylabs/orpheus-3b-0.1-ft"], str],
192
+ stream: bool,
193
+ voice: str,
194
+ language: Literal["en", "de", "fr", "es", "hi", "it", "ja", "ko", "nl", "pl", "pt", "ru", "sv", "tr", "zh"]
195
+ | Omit = omit,
196
+ response_encoding: Literal["pcm_f32le", "pcm_s16le", "pcm_mulaw", "pcm_alaw"] | Omit = omit,
197
+ response_format: Literal["mp3", "wav", "raw"] | Omit = omit,
198
+ sample_rate: int | Omit = omit,
199
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
200
+ # The extra values given here take precedence over values defined on the client or passed to this method.
201
+ extra_headers: Headers | None = None,
202
+ extra_query: Query | None = None,
203
+ extra_body: Body | None = None,
204
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
205
+ ) -> BinaryAPIResponse | Stream[AudioSpeechStreamChunk]:
206
+ """
207
+ Generate audio from input text
208
+
209
+ Args:
210
+ input: Input text to generate the audio for
211
+
212
+ model: The name of the model to query.
213
+
214
+ [See all of Together AI's chat models](https://docs.together.ai/docs/serverless-models#audio-models)
215
+ The current supported tts models are: - cartesia/sonic - hexgrad/Kokoro-82M -
216
+ canopylabs/orpheus-3b-0.1-ft
217
+
218
+ stream: If true, output is streamed for several characters at a time instead of waiting
219
+ for the full response. The stream terminates with `data: [DONE]`. If false,
220
+ return the encoded audio as octet stream
221
+
222
+ voice: The voice to use for generating the audio. The voices supported are different
223
+ for each model. For eg - for canopylabs/orpheus-3b-0.1-ft, one of the voices
224
+ supported is tara, for hexgrad/Kokoro-82M, one of the voices supported is
225
+ af_alloy and for cartesia/sonic, one of the voices supported is "friendly
226
+ sidekick".
227
+
228
+ You can view the voices supported for each model using the /v1/voices endpoint
229
+ sending the model name as the query parameter.
230
+ [View all supported voices here](https://docs.together.ai/docs/text-to-speech#voices-available).
231
+
232
+ language: Language of input text.
233
+
234
+ response_encoding: Audio encoding of response
235
+
236
+ response_format: The format of audio output. Supported formats are mp3, wav, raw if streaming is
237
+ false. If streaming is true, the only supported format is raw.
238
+
239
+ sample_rate: Sampling rate to use for the output audio. The default sampling rate for
240
+ canopylabs/orpheus-3b-0.1-ft and hexgrad/Kokoro-82M is 24000 and for
241
+ cartesia/sonic is 44100.
242
+
243
+ extra_headers: Send extra headers
244
+
245
+ extra_query: Add additional query parameters to the request
246
+
247
+ extra_body: Add additional JSON properties to the request
248
+
249
+ timeout: Override the client-level default timeout for this request, in seconds
250
+ """
251
+ ...
252
+
253
+ @required_args(["input", "model", "voice"], ["input", "model", "stream", "voice"])
254
+ def create(
255
+ self,
256
+ *,
257
+ input: str,
258
+ model: Union[Literal["cartesia/sonic", "hexgrad/Kokoro-82M", "canopylabs/orpheus-3b-0.1-ft"], str],
259
+ voice: str,
260
+ language: Literal["en", "de", "fr", "es", "hi", "it", "ja", "ko", "nl", "pl", "pt", "ru", "sv", "tr", "zh"]
261
+ | Omit = omit,
262
+ response_encoding: Literal["pcm_f32le", "pcm_s16le", "pcm_mulaw", "pcm_alaw"] | Omit = omit,
263
+ response_format: Literal["mp3", "wav", "raw"] | Omit = omit,
264
+ sample_rate: int | Omit = omit,
265
+ stream: Literal[False] | Literal[True] | Omit = omit,
266
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
267
+ # The extra values given here take precedence over values defined on the client or passed to this method.
268
+ extra_headers: Headers | None = None,
269
+ extra_query: Query | None = None,
270
+ extra_body: Body | None = None,
271
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
272
+ ) -> BinaryAPIResponse | Stream[AudioSpeechStreamChunk]:
273
+ extra_headers = {"Accept": "application/octet-stream", **(extra_headers or {})}
274
+ return self._post(
275
+ "/audio/speech",
276
+ body=maybe_transform(
277
+ {
278
+ "input": input,
279
+ "model": model,
280
+ "voice": voice,
281
+ "language": language,
282
+ "response_encoding": response_encoding,
283
+ "response_format": response_format,
284
+ "sample_rate": sample_rate,
285
+ "stream": stream,
286
+ },
287
+ speech_create_params.SpeechCreateParamsStreaming
288
+ if stream
289
+ else speech_create_params.SpeechCreateParamsNonStreaming,
290
+ ),
291
+ options=make_request_options(
292
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
81
293
  ),
82
- stream=stream,
294
+ cast_to=BinaryAPIResponse,
295
+ stream=stream or False,
296
+ stream_cls=Stream[AudioSpeechStreamChunk],
83
297
  )
84
298
 
85
- return AudioSpeechStreamResponse(response=response)
86
299
 
300
+ class AsyncSpeechResource(AsyncAPIResource):
301
+ @cached_property
302
+ def with_raw_response(self) -> AsyncSpeechResourceWithRawResponse:
303
+ """
304
+ This property can be used as a prefix for any HTTP method call to return
305
+ the raw response object instead of the parsed content.
306
+
307
+ For more information, see https://www.github.com/togethercomputer/together-py#accessing-raw-response-data-eg-headers
308
+ """
309
+ return AsyncSpeechResourceWithRawResponse(self)
310
+
311
+ @cached_property
312
+ def with_streaming_response(self) -> AsyncSpeechResourceWithStreamingResponse:
313
+ """
314
+ An alternative to `.with_raw_response` that doesn't eagerly read the response body.
315
+
316
+ For more information, see https://www.github.com/togethercomputer/together-py#with_streaming_response
317
+ """
318
+ return AsyncSpeechResourceWithStreamingResponse(self)
319
+
320
+ @overload
321
+ async def create(
322
+ self,
323
+ *,
324
+ input: str,
325
+ model: Union[Literal["cartesia/sonic", "hexgrad/Kokoro-82M", "canopylabs/orpheus-3b-0.1-ft"], str],
326
+ voice: str,
327
+ language: Literal["en", "de", "fr", "es", "hi", "it", "ja", "ko", "nl", "pl", "pt", "ru", "sv", "tr", "zh"]
328
+ | Omit = omit,
329
+ response_encoding: Literal["pcm_f32le", "pcm_s16le", "pcm_mulaw", "pcm_alaw"] | Omit = omit,
330
+ response_format: Literal["mp3", "wav", "raw"] | Omit = omit,
331
+ sample_rate: int | Omit = omit,
332
+ stream: Literal[False] | Omit = omit,
333
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
334
+ # The extra values given here take precedence over values defined on the client or passed to this method.
335
+ extra_headers: Headers | None = None,
336
+ extra_query: Query | None = None,
337
+ extra_body: Body | None = None,
338
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
339
+ ) -> AsyncBinaryAPIResponse:
340
+ """
341
+ Generate audio from input text
342
+
343
+ Args:
344
+ input: Input text to generate the audio for
345
+
346
+ model: The name of the model to query.
347
+
348
+ [See all of Together AI's chat models](https://docs.together.ai/docs/serverless-models#audio-models)
349
+ The current supported tts models are: - cartesia/sonic - hexgrad/Kokoro-82M -
350
+ canopylabs/orpheus-3b-0.1-ft
351
+
352
+ voice: The voice to use for generating the audio. The voices supported are different
353
+ for each model. For eg - for canopylabs/orpheus-3b-0.1-ft, one of the voices
354
+ supported is tara, for hexgrad/Kokoro-82M, one of the voices supported is
355
+ af_alloy and for cartesia/sonic, one of the voices supported is "friendly
356
+ sidekick".
357
+
358
+ You can view the voices supported for each model using the /v1/voices endpoint
359
+ sending the model name as the query parameter.
360
+ [View all supported voices here](https://docs.together.ai/docs/text-to-speech#voices-available).
361
+
362
+ language: Language of input text.
363
+
364
+ response_encoding: Audio encoding of response
365
+
366
+ response_format: The format of audio output. Supported formats are mp3, wav, raw if streaming is
367
+ false. If streaming is true, the only supported format is raw.
368
+
369
+ sample_rate: Sampling rate to use for the output audio. The default sampling rate for
370
+ canopylabs/orpheus-3b-0.1-ft and hexgrad/Kokoro-82M is 24000 and for
371
+ cartesia/sonic is 44100.
372
+
373
+ stream: If true, output is streamed for several characters at a time instead of waiting
374
+ for the full response. The stream terminates with `data: [DONE]`. If false,
375
+ return the encoded audio as octet stream
376
+
377
+ extra_headers: Send extra headers
87
378
 
88
- class AsyncSpeech:
89
- def __init__(self, client: TogetherClient) -> None:
90
- self._client = client
379
+ extra_query: Add additional query parameters to the request
91
380
 
381
+ extra_body: Add additional JSON properties to the request
382
+
383
+ timeout: Override the client-level default timeout for this request, in seconds
384
+ """
385
+ ...
386
+
387
+ @overload
92
388
  async def create(
93
389
  self,
94
390
  *,
95
- model: str,
96
391
  input: str,
97
- voice: str | None = None,
98
- response_format: str = "wav",
99
- language: str = "en",
100
- response_encoding: str = "pcm_f32le",
101
- sample_rate: int = 44100,
102
- stream: bool = False,
103
- **kwargs: Any,
104
- ) -> AudioSpeechStreamResponse:
392
+ model: Union[Literal["cartesia/sonic", "hexgrad/Kokoro-82M", "canopylabs/orpheus-3b-0.1-ft"], str],
393
+ stream: Literal[True],
394
+ voice: str,
395
+ language: Literal["en", "de", "fr", "es", "hi", "it", "ja", "ko", "nl", "pl", "pt", "ru", "sv", "tr", "zh"]
396
+ | Omit = omit,
397
+ response_encoding: Literal["pcm_f32le", "pcm_s16le", "pcm_mulaw", "pcm_alaw"] | Omit = omit,
398
+ response_format: Literal["mp3", "wav", "raw"] | Omit = omit,
399
+ sample_rate: int | Omit = omit,
400
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
401
+ # The extra values given here take precedence over values defined on the client or passed to this method.
402
+ extra_headers: Headers | None = None,
403
+ extra_query: Query | None = None,
404
+ extra_body: Body | None = None,
405
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
406
+ ) -> AsyncStream[AudioSpeechStreamChunk]:
105
407
  """
106
- Async method to generate audio from input text using a specified model.
408
+ Generate audio from input text
107
409
 
108
410
  Args:
109
- model (str): The name of the model to query.
110
- input (str): Input text to generate the audio for.
111
- voice (str, optional): The voice to use for generating the audio.
112
- Defaults to None.
113
- response_format (str, optional): The format of audio output.
114
- Defaults to "wav".
115
- language (str, optional): Language of input text.
116
- Defaults to "en".
117
- response_encoding (str, optional): Audio encoding of response.
118
- Defaults to "pcm_f32le".
119
- sample_rate (int, optional): Sampling rate to use for the output audio.
120
- Defaults to 44100.
121
- stream (bool, optional): If true, output is streamed for several characters at a time.
122
- Defaults to False.
123
-
124
- Returns:
125
- Union[bytes, AsyncGenerator[AudioSpeechStreamChunk, None]]: The generated audio as bytes or an async generator over audio stream chunks.
126
- """
127
-
128
- requestor = api_requestor.APIRequestor(
129
- client=self._client,
130
- )
411
+ input: Input text to generate the audio for
412
+
413
+ model: The name of the model to query.
414
+
415
+ [See all of Together AI's chat models](https://docs.together.ai/docs/serverless-models#audio-models)
416
+ The current supported tts models are: - cartesia/sonic - hexgrad/Kokoro-82M -
417
+ canopylabs/orpheus-3b-0.1-ft
418
+
419
+ stream: If true, output is streamed for several characters at a time instead of waiting
420
+ for the full response. The stream terminates with `data: [DONE]`. If false,
421
+ return the encoded audio as octet stream
422
+
423
+ voice: The voice to use for generating the audio. The voices supported are different
424
+ for each model. For eg - for canopylabs/orpheus-3b-0.1-ft, one of the voices
425
+ supported is tara, for hexgrad/Kokoro-82M, one of the voices supported is
426
+ af_alloy and for cartesia/sonic, one of the voices supported is "friendly
427
+ sidekick".
428
+
429
+ You can view the voices supported for each model using the /v1/voices endpoint
430
+ sending the model name as the query parameter.
431
+ [View all supported voices here](https://docs.together.ai/docs/text-to-speech#voices-available).
432
+
433
+ language: Language of input text.
434
+
435
+ response_encoding: Audio encoding of response
436
+
437
+ response_format: The format of audio output. Supported formats are mp3, wav, raw if streaming is
438
+ false. If streaming is true, the only supported format is raw.
439
+
440
+ sample_rate: Sampling rate to use for the output audio. The default sampling rate for
441
+ canopylabs/orpheus-3b-0.1-ft and hexgrad/Kokoro-82M is 24000 and for
442
+ cartesia/sonic is 44100.
443
+
444
+ extra_headers: Send extra headers
445
+
446
+ extra_query: Add additional query parameters to the request
447
+
448
+ extra_body: Add additional JSON properties to the request
449
+
450
+ timeout: Override the client-level default timeout for this request, in seconds
451
+ """
452
+ ...
453
+
454
+ @overload
455
+ async def create(
456
+ self,
457
+ *,
458
+ input: str,
459
+ model: Union[Literal["cartesia/sonic", "hexgrad/Kokoro-82M", "canopylabs/orpheus-3b-0.1-ft"], str],
460
+ stream: bool,
461
+ voice: str,
462
+ language: Literal["en", "de", "fr", "es", "hi", "it", "ja", "ko", "nl", "pl", "pt", "ru", "sv", "tr", "zh"]
463
+ | Omit = omit,
464
+ response_encoding: Literal["pcm_f32le", "pcm_s16le", "pcm_mulaw", "pcm_alaw"] | Omit = omit,
465
+ response_format: Literal["mp3", "wav", "raw"] | Omit = omit,
466
+ sample_rate: int | Omit = omit,
467
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
468
+ # The extra values given here take precedence over values defined on the client or passed to this method.
469
+ extra_headers: Headers | None = None,
470
+ extra_query: Query | None = None,
471
+ extra_body: Body | None = None,
472
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
473
+ ) -> AsyncBinaryAPIResponse | AsyncStream[AudioSpeechStreamChunk]:
474
+ """
475
+ Generate audio from input text
476
+
477
+ Args:
478
+ input: Input text to generate the audio for
479
+
480
+ model: The name of the model to query.
481
+
482
+ [See all of Together AI's chat models](https://docs.together.ai/docs/serverless-models#audio-models)
483
+ The current supported tts models are: - cartesia/sonic - hexgrad/Kokoro-82M -
484
+ canopylabs/orpheus-3b-0.1-ft
485
+
486
+ stream: If true, output is streamed for several characters at a time instead of waiting
487
+ for the full response. The stream terminates with `data: [DONE]`. If false,
488
+ return the encoded audio as octet stream
489
+
490
+ voice: The voice to use for generating the audio. The voices supported are different
491
+ for each model. For eg - for canopylabs/orpheus-3b-0.1-ft, one of the voices
492
+ supported is tara, for hexgrad/Kokoro-82M, one of the voices supported is
493
+ af_alloy and for cartesia/sonic, one of the voices supported is "friendly
494
+ sidekick".
495
+
496
+ You can view the voices supported for each model using the /v1/voices endpoint
497
+ sending the model name as the query parameter.
498
+ [View all supported voices here](https://docs.together.ai/docs/text-to-speech#voices-available).
499
+
500
+ language: Language of input text.
501
+
502
+ response_encoding: Audio encoding of response
503
+
504
+ response_format: The format of audio output. Supported formats are mp3, wav, raw if streaming is
505
+ false. If streaming is true, the only supported format is raw.
506
+
507
+ sample_rate: Sampling rate to use for the output audio. The default sampling rate for
508
+ canopylabs/orpheus-3b-0.1-ft and hexgrad/Kokoro-82M is 24000 and for
509
+ cartesia/sonic is 44100.
510
+
511
+ extra_headers: Send extra headers
512
+
513
+ extra_query: Add additional query parameters to the request
514
+
515
+ extra_body: Add additional JSON properties to the request
516
+
517
+ timeout: Override the client-level default timeout for this request, in seconds
518
+ """
519
+ ...
131
520
 
132
- parameter_payload = AudioSpeechRequest(
133
- model=model,
134
- input=input,
135
- voice=voice,
136
- response_format=AudioResponseFormat(response_format),
137
- language=AudioLanguage(language),
138
- response_encoding=AudioResponseEncoding(response_encoding),
139
- sample_rate=sample_rate,
140
- stream=stream,
141
- **kwargs,
142
- ).model_dump(exclude_none=True)
143
-
144
- response, _, _ = await requestor.arequest(
145
- options=TogetherRequest(
146
- method="POST",
147
- url="audio/speech",
148
- params=parameter_payload,
521
+ @required_args(["input", "model", "voice"], ["input", "model", "stream", "voice"])
522
+ async def create(
523
+ self,
524
+ *,
525
+ input: str,
526
+ model: Union[Literal["cartesia/sonic", "hexgrad/Kokoro-82M", "canopylabs/orpheus-3b-0.1-ft"], str],
527
+ voice: str,
528
+ language: Literal["en", "de", "fr", "es", "hi", "it", "ja", "ko", "nl", "pl", "pt", "ru", "sv", "tr", "zh"]
529
+ | Omit = omit,
530
+ response_encoding: Literal["pcm_f32le", "pcm_s16le", "pcm_mulaw", "pcm_alaw"] | Omit = omit,
531
+ response_format: Literal["mp3", "wav", "raw"] | Omit = omit,
532
+ sample_rate: int | Omit = omit,
533
+ stream: Literal[False] | Literal[True] | Omit = omit,
534
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
535
+ # The extra values given here take precedence over values defined on the client or passed to this method.
536
+ extra_headers: Headers | None = None,
537
+ extra_query: Query | None = None,
538
+ extra_body: Body | None = None,
539
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
540
+ ) -> AsyncBinaryAPIResponse | AsyncStream[AudioSpeechStreamChunk]:
541
+ extra_headers = {"Accept": "application/octet-stream", **(extra_headers or {})}
542
+ return await self._post(
543
+ "/audio/speech",
544
+ body=await async_maybe_transform(
545
+ {
546
+ "input": input,
547
+ "model": model,
548
+ "voice": voice,
549
+ "language": language,
550
+ "response_encoding": response_encoding,
551
+ "response_format": response_format,
552
+ "sample_rate": sample_rate,
553
+ "stream": stream,
554
+ },
555
+ speech_create_params.SpeechCreateParamsStreaming
556
+ if stream
557
+ else speech_create_params.SpeechCreateParamsNonStreaming,
558
+ ),
559
+ options=make_request_options(
560
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
149
561
  ),
150
- stream=stream,
562
+ cast_to=AsyncBinaryAPIResponse,
563
+ stream=stream or False,
564
+ stream_cls=AsyncStream[AudioSpeechStreamChunk],
565
+ )
566
+
567
+
568
+ class SpeechResourceWithRawResponse:
569
+ def __init__(self, speech: SpeechResource) -> None:
570
+ self._speech = speech
571
+
572
+ self.create = to_custom_raw_response_wrapper(
573
+ speech.create,
574
+ BinaryAPIResponse,
575
+ )
576
+
577
+
578
+ class AsyncSpeechResourceWithRawResponse:
579
+ def __init__(self, speech: AsyncSpeechResource) -> None:
580
+ self._speech = speech
581
+
582
+ self.create = async_to_custom_raw_response_wrapper(
583
+ speech.create,
584
+ AsyncBinaryAPIResponse,
585
+ )
586
+
587
+
588
+ class SpeechResourceWithStreamingResponse:
589
+ def __init__(self, speech: SpeechResource) -> None:
590
+ self._speech = speech
591
+
592
+ self.create = to_custom_streamed_response_wrapper(
593
+ speech.create,
594
+ StreamedBinaryAPIResponse,
151
595
  )
152
596
 
153
- return AudioSpeechStreamResponse(response=response)
597
+
598
+ class AsyncSpeechResourceWithStreamingResponse:
599
+ def __init__(self, speech: AsyncSpeechResource) -> None:
600
+ self._speech = speech
601
+
602
+ self.create = async_to_custom_streamed_response_wrapper(
603
+ speech.create,
604
+ AsyncStreamedBinaryAPIResponse,
605
+ )