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