together 1.5.34__py3-none-any.whl → 2.0.0a6__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 (208) hide show
  1. together/__init__.py +101 -114
  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 +65 -81
  30. together/{cli/api/evaluation.py → lib/cli/api/evals.py} +152 -43
  31. together/{cli → lib/cli}/api/files.py +20 -17
  32. together/{cli/api/finetune.py → lib/cli/api/fine_tuning.py} +116 -172
  33. together/{cli → lib/cli}/api/models.py +34 -27
  34. together/lib/cli/api/utils.py +50 -0
  35. together/{cli → lib/cli}/cli.py +16 -26
  36. together/{constants.py → lib/constants.py} +11 -24
  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 +397 -0
  44. together/{utils → lib/utils}/__init__.py +6 -14
  45. together/{utils → lib/utils}/_log.py +11 -16
  46. together/{utils → lib/utils}/files.py +90 -288
  47. together/lib/utils/serializer.py +10 -0
  48. together/{utils → lib/utils}/tools.py +19 -55
  49. together/resources/__init__.py +225 -39
  50. together/resources/audio/__init__.py +72 -48
  51. together/resources/audio/audio.py +198 -0
  52. together/resources/audio/speech.py +574 -128
  53. together/resources/audio/transcriptions.py +247 -261
  54. together/resources/audio/translations.py +221 -241
  55. together/resources/audio/voices.py +111 -41
  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 +589 -477
  66. together/resources/evals.py +452 -0
  67. together/resources/files.py +397 -129
  68. together/resources/fine_tuning.py +1033 -0
  69. together/resources/hardware.py +181 -0
  70. together/resources/images.py +258 -104
  71. together/resources/jobs.py +214 -0
  72. together/resources/models.py +223 -193
  73. together/resources/rerank.py +190 -92
  74. together/resources/videos.py +286 -214
  75. together/types/__init__.py +66 -167
  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_create_response.py +10 -0
  157. together/types/video_job.py +57 -0
  158. together-2.0.0a6.dist-info/METADATA +729 -0
  159. together-2.0.0a6.dist-info/RECORD +165 -0
  160. {together-1.5.34.dist-info → together-2.0.0a6.dist-info}/WHEEL +1 -1
  161. together-2.0.0a6.dist-info/entry_points.txt +2 -0
  162. {together-1.5.34.dist-info → together-2.0.0a6.dist-info}/licenses/LICENSE +1 -1
  163. together/abstract/api_requestor.py +0 -770
  164. together/cli/api/chat.py +0 -298
  165. together/cli/api/completions.py +0 -119
  166. together/cli/api/images.py +0 -93
  167. together/cli/api/utils.py +0 -139
  168. together/client.py +0 -186
  169. together/error.py +0 -194
  170. together/filemanager.py +0 -635
  171. together/legacy/__init__.py +0 -0
  172. together/legacy/base.py +0 -27
  173. together/legacy/complete.py +0 -93
  174. together/legacy/embeddings.py +0 -27
  175. together/legacy/files.py +0 -146
  176. together/legacy/finetune.py +0 -177
  177. together/legacy/images.py +0 -27
  178. together/legacy/models.py +0 -44
  179. together/resources/batch.py +0 -165
  180. together/resources/code_interpreter.py +0 -82
  181. together/resources/evaluation.py +0 -808
  182. together/resources/finetune.py +0 -1388
  183. together/together_response.py +0 -50
  184. together/types/abstract.py +0 -26
  185. together/types/audio_speech.py +0 -311
  186. together/types/batch.py +0 -54
  187. together/types/chat_completions.py +0 -210
  188. together/types/code_interpreter.py +0 -57
  189. together/types/common.py +0 -67
  190. together/types/completions.py +0 -107
  191. together/types/embeddings.py +0 -35
  192. together/types/endpoints.py +0 -123
  193. together/types/error.py +0 -16
  194. together/types/evaluation.py +0 -93
  195. together/types/files.py +0 -93
  196. together/types/finetune.py +0 -464
  197. together/types/images.py +0 -42
  198. together/types/models.py +0 -96
  199. together/types/rerank.py +0 -43
  200. together/types/videos.py +0 -69
  201. together/utils/api_helpers.py +0 -124
  202. together/version.py +0 -6
  203. together-1.5.34.dist-info/METADATA +0 -583
  204. together-1.5.34.dist-info/RECORD +0 -77
  205. together-1.5.34.dist-info/entry_points.txt +0 -3
  206. /together/{abstract → lib/cli}/__init__.py +0 -0
  207. /together/{cli → lib/cli/api}/__init__.py +0 -0
  208. /together/{cli/api/__init__.py → py.typed} +0 -0
@@ -0,0 +1,729 @@
1
+ Metadata-Version: 2.3
2
+ Name: together
3
+ Version: 2.0.0a6
4
+ Summary: The official Python library for the together API
5
+ Project-URL: Homepage, https://github.com/togethercomputer/together-py
6
+ Project-URL: Repository, https://github.com/togethercomputer/together-py
7
+ Author-email: Together <dev-feedback@TogetherAI.com>
8
+ License: Apache-2.0
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Operating System :: MacOS
12
+ Classifier: Operating System :: Microsoft :: Windows
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Operating System :: POSIX
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.9
25
+ Requires-Dist: anyio<5,>=3.5.0
26
+ Requires-Dist: click>=8.1.7
27
+ Requires-Dist: distro<2,>=1.7.0
28
+ Requires-Dist: filelock>=3.13.1
29
+ Requires-Dist: httpx<1,>=0.23.0
30
+ Requires-Dist: pillow>=10.4.0
31
+ Requires-Dist: pydantic<3,>=1.9.0
32
+ Requires-Dist: sniffio
33
+ Requires-Dist: tabulate>=0.9.0
34
+ Requires-Dist: tqdm>=4.67.1
35
+ Requires-Dist: types-tabulate>=0.9.0.20240106
36
+ Requires-Dist: types-tqdm>=4.67.0.20250516
37
+ Requires-Dist: typing-extensions<5,>=4.10
38
+ Provides-Extra: aiohttp
39
+ Requires-Dist: aiohttp; extra == 'aiohttp'
40
+ Requires-Dist: httpx-aiohttp>=0.1.9; extra == 'aiohttp'
41
+ Provides-Extra: pyarrow
42
+ Requires-Dist: pyarrow-stubs>=10.0.1.7; extra == 'pyarrow'
43
+ Requires-Dist: pyarrow>=16.1.0; extra == 'pyarrow'
44
+ Description-Content-Type: text/markdown
45
+
46
+ # Together Python API library
47
+
48
+ <!-- prettier-ignore -->
49
+ [![PyPI version](https://img.shields.io/pypi/v/together.svg?label=pypi%20(stable))](https://pypi.org/project/together/)
50
+
51
+ The Together Python library provides convenient access to the Together REST API from any Python 3.9+
52
+ application. The library includes type definitions for all request params and response fields,
53
+ and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).
54
+
55
+ It is generated with [Stainless](https://www.stainless.com/).
56
+
57
+ ## Documentation
58
+
59
+ The REST API documentation can be found on [docs.together.ai](https://docs.together.ai/). The full API of this library can be found in [api.md](https://github.com/togethercomputer/together-py/tree/main/api.md).
60
+
61
+ ## Installation
62
+
63
+ ```sh
64
+ # install from the production repo
65
+ pip install git+ssh://git@github.com/togethercomputer/together-py.git
66
+ ```
67
+
68
+ > [!NOTE]
69
+ > Once this package is [published to PyPI](https://www.stainless.com/docs/guides/publish), this will become: `pip install --pre together`
70
+
71
+ ## Usage
72
+
73
+ The full API of this library can be found in [api.md](https://github.com/togethercomputer/together-py/tree/main/api.md).
74
+
75
+ ```python
76
+ import os
77
+ from together import Together
78
+
79
+ client = Together(
80
+ api_key=os.environ.get("TOGETHER_API_KEY"), # This is the default and can be omitted
81
+ )
82
+
83
+ chat_completion = client.chat.completions.create(
84
+ messages=[
85
+ {
86
+ "role": "user",
87
+ "content": "Say this is a test!",
88
+ }
89
+ ],
90
+ model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
91
+ )
92
+ print(chat_completion.choices)
93
+ ```
94
+
95
+ While you can provide an `api_key` keyword argument,
96
+ we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
97
+ to add `TOGETHER_API_KEY="My API Key"` to your `.env` file
98
+ so that your API Key is not stored in source control.
99
+
100
+ ## Async usage
101
+
102
+ Simply import `AsyncTogether` instead of `Together` and use `await` with each API call:
103
+
104
+ ```python
105
+ import os
106
+ import asyncio
107
+ from together import AsyncTogether
108
+
109
+ client = AsyncTogether(
110
+ api_key=os.environ.get("TOGETHER_API_KEY"), # This is the default and can be omitted
111
+ )
112
+
113
+
114
+ async def main() -> None:
115
+ chat_completion = await client.chat.completions.create(
116
+ messages=[
117
+ {
118
+ "role": "user",
119
+ "content": "Say this is a test!",
120
+ }
121
+ ],
122
+ model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
123
+ )
124
+ print(chat_completion.choices)
125
+
126
+
127
+ asyncio.run(main())
128
+ ```
129
+
130
+ Functionality between the synchronous and asynchronous clients is otherwise identical.
131
+
132
+ ### With aiohttp
133
+
134
+ By default, the async client uses `httpx` for HTTP requests. However, for improved concurrency performance you may also use `aiohttp` as the HTTP backend.
135
+
136
+ You can enable this by installing `aiohttp`:
137
+
138
+ ```sh
139
+ # install from the production repo
140
+ pip install 'together[aiohttp] @ git+ssh://git@github.com/togethercomputer/together-py.git'
141
+ ```
142
+
143
+ Then you can enable it by instantiating the client with `http_client=DefaultAioHttpClient()`:
144
+
145
+ ```python
146
+ import asyncio
147
+ from together import DefaultAioHttpClient
148
+ from together import AsyncTogether
149
+
150
+
151
+ async def main() -> None:
152
+ async with AsyncTogether(
153
+ api_key="My API Key",
154
+ http_client=DefaultAioHttpClient(),
155
+ ) as client:
156
+ chat_completion = await client.chat.completions.create(
157
+ messages=[
158
+ {
159
+ "role": "user",
160
+ "content": "Say this is a test!",
161
+ }
162
+ ],
163
+ model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
164
+ )
165
+ print(chat_completion.choices)
166
+
167
+
168
+ asyncio.run(main())
169
+ ```
170
+
171
+ ## Streaming responses
172
+
173
+ We provide support for streaming responses using Server Side Events (SSE).
174
+
175
+ ```python
176
+ from together import Together
177
+
178
+ client = Together()
179
+
180
+ stream = client.chat.completions.create(
181
+ messages=[
182
+ {
183
+ "role": "user",
184
+ "content": "Say this is a test",
185
+ }
186
+ ],
187
+ model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
188
+ stream=True,
189
+ )
190
+ for chat_completion in stream:
191
+ print(chat_completion.choices)
192
+ ```
193
+
194
+ The async client uses the exact same interface.
195
+
196
+ ```python
197
+ from together import AsyncTogether
198
+
199
+ client = AsyncTogether()
200
+
201
+ stream = await client.chat.completions.create(
202
+ messages=[
203
+ {
204
+ "role": "user",
205
+ "content": "Say this is a test",
206
+ }
207
+ ],
208
+ model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
209
+ stream=True,
210
+ )
211
+ async for chat_completion in stream:
212
+ print(chat_completion.choices)
213
+ ```
214
+
215
+ ## Using types
216
+
217
+ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also provide helper methods for things like:
218
+
219
+ - Serializing back into JSON, `model.to_json()`
220
+ - Converting to a dictionary, `model.to_dict()`
221
+
222
+ Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
223
+
224
+ ## Nested params
225
+
226
+ Nested parameters are dictionaries, typed using `TypedDict`, for example:
227
+
228
+ ```python
229
+ from together import Together
230
+
231
+ client = Together()
232
+
233
+ chat_completion = client.chat.completions.create(
234
+ messages=[
235
+ {
236
+ "content": "content",
237
+ "role": "system",
238
+ }
239
+ ],
240
+ model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
241
+ response_format={},
242
+ )
243
+ print(chat_completion.response_format)
244
+ ```
245
+
246
+ ## File uploads
247
+
248
+ Request parameters that correspond to file uploads can be passed as `bytes`, or a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance or a tuple of `(filename, contents, media type)`.
249
+
250
+ ```python
251
+ from pathlib import Path
252
+ from together import Together
253
+
254
+ client = Together()
255
+
256
+ client.files.upload(
257
+ file=Path("/path/to/file"),
258
+ purpose="fine-tune",
259
+ )
260
+ ```
261
+
262
+ The async client uses the exact same interface. If you pass a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance, the file contents will be read asynchronously automatically.
263
+
264
+ ## Handling errors
265
+
266
+ When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `together.APIConnectionError` is raised.
267
+
268
+ When the API returns a non-success status code (that is, 4xx or 5xx
269
+ response), a subclass of `together.APIStatusError` is raised, containing `status_code` and `response` properties.
270
+
271
+ All errors inherit from `together.APIError`.
272
+
273
+ ```python
274
+ import together
275
+ from together import Together
276
+
277
+ client = Together()
278
+
279
+ try:
280
+ client.chat.completions.create(
281
+ messages=[
282
+ {
283
+ "role": "user",
284
+ "content": "Say this is a test",
285
+ }
286
+ ],
287
+ model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
288
+ )
289
+ except together.APIConnectionError as e:
290
+ print("The server could not be reached")
291
+ print(e.__cause__) # an underlying Exception, likely raised within httpx.
292
+ except together.RateLimitError as e:
293
+ print("A 429 status code was received; we should back off a bit.")
294
+ except together.APIStatusError as e:
295
+ print("Another non-200-range status code was received")
296
+ print(e.status_code)
297
+ print(e.response)
298
+ ```
299
+
300
+ Error codes are as follows:
301
+
302
+ | Status Code | Error Type |
303
+ | ----------- | -------------------------- |
304
+ | 400 | `BadRequestError` |
305
+ | 401 | `AuthenticationError` |
306
+ | 403 | `PermissionDeniedError` |
307
+ | 404 | `NotFoundError` |
308
+ | 422 | `UnprocessableEntityError` |
309
+ | 429 | `RateLimitError` |
310
+ | >=500 | `InternalServerError` |
311
+ | N/A | `APIConnectionError` |
312
+
313
+ ### Retries
314
+
315
+ Certain errors are automatically retried 2 times by default, with a short exponential backoff.
316
+ Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,
317
+ 429 Rate Limit, and >=500 Internal errors are all retried by default.
318
+
319
+ You can use the `max_retries` option to configure or disable retry settings:
320
+
321
+ ```python
322
+ from together import Together
323
+
324
+ # Configure the default for all requests:
325
+ client = Together(
326
+ # default is 2
327
+ max_retries=0,
328
+ )
329
+
330
+ # Or, configure per-request:
331
+ client.with_options(max_retries=5).chat.completions.create(
332
+ messages=[
333
+ {
334
+ "role": "user",
335
+ "content": "Say this is a test",
336
+ }
337
+ ],
338
+ model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
339
+ )
340
+ ```
341
+
342
+ ### Timeouts
343
+
344
+ By default requests time out after 1 minute. You can configure this with a `timeout` option,
345
+ which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/timeouts/#fine-tuning-the-configuration) object:
346
+
347
+ ```python
348
+ from together import Together
349
+
350
+ # Configure the default for all requests:
351
+ client = Together(
352
+ # 20 seconds (default is 1 minute)
353
+ timeout=20.0,
354
+ )
355
+
356
+ # More granular control:
357
+ client = Together(
358
+ timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
359
+ )
360
+
361
+ # Override per-request:
362
+ client.with_options(timeout=5.0).chat.completions.create(
363
+ messages=[
364
+ {
365
+ "role": "user",
366
+ "content": "Say this is a test",
367
+ }
368
+ ],
369
+ model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
370
+ )
371
+ ```
372
+
373
+ On timeout, an `APITimeoutError` is thrown.
374
+
375
+ Note that requests that time out are [retried twice by default](https://github.com/togethercomputer/together-py/tree/main/#retries).
376
+
377
+ ## Advanced
378
+
379
+ ### Logging
380
+
381
+ We use the standard library [`logging`](https://docs.python.org/3/library/logging.html) module.
382
+
383
+ You can enable logging by setting the environment variable `TOGETHER_LOG` to `info`.
384
+
385
+ ```shell
386
+ $ export TOGETHER_LOG=info
387
+ ```
388
+
389
+ Or to `debug` for more verbose logging.
390
+
391
+ ### How to tell whether `None` means `null` or missing
392
+
393
+ In an API response, a field may be explicitly `null`, or missing entirely; in either case, its value is `None` in this library. You can differentiate the two cases with `.model_fields_set`:
394
+
395
+ ```py
396
+ if response.my_field is None:
397
+ if 'my_field' not in response.model_fields_set:
398
+ print('Got json like {}, without a "my_field" key present at all.')
399
+ else:
400
+ print('Got json like {"my_field": null}.')
401
+ ```
402
+
403
+ ### Accessing raw response data (e.g. headers)
404
+
405
+ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to any HTTP method call, e.g.,
406
+
407
+ ```py
408
+ from together import Together
409
+
410
+ client = Together()
411
+ response = client.chat.completions.with_raw_response.create(
412
+ messages=[{
413
+ "role": "user",
414
+ "content": "Say this is a test",
415
+ }],
416
+ model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
417
+ )
418
+ print(response.headers.get('X-My-Header'))
419
+
420
+ completion = response.parse() # get the object that `chat.completions.create()` would have returned
421
+ print(completion.choices)
422
+ ```
423
+
424
+ These methods return an [`APIResponse`](https://github.com/togethercomputer/together-py/tree/main/src/together/_response.py) object.
425
+
426
+ The async client returns an [`AsyncAPIResponse`](https://github.com/togethercomputer/together-py/tree/main/src/together/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
427
+
428
+ #### `.with_streaming_response`
429
+
430
+ The above interface eagerly reads the full response body when you make the request, which may not always be what you want.
431
+
432
+ To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.
433
+
434
+ ```python
435
+ with client.chat.completions.with_streaming_response.create(
436
+ messages=[
437
+ {
438
+ "role": "user",
439
+ "content": "Say this is a test",
440
+ }
441
+ ],
442
+ model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
443
+ ) as response:
444
+ print(response.headers.get("X-My-Header"))
445
+
446
+ for line in response.iter_lines():
447
+ print(line)
448
+ ```
449
+
450
+ The context manager is required so that the response will reliably be closed.
451
+
452
+ ### Making custom/undocumented requests
453
+
454
+ This library is typed for convenient access to the documented API.
455
+
456
+ If you need to access undocumented endpoints, params, or response properties, the library can still be used.
457
+
458
+ #### Undocumented endpoints
459
+
460
+ To make requests to undocumented endpoints, you can make requests using `client.get`, `client.post`, and other
461
+ http verbs. Options on the client will be respected (such as retries) when making this request.
462
+
463
+ ```py
464
+ import httpx
465
+
466
+ response = client.post(
467
+ "/foo",
468
+ cast_to=httpx.Response,
469
+ body={"my_param": True},
470
+ )
471
+
472
+ print(response.headers.get("x-foo"))
473
+ ```
474
+
475
+ #### Undocumented request params
476
+
477
+ If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` request
478
+ options.
479
+
480
+ #### Undocumented response properties
481
+
482
+ To access undocumented response properties, you can access the extra fields like `response.unknown_prop`. You
483
+ can also get all the extra fields on the Pydantic model as a dict with
484
+ [`response.model_extra`](https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_extra).
485
+
486
+ ### Configuring the HTTP client
487
+
488
+ You can directly override the [httpx client](https://www.python-httpx.org/api/#client) to customize it for your use case, including:
489
+
490
+ - Support for [proxies](https://www.python-httpx.org/advanced/proxies/)
491
+ - Custom [transports](https://www.python-httpx.org/advanced/transports/)
492
+ - Additional [advanced](https://www.python-httpx.org/advanced/clients/) functionality
493
+
494
+ ```python
495
+ import httpx
496
+ from together import Together, DefaultHttpxClient
497
+
498
+ client = Together(
499
+ # Or use the `TOGETHER_BASE_URL` env var
500
+ base_url="http://my.test.server.example.com:8083",
501
+ http_client=DefaultHttpxClient(
502
+ proxy="http://my.test.proxy.example.com",
503
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
504
+ ),
505
+ )
506
+ ```
507
+
508
+ You can also customize the client on a per-request basis by using `with_options()`:
509
+
510
+ ```python
511
+ client.with_options(http_client=DefaultHttpxClient(...))
512
+ ```
513
+
514
+ ### Managing HTTP resources
515
+
516
+ By default the library closes underlying HTTP connections whenever the client is [garbage collected](https://docs.python.org/3/reference/datamodel.html#object.__del__). You can manually close the client using the `.close()` method if desired, or with a context manager that closes when exiting.
517
+
518
+ ```py
519
+ from together import Together
520
+
521
+ with Together() as client:
522
+ # make requests here
523
+ ...
524
+
525
+ # HTTP client is now closed
526
+ ```
527
+
528
+ ## Usage – CLI
529
+
530
+ ### Chat Completions
531
+
532
+ ```bash
533
+ together chat.completions \
534
+ --message "system" "You are a helpful assistant named Together" \
535
+ --message "user" "What is your name?" \
536
+ --model mistralai/Mixtral-8x7B-Instruct-v0.1
537
+ ```
538
+
539
+ The Chat Completions CLI enables streaming tokens to stdout by default. To disable streaming, use `--no-stream`.
540
+
541
+ ### Completions
542
+
543
+ ```bash
544
+ together completions \
545
+ "Large language models are " \
546
+ --model mistralai/Mixtral-8x7B-v0.1 \
547
+ --max-tokens 512 \
548
+ --stop "."
549
+ ```
550
+
551
+ The Completions CLI enables streaming tokens to stdout by default. To disable streaming, use `--no-stream`.
552
+
553
+ ### Image Generations
554
+
555
+ ```bash
556
+ together images generate \
557
+ "space robots" \
558
+ --model stabilityai/stable-diffusion-xl-base-1.0 \
559
+ --n 4
560
+ ```
561
+
562
+ The image is opened in the default image viewer by default. To disable this, use `--no-show`.
563
+
564
+ ### Files
565
+
566
+ ```bash
567
+ # Help
568
+ together files --help
569
+
570
+ # Check file
571
+ together files check example.jsonl
572
+
573
+ # Upload file
574
+ together files upload example.jsonl
575
+
576
+ # List files
577
+ together files list
578
+
579
+ # Retrieve file metadata
580
+ together files retrieve file-6f50f9d1-5b95-416c-9040-0799b2b4b894
581
+
582
+ # Retrieve file content
583
+ together files retrieve-content file-6f50f9d1-5b95-416c-9040-0799b2b4b894
584
+
585
+ # Delete remote file
586
+ together files delete file-6f50f9d1-5b95-416c-9040-0799b2b4b894
587
+ ```
588
+
589
+ ### Fine-tuning
590
+
591
+ ```bash
592
+ # Help
593
+ together fine-tuning --help
594
+
595
+ # Create fine-tune job
596
+ together fine-tuning create \
597
+ --model togethercomputer/llama-2-7b-chat \
598
+ --training-file file-711d8724-b3e3-4ae2-b516-94841958117d
599
+
600
+ # List fine-tune jobs
601
+ together fine-tuning list
602
+
603
+ # Retrieve fine-tune job details
604
+ together fine-tuning retrieve ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
605
+
606
+ # List fine-tune job events
607
+ together fine-tuning list-events ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
608
+
609
+ # Cancel running job
610
+ together fine-tuning cancel ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
611
+
612
+ # Download fine-tuned model weights
613
+ together fine-tuning download ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
614
+ ```
615
+
616
+ ### Models
617
+
618
+ ```bash
619
+ # Help
620
+ together models --help
621
+
622
+ # List models
623
+ together models list
624
+ ```
625
+
626
+
627
+ ## Versioning
628
+
629
+ This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
630
+
631
+ 1. Changes that only affect static types, without breaking runtime behavior.
632
+ 2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_
633
+ 3. Changes that we do not expect to impact the vast majority of users in practice.
634
+
635
+ We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
636
+
637
+ We are keen for your feedback; please open an [issue](https://www.github.com/togethercomputer/together-py/issues) with questions, bugs, or suggestions.
638
+
639
+ ### Determining the installed version
640
+
641
+ If you've upgraded to the latest version but aren't seeing any new features you were expecting then your python environment is likely still using an older version.
642
+
643
+ You can determine the version that is being used at runtime with:
644
+
645
+ ```py
646
+ import together
647
+ print(together.__version__)
648
+ ```
649
+
650
+ ## Requirements
651
+
652
+ Python 3.9 or higher.
653
+
654
+ ## Usage – CLI
655
+
656
+ ### Files
657
+
658
+ ```bash
659
+ # Help
660
+ together files --help
661
+
662
+ # Check file
663
+ together files check example.jsonl
664
+
665
+ # Upload file
666
+ together files upload example.jsonl
667
+
668
+ # List files
669
+ together files list
670
+
671
+ # Retrieve file metadata
672
+ together files retrieve file-6f50f9d1-5b95-416c-9040-0799b2b4b894
673
+
674
+ # Retrieve file content
675
+ together files retrieve-content file-6f50f9d1-5b95-416c-9040-0799b2b4b894
676
+
677
+ # Delete remote file
678
+ together files delete file-6f50f9d1-5b95-416c-9040-0799b2b4b894
679
+ ```
680
+
681
+ ### Fine-tuning
682
+
683
+ ```bash
684
+ # Help
685
+ together fine-tuning --help
686
+
687
+ # Create fine-tune job
688
+ together fine-tuning create \
689
+ --model togethercomputer/llama-2-7b-chat \
690
+ --training-file file-711d8724-b3e3-4ae2-b516-94841958117d
691
+
692
+ # List fine-tune jobs
693
+ together fine-tuning list
694
+
695
+ # Retrieve fine-tune job details
696
+ together fine-tuning retrieve ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
697
+
698
+ # List fine-tune job events
699
+ together fine-tuning list-events ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
700
+
701
+ # List fine-tune checkpoints
702
+ together fine-tuning list-checkpoints ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
703
+
704
+ # Cancel running job
705
+ together fine-tuning cancel ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
706
+
707
+ # Download fine-tuned model weights
708
+ together fine-tuning download ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
709
+
710
+ # Delete fine-tuned model weights
711
+ together fine-tuning delete ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
712
+ ```
713
+
714
+ ### Models
715
+
716
+ ```bash
717
+ # Help
718
+ together models --help
719
+
720
+ # List models
721
+ together models list
722
+
723
+ # Upload a model
724
+ together models upload --model-name my-org/my-model --model-source s3-or-hugging-face
725
+ ```
726
+
727
+ ## Contributing
728
+
729
+ See [the contributing documentation](https://github.com/togethercomputer/together-py/tree/main/./CONTRIBUTING.md).