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
@@ -1,195 +1,463 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
1
3
  from __future__ import annotations
2
4
 
3
- import os
4
- from pathlib import Path
5
5
  from pprint import pformat
6
+ from typing import cast, get_args
7
+ from pathlib import Path
6
8
 
7
- from together.abstract import api_requestor
8
- from together.constants import MULTIPART_THRESHOLD_GB, NUM_BYTES_IN_GB
9
- from together.error import FileTypeError
10
- from together.filemanager import DownloadManager, UploadManager, MultipartUploadManager
11
- from together.together_response import TogetherResponse
12
- from together.types import (
13
- FileDeleteResponse,
14
- FileList,
15
- FileObject,
16
- FilePurpose,
17
- FileResponse,
18
- TogetherClient,
19
- TogetherRequest,
9
+ import httpx
10
+
11
+ from together.types import FilePurpose
12
+
13
+ from ..lib import FileTypeError, UploadManager, AsyncUploadManager, check_file
14
+ from ..types import FilePurpose
15
+ from .._types import Body, Query, Headers, NotGiven, not_given
16
+ from .._compat import cached_property
17
+ from .._resource import SyncAPIResource, AsyncAPIResource
18
+ from .._response import (
19
+ BinaryAPIResponse,
20
+ AsyncBinaryAPIResponse,
21
+ StreamedBinaryAPIResponse,
22
+ AsyncStreamedBinaryAPIResponse,
23
+ to_raw_response_wrapper,
24
+ to_streamed_response_wrapper,
25
+ async_to_raw_response_wrapper,
26
+ to_custom_raw_response_wrapper,
27
+ async_to_streamed_response_wrapper,
28
+ to_custom_streamed_response_wrapper,
29
+ async_to_custom_raw_response_wrapper,
30
+ async_to_custom_streamed_response_wrapper,
20
31
  )
21
- from together.utils import check_file, normalize_key
32
+ from .._base_client import make_request_options
33
+ from ..types.file_list import FileList
34
+ from ..types.file_response import FileResponse
35
+ from ..types.file_delete_response import FileDeleteResponse
36
+
37
+ __all__ = ["FilesResource", "AsyncFilesResource"]
38
+
39
+
40
+ class FilesResource(SyncAPIResource):
41
+ @cached_property
42
+ def with_raw_response(self) -> FilesResourceWithRawResponse:
43
+ """
44
+ This property can be used as a prefix for any HTTP method call to return
45
+ the raw response object instead of the parsed content.
46
+
47
+ For more information, see https://www.github.com/togethercomputer/together-py#accessing-raw-response-data-eg-headers
48
+ """
49
+ return FilesResourceWithRawResponse(self)
50
+
51
+ @cached_property
52
+ def with_streaming_response(self) -> FilesResourceWithStreamingResponse:
53
+ """
54
+ An alternative to `.with_raw_response` that doesn't eagerly read the response body.
55
+
56
+ For more information, see https://www.github.com/togethercomputer/together-py#with_streaming_response
57
+ """
58
+ return FilesResourceWithStreamingResponse(self)
59
+
60
+ def retrieve(
61
+ self,
62
+ id: str,
63
+ *,
64
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
65
+ # The extra values given here take precedence over values defined on the client or passed to this method.
66
+ extra_headers: Headers | None = None,
67
+ extra_query: Query | None = None,
68
+ extra_body: Body | None = None,
69
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
70
+ ) -> FileResponse:
71
+ """
72
+ List the metadata for a single uploaded data file.
73
+
74
+ Args:
75
+ extra_headers: Send extra headers
76
+
77
+ extra_query: Add additional query parameters to the request
78
+
79
+ extra_body: Add additional JSON properties to the request
80
+
81
+ timeout: Override the client-level default timeout for this request, in seconds
82
+ """
83
+ if not id:
84
+ raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
85
+ return self._get(
86
+ f"/files/{id}",
87
+ options=make_request_options(
88
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
89
+ ),
90
+ cast_to=FileResponse,
91
+ )
22
92
 
93
+ def list(
94
+ self,
95
+ *,
96
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
97
+ # The extra values given here take precedence over values defined on the client or passed to this method.
98
+ extra_headers: Headers | None = None,
99
+ extra_query: Query | None = None,
100
+ extra_body: Body | None = None,
101
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
102
+ ) -> FileList:
103
+ """List the metadata for all uploaded data files."""
104
+ return self._get(
105
+ "/files",
106
+ options=make_request_options(
107
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
108
+ ),
109
+ cast_to=FileList,
110
+ )
23
111
 
24
- class Files:
25
- def __init__(self, client: TogetherClient) -> None:
26
- self._client = client
112
+ def delete(
113
+ self,
114
+ id: str,
115
+ *,
116
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
117
+ # The extra values given here take precedence over values defined on the client or passed to this method.
118
+ extra_headers: Headers | None = None,
119
+ extra_query: Query | None = None,
120
+ extra_body: Body | None = None,
121
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
122
+ ) -> FileDeleteResponse:
123
+ """
124
+ Delete a previously uploaded data file.
125
+
126
+ Args:
127
+ extra_headers: Send extra headers
128
+
129
+ extra_query: Add additional query parameters to the request
130
+
131
+ extra_body: Add additional JSON properties to the request
132
+
133
+ timeout: Override the client-level default timeout for this request, in seconds
134
+ """
135
+ if not id:
136
+ raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
137
+ return self._delete(
138
+ f"/files/{id}",
139
+ options=make_request_options(
140
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
141
+ ),
142
+ cast_to=FileDeleteResponse,
143
+ )
27
144
 
28
145
  def upload(
29
146
  self,
30
147
  file: Path | str,
31
148
  *,
32
- purpose: FilePurpose | str = FilePurpose.FineTune,
149
+ purpose: FilePurpose | str = "fine-tune",
33
150
  check: bool = True,
34
151
  ) -> FileResponse:
35
-
36
- if check and purpose == FilePurpose.FineTune:
152
+ if check:
37
153
  report_dict = check_file(file)
38
154
  if not report_dict["is_check_passed"]:
39
- raise FileTypeError(
40
- f"Invalid file supplied, failed to upload. Report:\n{pformat(report_dict)}"
41
- )
155
+ raise FileTypeError(f"Invalid file supplied, failed to upload. Report:\n{pformat(report_dict)}")
42
156
 
43
157
  if isinstance(file, str):
44
158
  file = Path(file)
45
159
 
46
- if isinstance(purpose, str):
47
- purpose = FilePurpose(purpose)
48
-
49
- assert isinstance(purpose, FilePurpose)
160
+ if purpose not in get_args(FilePurpose):
161
+ raise ValueError(f"Invalid purpose '{purpose}'. Must be one of: {get_args(FilePurpose)}")
50
162
 
51
- file_size = os.stat(file).st_size
52
- file_size_gb = file_size / NUM_BYTES_IN_GB
163
+ purpose = cast(FilePurpose, purpose)
53
164
 
54
- if file_size_gb > MULTIPART_THRESHOLD_GB:
55
- multipart_manager = MultipartUploadManager(self._client)
56
- return multipart_manager.upload("files", file, purpose)
57
- else:
58
- upload_manager = UploadManager(self._client)
59
- return upload_manager.upload("files", file, purpose=purpose, redirect=True)
165
+ upload_manager = UploadManager(self._client)
166
+ result = upload_manager.upload("/files", file, purpose)
60
167
 
61
- def list(self) -> FileList:
62
- requestor = api_requestor.APIRequestor(
63
- client=self._client,
168
+ return FileResponse(
169
+ id=result.id,
170
+ bytes=result.bytes,
171
+ created_at=result.created_at,
172
+ filename=result.filename,
173
+ FileType=result.file_type,
174
+ LineCount=result.line_count,
175
+ object=result.object,
176
+ Processed=result.processed,
177
+ purpose=result.purpose,
64
178
  )
65
179
 
66
- response, _, _ = requestor.request(
67
- options=TogetherRequest(
68
- method="GET",
69
- url="files",
180
+ def content(
181
+ self,
182
+ id: str,
183
+ *,
184
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
185
+ # The extra values given here take precedence over values defined on the client or passed to this method.
186
+ extra_headers: Headers | None = None,
187
+ extra_query: Query | None = None,
188
+ extra_body: Body | None = None,
189
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
190
+ ) -> BinaryAPIResponse:
191
+ """
192
+ Get the contents of a single uploaded data file.
193
+
194
+ Args:
195
+ extra_headers: Send extra headers
196
+
197
+ extra_query: Add additional query parameters to the request
198
+
199
+ extra_body: Add additional JSON properties to the request
200
+
201
+ timeout: Override the client-level default timeout for this request, in seconds
202
+ """
203
+ if not id:
204
+ raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
205
+ extra_headers = {"Accept": "application/binary", **(extra_headers or {})}
206
+ return self._get(
207
+ f"/files/{id}/content",
208
+ options=make_request_options(
209
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
70
210
  ),
71
- stream=False,
211
+ cast_to=BinaryAPIResponse,
72
212
  )
73
213
 
74
- assert isinstance(response, TogetherResponse)
75
214
 
76
- return FileList(**response.data)
215
+ class AsyncFilesResource(AsyncAPIResource):
216
+ @cached_property
217
+ def with_raw_response(self) -> AsyncFilesResourceWithRawResponse:
218
+ """
219
+ This property can be used as a prefix for any HTTP method call to return
220
+ the raw response object instead of the parsed content.
77
221
 
78
- def retrieve(self, id: str) -> FileResponse:
79
- requestor = api_requestor.APIRequestor(
80
- client=self._client,
81
- )
222
+ For more information, see https://www.github.com/togethercomputer/together-py#accessing-raw-response-data-eg-headers
223
+ """
224
+ return AsyncFilesResourceWithRawResponse(self)
82
225
 
83
- response, _, _ = requestor.request(
84
- options=TogetherRequest(
85
- method="GET",
86
- url=f"files/{id}",
87
- ),
88
- stream=False,
89
- )
226
+ @cached_property
227
+ def with_streaming_response(self) -> AsyncFilesResourceWithStreamingResponse:
228
+ """
229
+ An alternative to `.with_raw_response` that doesn't eagerly read the response body.
90
230
 
91
- assert isinstance(response, TogetherResponse)
231
+ For more information, see https://www.github.com/togethercomputer/together-py#with_streaming_response
232
+ """
233
+ return AsyncFilesResourceWithStreamingResponse(self)
92
234
 
93
- return FileResponse(**response.data)
235
+ async def retrieve(
236
+ self,
237
+ id: str,
238
+ *,
239
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
240
+ # The extra values given here take precedence over values defined on the client or passed to this method.
241
+ extra_headers: Headers | None = None,
242
+ extra_query: Query | None = None,
243
+ extra_body: Body | None = None,
244
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
245
+ ) -> FileResponse:
246
+ """
247
+ List the metadata for a single uploaded data file.
94
248
 
95
- def retrieve_content(
96
- self, id: str, *, output: Path | str | None = None
97
- ) -> FileObject:
98
- download_manager = DownloadManager(self._client)
249
+ Args:
250
+ extra_headers: Send extra headers
99
251
 
100
- if isinstance(output, str):
101
- output = Path(output)
252
+ extra_query: Add additional query parameters to the request
102
253
 
103
- downloaded_filename, file_size = download_manager.download(
104
- f"files/{id}/content", output, normalize_key(f"{id}.jsonl")
105
- )
254
+ extra_body: Add additional JSON properties to the request
106
255
 
107
- return FileObject(
108
- object="local",
109
- id=id,
110
- filename=downloaded_filename,
111
- size=file_size,
256
+ timeout: Override the client-level default timeout for this request, in seconds
257
+ """
258
+ if not id:
259
+ raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
260
+ return await self._get(
261
+ f"/files/{id}",
262
+ options=make_request_options(
263
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
264
+ ),
265
+ cast_to=FileResponse,
112
266
  )
113
267
 
114
- def delete(self, id: str) -> FileDeleteResponse:
115
- requestor = api_requestor.APIRequestor(
116
- client=self._client,
268
+ async def list(
269
+ self,
270
+ *,
271
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
272
+ # The extra values given here take precedence over values defined on the client or passed to this method.
273
+ extra_headers: Headers | None = None,
274
+ extra_query: Query | None = None,
275
+ extra_body: Body | None = None,
276
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
277
+ ) -> FileList:
278
+ """List the metadata for all uploaded data files."""
279
+ return await self._get(
280
+ "/files",
281
+ options=make_request_options(
282
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
283
+ ),
284
+ cast_to=FileList,
117
285
  )
118
286
 
119
- response, _, _ = requestor.request(
120
- options=TogetherRequest(
121
- method="DELETE",
122
- url=f"files/{id}",
287
+ async def delete(
288
+ self,
289
+ id: str,
290
+ *,
291
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
292
+ # The extra values given here take precedence over values defined on the client or passed to this method.
293
+ extra_headers: Headers | None = None,
294
+ extra_query: Query | None = None,
295
+ extra_body: Body | None = None,
296
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
297
+ ) -> FileDeleteResponse:
298
+ """
299
+ Delete a previously uploaded data file.
300
+
301
+ Args:
302
+ extra_headers: Send extra headers
303
+
304
+ extra_query: Add additional query parameters to the request
305
+
306
+ extra_body: Add additional JSON properties to the request
307
+
308
+ timeout: Override the client-level default timeout for this request, in seconds
309
+ """
310
+ if not id:
311
+ raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
312
+ return await self._delete(
313
+ f"/files/{id}",
314
+ options=make_request_options(
315
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
123
316
  ),
124
- stream=False,
317
+ cast_to=FileDeleteResponse,
125
318
  )
126
319
 
127
- assert isinstance(response, TogetherResponse)
320
+ async def upload(
321
+ self,
322
+ file: Path | str,
323
+ *,
324
+ purpose: FilePurpose | str = "fine-tune",
325
+ check: bool = True,
326
+ ) -> FileResponse:
327
+ if check:
328
+ report_dict = check_file(file)
329
+ if not report_dict["is_check_passed"]:
330
+ raise FileTypeError(f"Invalid file supplied, failed to upload. Report:\n{pformat(report_dict)}")
128
331
 
129
- return FileDeleteResponse(**response.data)
332
+ if isinstance(file, str):
333
+ file = Path(file)
130
334
 
335
+ if purpose not in get_args(FilePurpose):
336
+ raise ValueError(f"Invalid purpose '{purpose}'. Must be one of: {get_args(FilePurpose)}")
131
337
 
132
- class AsyncFiles:
133
- def __init__(self, client: TogetherClient) -> None:
134
- self._client = client
338
+ purpose = cast(FilePurpose, purpose)
135
339
 
136
- async def upload(
137
- self, file: Path | str, *, purpose: FilePurpose | str = FilePurpose.FineTune
138
- ) -> None:
139
- raise NotImplementedError()
340
+ upload_manager = AsyncUploadManager(self._client)
341
+ result = await upload_manager.upload("/files", file, purpose)
140
342
 
141
- async def list(self) -> FileList:
142
- requestor = api_requestor.APIRequestor(
143
- client=self._client,
343
+ return FileResponse(
344
+ id=result.id,
345
+ bytes=result.bytes,
346
+ created_at=result.created_at,
347
+ filename=result.filename,
348
+ FileType=result.file_type,
349
+ LineCount=result.line_count,
350
+ object=result.object,
351
+ Processed=result.processed,
352
+ purpose=result.purpose,
144
353
  )
145
354
 
146
- response, _, _ = await requestor.arequest(
147
- options=TogetherRequest(
148
- method="GET",
149
- url="files",
355
+ async def content(
356
+ self,
357
+ id: str,
358
+ *,
359
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
360
+ # The extra values given here take precedence over values defined on the client or passed to this method.
361
+ extra_headers: Headers | None = None,
362
+ extra_query: Query | None = None,
363
+ extra_body: Body | None = None,
364
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
365
+ ) -> AsyncBinaryAPIResponse:
366
+ """
367
+ Get the contents of a single uploaded data file.
368
+
369
+ Args:
370
+ extra_headers: Send extra headers
371
+
372
+ extra_query: Add additional query parameters to the request
373
+
374
+ extra_body: Add additional JSON properties to the request
375
+
376
+ timeout: Override the client-level default timeout for this request, in seconds
377
+ """
378
+ if not id:
379
+ raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
380
+ extra_headers = {"Accept": "application/binary", **(extra_headers or {})}
381
+ return await self._get(
382
+ f"/files/{id}/content",
383
+ options=make_request_options(
384
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
150
385
  ),
151
- stream=False,
386
+ cast_to=AsyncBinaryAPIResponse,
152
387
  )
153
388
 
154
- assert isinstance(response, TogetherResponse)
155
389
 
156
- return FileList(**response.data)
390
+ class FilesResourceWithRawResponse:
391
+ def __init__(self, files: FilesResource) -> None:
392
+ self._files = files
157
393
 
158
- async def retrieve(self, id: str) -> FileResponse:
159
- requestor = api_requestor.APIRequestor(
160
- client=self._client,
394
+ self.retrieve = to_raw_response_wrapper(
395
+ files.retrieve,
161
396
  )
162
-
163
- response, _, _ = await requestor.arequest(
164
- options=TogetherRequest(
165
- method="GET",
166
- url=f"files/{id}",
167
- ),
168
- stream=False,
397
+ self.list = to_raw_response_wrapper(
398
+ files.list,
399
+ )
400
+ self.delete = to_raw_response_wrapper(
401
+ files.delete,
402
+ )
403
+ self.content = to_custom_raw_response_wrapper(
404
+ files.content,
405
+ BinaryAPIResponse,
169
406
  )
170
407
 
171
- assert isinstance(response, TogetherResponse)
172
-
173
- return FileResponse(**response.data)
174
408
 
175
- async def retrieve_content(
176
- self, id: str, *, output: Path | str | None = None
177
- ) -> FileObject:
178
- raise NotImplementedError()
409
+ class AsyncFilesResourceWithRawResponse:
410
+ def __init__(self, files: AsyncFilesResource) -> None:
411
+ self._files = files
179
412
 
180
- async def delete(self, id: str) -> FileDeleteResponse:
181
- requestor = api_requestor.APIRequestor(
182
- client=self._client,
413
+ self.retrieve = async_to_raw_response_wrapper(
414
+ files.retrieve,
415
+ )
416
+ self.list = async_to_raw_response_wrapper(
417
+ files.list,
418
+ )
419
+ self.delete = async_to_raw_response_wrapper(
420
+ files.delete,
421
+ )
422
+ self.content = async_to_custom_raw_response_wrapper(
423
+ files.content,
424
+ AsyncBinaryAPIResponse,
183
425
  )
184
426
 
185
- response, _, _ = await requestor.arequest(
186
- options=TogetherRequest(
187
- method="DELETE",
188
- url=f"files/{id}",
189
- ),
190
- stream=False,
427
+
428
+ class FilesResourceWithStreamingResponse:
429
+ def __init__(self, files: FilesResource) -> None:
430
+ self._files = files
431
+
432
+ self.retrieve = to_streamed_response_wrapper(
433
+ files.retrieve,
434
+ )
435
+ self.list = to_streamed_response_wrapper(
436
+ files.list,
437
+ )
438
+ self.delete = to_streamed_response_wrapper(
439
+ files.delete,
191
440
  )
441
+ self.content = to_custom_streamed_response_wrapper(
442
+ files.content,
443
+ StreamedBinaryAPIResponse,
444
+ )
445
+
192
446
 
193
- assert isinstance(response, TogetherResponse)
447
+ class AsyncFilesResourceWithStreamingResponse:
448
+ def __init__(self, files: AsyncFilesResource) -> None:
449
+ self._files = files
194
450
 
195
- return FileDeleteResponse(**response.data)
451
+ self.retrieve = async_to_streamed_response_wrapper(
452
+ files.retrieve,
453
+ )
454
+ self.list = async_to_streamed_response_wrapper(
455
+ files.list,
456
+ )
457
+ self.delete = async_to_streamed_response_wrapper(
458
+ files.delete,
459
+ )
460
+ self.content = async_to_custom_streamed_response_wrapper(
461
+ files.content,
462
+ AsyncStreamedBinaryAPIResponse,
463
+ )