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
@@ -0,0 +1,680 @@
1
+ Metadata-Version: 2.3
2
+ Name: together
3
+ Version: 2.0.0a8
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
+ 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.
248
+
249
+ ## Handling errors
250
+
251
+ 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.
252
+
253
+ When the API returns a non-success status code (that is, 4xx or 5xx
254
+ response), a subclass of `together.APIStatusError` is raised, containing `status_code` and `response` properties.
255
+
256
+ All errors inherit from `together.APIError`.
257
+
258
+ ```python
259
+ import together
260
+ from together import Together
261
+
262
+ client = Together()
263
+
264
+ try:
265
+ client.chat.completions.create(
266
+ messages=[
267
+ {
268
+ "role": "user",
269
+ "content": "Say this is a test",
270
+ }
271
+ ],
272
+ model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
273
+ )
274
+ except together.APIConnectionError as e:
275
+ print("The server could not be reached")
276
+ print(e.__cause__) # an underlying Exception, likely raised within httpx.
277
+ except together.RateLimitError as e:
278
+ print("A 429 status code was received; we should back off a bit.")
279
+ except together.APIStatusError as e:
280
+ print("Another non-200-range status code was received")
281
+ print(e.status_code)
282
+ print(e.response)
283
+ ```
284
+
285
+ Error codes are as follows:
286
+
287
+ | Status Code | Error Type |
288
+ | ----------- | -------------------------- |
289
+ | 400 | `BadRequestError` |
290
+ | 401 | `AuthenticationError` |
291
+ | 403 | `PermissionDeniedError` |
292
+ | 404 | `NotFoundError` |
293
+ | 422 | `UnprocessableEntityError` |
294
+ | 429 | `RateLimitError` |
295
+ | >=500 | `InternalServerError` |
296
+ | N/A | `APIConnectionError` |
297
+
298
+ ### Retries
299
+
300
+ Certain errors are automatically retried 2 times by default, with a short exponential backoff.
301
+ Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,
302
+ 429 Rate Limit, and >=500 Internal errors are all retried by default.
303
+
304
+ You can use the `max_retries` option to configure or disable retry settings:
305
+
306
+ ```python
307
+ from together import Together
308
+
309
+ # Configure the default for all requests:
310
+ client = Together(
311
+ # default is 2
312
+ max_retries=0,
313
+ )
314
+
315
+ # Or, configure per-request:
316
+ client.with_options(max_retries=5).chat.completions.create(
317
+ messages=[
318
+ {
319
+ "role": "user",
320
+ "content": "Say this is a test",
321
+ }
322
+ ],
323
+ model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
324
+ )
325
+ ```
326
+
327
+ ### Timeouts
328
+
329
+ By default requests time out after 1 minute. You can configure this with a `timeout` option,
330
+ which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/timeouts/#fine-tuning-the-configuration) object:
331
+
332
+ ```python
333
+ from together import Together
334
+
335
+ # Configure the default for all requests:
336
+ client = Together(
337
+ # 20 seconds (default is 1 minute)
338
+ timeout=20.0,
339
+ )
340
+
341
+ # More granular control:
342
+ client = Together(
343
+ timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
344
+ )
345
+
346
+ # Override per-request:
347
+ client.with_options(timeout=5.0).chat.completions.create(
348
+ messages=[
349
+ {
350
+ "role": "user",
351
+ "content": "Say this is a test",
352
+ }
353
+ ],
354
+ model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
355
+ )
356
+ ```
357
+
358
+ On timeout, an `APITimeoutError` is thrown.
359
+
360
+ Note that requests that time out are [retried twice by default](https://github.com/togethercomputer/together-py/tree/main/#retries).
361
+
362
+ ## Advanced
363
+
364
+ ### Logging
365
+
366
+ We use the standard library [`logging`](https://docs.python.org/3/library/logging.html) module.
367
+
368
+ You can enable logging by setting the environment variable `TOGETHER_LOG` to `info`.
369
+
370
+ ```shell
371
+ $ export TOGETHER_LOG=info
372
+ ```
373
+
374
+ Or to `debug` for more verbose logging.
375
+
376
+ ### How to tell whether `None` means `null` or missing
377
+
378
+ 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`:
379
+
380
+ ```py
381
+ if response.my_field is None:
382
+ if 'my_field' not in response.model_fields_set:
383
+ print('Got json like {}, without a "my_field" key present at all.')
384
+ else:
385
+ print('Got json like {"my_field": null}.')
386
+ ```
387
+
388
+ ### Accessing raw response data (e.g. headers)
389
+
390
+ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to any HTTP method call, e.g.,
391
+
392
+ ```py
393
+ from together import Together
394
+
395
+ client = Together()
396
+ response = client.chat.completions.with_raw_response.create(
397
+ messages=[{
398
+ "role": "user",
399
+ "content": "Say this is a test",
400
+ }],
401
+ model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
402
+ )
403
+ print(response.headers.get('X-My-Header'))
404
+
405
+ completion = response.parse() # get the object that `chat.completions.create()` would have returned
406
+ print(completion.choices)
407
+ ```
408
+
409
+ These methods return an [`APIResponse`](https://github.com/togethercomputer/together-py/tree/main/src/together/_response.py) object.
410
+
411
+ 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.
412
+
413
+ #### `.with_streaming_response`
414
+
415
+ The above interface eagerly reads the full response body when you make the request, which may not always be what you want.
416
+
417
+ 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.
418
+
419
+ ```python
420
+ with client.chat.completions.with_streaming_response.create(
421
+ messages=[
422
+ {
423
+ "role": "user",
424
+ "content": "Say this is a test",
425
+ }
426
+ ],
427
+ model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
428
+ ) as response:
429
+ print(response.headers.get("X-My-Header"))
430
+
431
+ for line in response.iter_lines():
432
+ print(line)
433
+ ```
434
+
435
+ The context manager is required so that the response will reliably be closed.
436
+
437
+ ### Making custom/undocumented requests
438
+
439
+ This library is typed for convenient access to the documented API.
440
+
441
+ If you need to access undocumented endpoints, params, or response properties, the library can still be used.
442
+
443
+ #### Undocumented endpoints
444
+
445
+ To make requests to undocumented endpoints, you can make requests using `client.get`, `client.post`, and other
446
+ http verbs. Options on the client will be respected (such as retries) when making this request.
447
+
448
+ ```py
449
+ import httpx
450
+
451
+ response = client.post(
452
+ "/foo",
453
+ cast_to=httpx.Response,
454
+ body={"my_param": True},
455
+ )
456
+
457
+ print(response.headers.get("x-foo"))
458
+ ```
459
+
460
+ #### Undocumented request params
461
+
462
+ If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` request
463
+ options.
464
+
465
+ #### Undocumented response properties
466
+
467
+ To access undocumented response properties, you can access the extra fields like `response.unknown_prop`. You
468
+ can also get all the extra fields on the Pydantic model as a dict with
469
+ [`response.model_extra`](https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_extra).
470
+
471
+ ### Configuring the HTTP client
472
+
473
+ You can directly override the [httpx client](https://www.python-httpx.org/api/#client) to customize it for your use case, including:
474
+
475
+ - Support for [proxies](https://www.python-httpx.org/advanced/proxies/)
476
+ - Custom [transports](https://www.python-httpx.org/advanced/transports/)
477
+ - Additional [advanced](https://www.python-httpx.org/advanced/clients/) functionality
478
+
479
+ ```python
480
+ import httpx
481
+ from together import Together, DefaultHttpxClient
482
+
483
+ client = Together(
484
+ # Or use the `TOGETHER_BASE_URL` env var
485
+ base_url="http://my.test.server.example.com:8083",
486
+ http_client=DefaultHttpxClient(
487
+ proxy="http://my.test.proxy.example.com",
488
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
489
+ ),
490
+ )
491
+ ```
492
+
493
+ You can also customize the client on a per-request basis by using `with_options()`:
494
+
495
+ ```python
496
+ client.with_options(http_client=DefaultHttpxClient(...))
497
+ ```
498
+
499
+ ### Managing HTTP resources
500
+
501
+ 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.
502
+
503
+ ```py
504
+ from together import Together
505
+
506
+ with Together() as client:
507
+ # make requests here
508
+ ...
509
+
510
+ # HTTP client is now closed
511
+ ```
512
+
513
+ ## Usage – CLI
514
+
515
+ ### Files
516
+
517
+ ```bash
518
+ # Help
519
+ together files --help
520
+
521
+ # Check file
522
+ together files check example.jsonl
523
+
524
+ # Upload file
525
+ together files upload example.jsonl
526
+
527
+ # List files
528
+ together files list
529
+
530
+ # Retrieve file metadata
531
+ together files retrieve file-6f50f9d1-5b95-416c-9040-0799b2b4b894
532
+
533
+ # Retrieve file content
534
+ together files retrieve-content file-6f50f9d1-5b95-416c-9040-0799b2b4b894
535
+
536
+ # Delete remote file
537
+ together files delete file-6f50f9d1-5b95-416c-9040-0799b2b4b894
538
+ ```
539
+
540
+ ### Fine-tuning
541
+
542
+ ```bash
543
+ # Help
544
+ together fine-tuning --help
545
+
546
+ # Create fine-tune job
547
+ together fine-tuning create \
548
+ --model togethercomputer/llama-2-7b-chat \
549
+ --training-file file-711d8724-b3e3-4ae2-b516-94841958117d
550
+
551
+ # List fine-tune jobs
552
+ together fine-tuning list
553
+
554
+ # Retrieve fine-tune job details
555
+ together fine-tuning retrieve ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
556
+
557
+ # List fine-tune job events
558
+ together fine-tuning list-events ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
559
+
560
+ # Cancel running job
561
+ together fine-tuning cancel ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
562
+
563
+ # Download fine-tuned model weights
564
+ together fine-tuning download ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
565
+ ```
566
+
567
+ ### Models
568
+
569
+ ```bash
570
+ # Help
571
+ together models --help
572
+
573
+ # List models
574
+ together models list
575
+ ```
576
+
577
+
578
+ ## Versioning
579
+
580
+ 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:
581
+
582
+ 1. Changes that only affect static types, without breaking runtime behavior.
583
+ 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.)_
584
+ 3. Changes that we do not expect to impact the vast majority of users in practice.
585
+
586
+ We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
587
+
588
+ We are keen for your feedback; please open an [issue](https://www.github.com/togethercomputer/together-py/issues) with questions, bugs, or suggestions.
589
+
590
+ ### Determining the installed version
591
+
592
+ 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.
593
+
594
+ You can determine the version that is being used at runtime with:
595
+
596
+ ```py
597
+ import together
598
+ print(together.__version__)
599
+ ```
600
+
601
+ ## Requirements
602
+
603
+ Python 3.9 or higher.
604
+
605
+ ## Usage – CLI
606
+
607
+ ### Files
608
+
609
+ ```bash
610
+ # Help
611
+ together files --help
612
+
613
+ # Check file
614
+ together files check example.jsonl
615
+
616
+ # Upload file
617
+ together files upload example.jsonl
618
+
619
+ # List files
620
+ together files list
621
+
622
+ # Retrieve file metadata
623
+ together files retrieve file-6f50f9d1-5b95-416c-9040-0799b2b4b894
624
+
625
+ # Retrieve file content
626
+ together files retrieve-content file-6f50f9d1-5b95-416c-9040-0799b2b4b894
627
+
628
+ # Delete remote file
629
+ together files delete file-6f50f9d1-5b95-416c-9040-0799b2b4b894
630
+ ```
631
+
632
+ ### Fine-tuning
633
+
634
+ ```bash
635
+ # Help
636
+ together fine-tuning --help
637
+
638
+ # Create fine-tune job
639
+ together fine-tuning create \
640
+ --model togethercomputer/llama-2-7b-chat \
641
+ --training-file file-711d8724-b3e3-4ae2-b516-94841958117d
642
+
643
+ # List fine-tune jobs
644
+ together fine-tuning list
645
+
646
+ # Retrieve fine-tune job details
647
+ together fine-tuning retrieve ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
648
+
649
+ # List fine-tune job events
650
+ together fine-tuning list-events ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
651
+
652
+ # List fine-tune checkpoints
653
+ together fine-tuning list-checkpoints ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
654
+
655
+ # Cancel running job
656
+ together fine-tuning cancel ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
657
+
658
+ # Download fine-tuned model weights
659
+ together fine-tuning download ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
660
+
661
+ # Delete fine-tuned model weights
662
+ together fine-tuning delete ft-c66a5c18-1d6d-43c9-94bd-32d756425b4b
663
+ ```
664
+
665
+ ### Models
666
+
667
+ ```bash
668
+ # Help
669
+ together models --help
670
+
671
+ # List models
672
+ together models list
673
+
674
+ # Upload a model
675
+ together models upload --model-name my-org/my-model --model-source s3-or-hugging-face
676
+ ```
677
+
678
+ ## Contributing
679
+
680
+ See [the contributing documentation](https://github.com/togethercomputer/together-py/tree/main/./CONTRIBUTING.md).