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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. together/__init__.py +101 -63
  2. together/_base_client.py +1995 -0
  3. together/_client.py +1033 -0
  4. together/_compat.py +219 -0
  5. together/_constants.py +14 -0
  6. together/_exceptions.py +108 -0
  7. together/_files.py +123 -0
  8. together/_models.py +857 -0
  9. together/_qs.py +150 -0
  10. together/_resource.py +43 -0
  11. together/_response.py +830 -0
  12. together/_streaming.py +370 -0
  13. together/_types.py +260 -0
  14. together/_utils/__init__.py +64 -0
  15. together/_utils/_compat.py +45 -0
  16. together/_utils/_datetime_parse.py +136 -0
  17. together/_utils/_logs.py +25 -0
  18. together/_utils/_proxy.py +65 -0
  19. together/_utils/_reflection.py +42 -0
  20. together/_utils/_resources_proxy.py +24 -0
  21. together/_utils/_streams.py +12 -0
  22. together/_utils/_sync.py +58 -0
  23. together/_utils/_transform.py +457 -0
  24. together/_utils/_typing.py +156 -0
  25. together/_utils/_utils.py +421 -0
  26. together/_version.py +4 -0
  27. together/lib/.keep +4 -0
  28. together/lib/__init__.py +23 -0
  29. together/{cli → lib/cli}/api/endpoints.py +108 -75
  30. together/lib/cli/api/evals.py +588 -0
  31. together/{cli → lib/cli}/api/files.py +20 -17
  32. together/{cli/api/finetune.py → lib/cli/api/fine_tuning.py} +161 -120
  33. together/lib/cli/api/models.py +140 -0
  34. together/{cli → lib/cli}/api/utils.py +6 -7
  35. together/{cli → lib/cli}/cli.py +16 -24
  36. together/{constants.py → lib/constants.py} +17 -12
  37. together/lib/resources/__init__.py +11 -0
  38. together/lib/resources/files.py +999 -0
  39. together/lib/resources/fine_tuning.py +280 -0
  40. together/lib/resources/models.py +35 -0
  41. together/lib/types/__init__.py +13 -0
  42. together/lib/types/error.py +9 -0
  43. together/lib/types/fine_tuning.py +455 -0
  44. together/{utils → lib/utils}/__init__.py +6 -14
  45. together/{utils → lib/utils}/_log.py +11 -16
  46. together/lib/utils/files.py +628 -0
  47. together/lib/utils/serializer.py +10 -0
  48. together/{utils → lib/utils}/tools.py +19 -55
  49. together/resources/__init__.py +225 -33
  50. together/resources/audio/__init__.py +72 -21
  51. together/resources/audio/audio.py +198 -0
  52. together/resources/audio/speech.py +574 -122
  53. together/resources/audio/transcriptions.py +282 -0
  54. together/resources/audio/translations.py +256 -0
  55. together/resources/audio/voices.py +135 -0
  56. together/resources/batches.py +417 -0
  57. together/resources/chat/__init__.py +30 -21
  58. together/resources/chat/chat.py +102 -0
  59. together/resources/chat/completions.py +1063 -263
  60. together/resources/code_interpreter/__init__.py +33 -0
  61. together/resources/code_interpreter/code_interpreter.py +258 -0
  62. together/resources/code_interpreter/sessions.py +135 -0
  63. together/resources/completions.py +884 -225
  64. together/resources/embeddings.py +172 -68
  65. together/resources/endpoints.py +598 -395
  66. together/resources/evals.py +452 -0
  67. together/resources/files.py +398 -121
  68. together/resources/fine_tuning.py +1033 -0
  69. together/resources/hardware.py +181 -0
  70. together/resources/images.py +256 -108
  71. together/resources/jobs.py +214 -0
  72. together/resources/models.py +238 -90
  73. together/resources/rerank.py +190 -92
  74. together/resources/videos.py +374 -0
  75. together/types/__init__.py +65 -109
  76. together/types/audio/__init__.py +10 -0
  77. together/types/audio/speech_create_params.py +75 -0
  78. together/types/audio/transcription_create_params.py +54 -0
  79. together/types/audio/transcription_create_response.py +111 -0
  80. together/types/audio/translation_create_params.py +40 -0
  81. together/types/audio/translation_create_response.py +70 -0
  82. together/types/audio/voice_list_response.py +23 -0
  83. together/types/audio_speech_stream_chunk.py +16 -0
  84. together/types/autoscaling.py +13 -0
  85. together/types/autoscaling_param.py +15 -0
  86. together/types/batch_create_params.py +24 -0
  87. together/types/batch_create_response.py +14 -0
  88. together/types/batch_job.py +45 -0
  89. together/types/batch_list_response.py +10 -0
  90. together/types/chat/__init__.py +18 -0
  91. together/types/chat/chat_completion.py +60 -0
  92. together/types/chat/chat_completion_chunk.py +61 -0
  93. together/types/chat/chat_completion_structured_message_image_url_param.py +18 -0
  94. together/types/chat/chat_completion_structured_message_text_param.py +13 -0
  95. together/types/chat/chat_completion_structured_message_video_url_param.py +18 -0
  96. together/types/chat/chat_completion_usage.py +13 -0
  97. together/types/chat/chat_completion_warning.py +9 -0
  98. together/types/chat/completion_create_params.py +329 -0
  99. together/types/code_interpreter/__init__.py +5 -0
  100. together/types/code_interpreter/session_list_response.py +31 -0
  101. together/types/code_interpreter_execute_params.py +45 -0
  102. together/types/completion.py +42 -0
  103. together/types/completion_chunk.py +66 -0
  104. together/types/completion_create_params.py +138 -0
  105. together/types/dedicated_endpoint.py +44 -0
  106. together/types/embedding.py +24 -0
  107. together/types/embedding_create_params.py +31 -0
  108. together/types/endpoint_create_params.py +43 -0
  109. together/types/endpoint_list_avzones_response.py +11 -0
  110. together/types/endpoint_list_params.py +18 -0
  111. together/types/endpoint_list_response.py +41 -0
  112. together/types/endpoint_update_params.py +27 -0
  113. together/types/eval_create_params.py +263 -0
  114. together/types/eval_create_response.py +16 -0
  115. together/types/eval_list_params.py +21 -0
  116. together/types/eval_list_response.py +10 -0
  117. together/types/eval_status_response.py +100 -0
  118. together/types/evaluation_job.py +139 -0
  119. together/types/execute_response.py +108 -0
  120. together/types/file_delete_response.py +13 -0
  121. together/types/file_list.py +12 -0
  122. together/types/file_purpose.py +9 -0
  123. together/types/file_response.py +31 -0
  124. together/types/file_type.py +7 -0
  125. together/types/fine_tuning_cancel_response.py +194 -0
  126. together/types/fine_tuning_content_params.py +24 -0
  127. together/types/fine_tuning_delete_params.py +11 -0
  128. together/types/fine_tuning_delete_response.py +12 -0
  129. together/types/fine_tuning_list_checkpoints_response.py +21 -0
  130. together/types/fine_tuning_list_events_response.py +12 -0
  131. together/types/fine_tuning_list_response.py +199 -0
  132. together/types/finetune_event.py +41 -0
  133. together/types/finetune_event_type.py +33 -0
  134. together/types/finetune_response.py +177 -0
  135. together/types/hardware_list_params.py +16 -0
  136. together/types/hardware_list_response.py +58 -0
  137. together/types/image_data_b64.py +15 -0
  138. together/types/image_data_url.py +15 -0
  139. together/types/image_file.py +23 -0
  140. together/types/image_generate_params.py +85 -0
  141. together/types/job_list_response.py +47 -0
  142. together/types/job_retrieve_response.py +43 -0
  143. together/types/log_probs.py +18 -0
  144. together/types/model_list_response.py +10 -0
  145. together/types/model_object.py +42 -0
  146. together/types/model_upload_params.py +36 -0
  147. together/types/model_upload_response.py +23 -0
  148. together/types/rerank_create_params.py +36 -0
  149. together/types/rerank_create_response.py +36 -0
  150. together/types/tool_choice.py +23 -0
  151. together/types/tool_choice_param.py +23 -0
  152. together/types/tools_param.py +23 -0
  153. together/types/training_method_dpo.py +22 -0
  154. together/types/training_method_sft.py +18 -0
  155. together/types/video_create_params.py +86 -0
  156. together/types/video_job.py +57 -0
  157. together-2.0.0a8.dist-info/METADATA +680 -0
  158. together-2.0.0a8.dist-info/RECORD +164 -0
  159. {together-1.5.17.dist-info → together-2.0.0a8.dist-info}/WHEEL +1 -1
  160. together-2.0.0a8.dist-info/entry_points.txt +2 -0
  161. {together-1.5.17.dist-info → together-2.0.0a8.dist-info/licenses}/LICENSE +1 -1
  162. together/abstract/api_requestor.py +0 -729
  163. together/cli/api/chat.py +0 -276
  164. together/cli/api/completions.py +0 -119
  165. together/cli/api/images.py +0 -93
  166. together/cli/api/models.py +0 -55
  167. together/client.py +0 -176
  168. together/error.py +0 -194
  169. together/filemanager.py +0 -389
  170. together/legacy/__init__.py +0 -0
  171. together/legacy/base.py +0 -27
  172. together/legacy/complete.py +0 -93
  173. together/legacy/embeddings.py +0 -27
  174. together/legacy/files.py +0 -146
  175. together/legacy/finetune.py +0 -177
  176. together/legacy/images.py +0 -27
  177. together/legacy/models.py +0 -44
  178. together/resources/batch.py +0 -136
  179. together/resources/code_interpreter.py +0 -82
  180. together/resources/finetune.py +0 -1064
  181. together/together_response.py +0 -50
  182. together/types/abstract.py +0 -26
  183. together/types/audio_speech.py +0 -110
  184. together/types/batch.py +0 -53
  185. together/types/chat_completions.py +0 -197
  186. together/types/code_interpreter.py +0 -57
  187. together/types/common.py +0 -66
  188. together/types/completions.py +0 -107
  189. together/types/embeddings.py +0 -35
  190. together/types/endpoints.py +0 -123
  191. together/types/error.py +0 -16
  192. together/types/files.py +0 -90
  193. together/types/finetune.py +0 -398
  194. together/types/images.py +0 -44
  195. together/types/models.py +0 -45
  196. together/types/rerank.py +0 -43
  197. together/utils/api_helpers.py +0 -124
  198. together/utils/files.py +0 -425
  199. together/version.py +0 -6
  200. together-1.5.17.dist-info/METADATA +0 -525
  201. together-1.5.17.dist-info/RECORD +0 -69
  202. together-1.5.17.dist-info/entry_points.txt +0 -3
  203. /together/{abstract → lib/cli}/__init__.py +0 -0
  204. /together/{cli → lib/cli/api}/__init__.py +0 -0
  205. /together/{cli/api/__init__.py → py.typed} +0 -0
@@ -1,186 +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
- from pathlib import Path
4
5
  from pprint import pformat
6
+ from typing import cast, get_args
7
+ from pathlib import Path
5
8
 
6
- from together.abstract import api_requestor
7
- from together.error import FileTypeError
8
- from together.filemanager import DownloadManager, UploadManager
9
- from together.together_response import TogetherResponse
10
- from together.types import (
11
- FileDeleteResponse,
12
- FileList,
13
- FileObject,
14
- FilePurpose,
15
- FileResponse,
16
- TogetherClient,
17
- 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,
18
31
  )
19
- 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
20
78
 
79
+ extra_body: Add additional JSON properties to the request
21
80
 
22
- class Files:
23
- def __init__(self, client: TogetherClient) -> None:
24
- self._client = client
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
+ )
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
+ )
111
+
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
+ )
25
144
 
26
145
  def upload(
27
146
  self,
28
147
  file: Path | str,
29
148
  *,
30
- purpose: FilePurpose | str = FilePurpose.FineTune,
149
+ purpose: FilePurpose | str = "fine-tune",
31
150
  check: bool = True,
32
151
  ) -> FileResponse:
33
- upload_manager = UploadManager(self._client)
34
-
35
- if check and purpose == FilePurpose.FineTune:
152
+ if check:
36
153
  report_dict = check_file(file)
37
154
  if not report_dict["is_check_passed"]:
38
- raise FileTypeError(
39
- f"Invalid file supplied, failed to upload. Report:\n{pformat(report_dict)}"
40
- )
155
+ raise FileTypeError(f"Invalid file supplied, failed to upload. Report:\n{pformat(report_dict)}")
41
156
 
42
157
  if isinstance(file, str):
43
158
  file = Path(file)
44
159
 
45
- if isinstance(purpose, str):
46
- purpose = FilePurpose(purpose)
47
-
48
- 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)}")
49
162
 
50
- return upload_manager.upload("files", file, purpose=purpose, redirect=True)
163
+ purpose = cast(FilePurpose, purpose)
51
164
 
52
- def list(self) -> FileList:
53
- requestor = api_requestor.APIRequestor(
54
- client=self._client,
165
+ upload_manager = UploadManager(self._client)
166
+ result = upload_manager.upload("/files", file, purpose)
167
+
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,
55
178
  )
56
179
 
57
- response, _, _ = requestor.request(
58
- options=TogetherRequest(
59
- method="GET",
60
- 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
61
210
  ),
62
- stream=False,
211
+ cast_to=BinaryAPIResponse,
63
212
  )
64
213
 
65
- assert isinstance(response, TogetherResponse)
66
214
 
67
- 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.
68
221
 
69
- def retrieve(self, id: str) -> FileResponse:
70
- requestor = api_requestor.APIRequestor(
71
- client=self._client,
72
- )
222
+ For more information, see https://www.github.com/togethercomputer/together-py#accessing-raw-response-data-eg-headers
223
+ """
224
+ return AsyncFilesResourceWithRawResponse(self)
73
225
 
74
- response, _, _ = requestor.request(
75
- options=TogetherRequest(
76
- method="GET",
77
- url=f"files/{id}",
78
- ),
79
- stream=False,
80
- )
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.
81
230
 
82
- assert isinstance(response, TogetherResponse)
231
+ For more information, see https://www.github.com/togethercomputer/together-py#with_streaming_response
232
+ """
233
+ return AsyncFilesResourceWithStreamingResponse(self)
83
234
 
84
- 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.
85
248
 
86
- def retrieve_content(
87
- self, id: str, *, output: Path | str | None = None
88
- ) -> FileObject:
89
- download_manager = DownloadManager(self._client)
249
+ Args:
250
+ extra_headers: Send extra headers
90
251
 
91
- if isinstance(output, str):
92
- output = Path(output)
252
+ extra_query: Add additional query parameters to the request
93
253
 
94
- downloaded_filename, file_size = download_manager.download(
95
- f"files/{id}/content", output, normalize_key(f"{id}.jsonl")
96
- )
254
+ extra_body: Add additional JSON properties to the request
97
255
 
98
- return FileObject(
99
- object="local",
100
- id=id,
101
- filename=downloaded_filename,
102
- 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,
103
266
  )
104
267
 
105
- def delete(self, id: str) -> FileDeleteResponse:
106
- requestor = api_requestor.APIRequestor(
107
- 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,
108
285
  )
109
286
 
110
- response, _, _ = requestor.request(
111
- options=TogetherRequest(
112
- method="DELETE",
113
- 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
114
316
  ),
115
- stream=False,
317
+ cast_to=FileDeleteResponse,
116
318
  )
117
319
 
118
- 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)}")
119
331
 
120
- return FileDeleteResponse(**response.data)
332
+ if isinstance(file, str):
333
+ file = Path(file)
121
334
 
335
+ if purpose not in get_args(FilePurpose):
336
+ raise ValueError(f"Invalid purpose '{purpose}'. Must be one of: {get_args(FilePurpose)}")
122
337
 
123
- class AsyncFiles:
124
- def __init__(self, client: TogetherClient) -> None:
125
- self._client = client
338
+ purpose = cast(FilePurpose, purpose)
126
339
 
127
- async def upload(
128
- self, file: Path | str, *, purpose: FilePurpose | str = FilePurpose.FineTune
129
- ) -> None:
130
- raise NotImplementedError()
340
+ upload_manager = AsyncUploadManager(self._client)
341
+ result = await upload_manager.upload("/files", file, purpose)
131
342
 
132
- async def list(self) -> FileList:
133
- requestor = api_requestor.APIRequestor(
134
- 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,
135
353
  )
136
354
 
137
- response, _, _ = await requestor.arequest(
138
- options=TogetherRequest(
139
- method="GET",
140
- 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
141
385
  ),
142
- stream=False,
386
+ cast_to=AsyncBinaryAPIResponse,
143
387
  )
144
388
 
145
- assert isinstance(response, TogetherResponse)
146
389
 
147
- return FileList(**response.data)
390
+ class FilesResourceWithRawResponse:
391
+ def __init__(self, files: FilesResource) -> None:
392
+ self._files = files
148
393
 
149
- async def retrieve(self, id: str) -> FileResponse:
150
- requestor = api_requestor.APIRequestor(
151
- client=self._client,
394
+ self.retrieve = to_raw_response_wrapper(
395
+ files.retrieve,
152
396
  )
153
-
154
- response, _, _ = await requestor.arequest(
155
- options=TogetherRequest(
156
- method="GET",
157
- url=f"files/{id}",
158
- ),
159
- 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,
160
406
  )
161
407
 
162
- assert isinstance(response, TogetherResponse)
163
-
164
- return FileResponse(**response.data)
165
408
 
166
- async def retrieve_content(
167
- self, id: str, *, output: Path | str | None = None
168
- ) -> FileObject:
169
- raise NotImplementedError()
409
+ class AsyncFilesResourceWithRawResponse:
410
+ def __init__(self, files: AsyncFilesResource) -> None:
411
+ self._files = files
170
412
 
171
- async def delete(self, id: str) -> FileDeleteResponse:
172
- requestor = api_requestor.APIRequestor(
173
- 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,
174
425
  )
175
426
 
176
- response, _, _ = await requestor.arequest(
177
- options=TogetherRequest(
178
- method="DELETE",
179
- url=f"files/{id}",
180
- ),
181
- 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,
182
440
  )
441
+ self.content = to_custom_streamed_response_wrapper(
442
+ files.content,
443
+ StreamedBinaryAPIResponse,
444
+ )
445
+
183
446
 
184
- assert isinstance(response, TogetherResponse)
447
+ class AsyncFilesResourceWithStreamingResponse:
448
+ def __init__(self, files: AsyncFilesResource) -> None:
449
+ self._files = files
185
450
 
186
- 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
+ )