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.
- together/__init__.py +101 -63
- together/_base_client.py +1995 -0
- together/_client.py +1033 -0
- together/_compat.py +219 -0
- together/_constants.py +14 -0
- together/_exceptions.py +108 -0
- together/_files.py +123 -0
- together/_models.py +857 -0
- together/_qs.py +150 -0
- together/_resource.py +43 -0
- together/_response.py +830 -0
- together/_streaming.py +370 -0
- together/_types.py +260 -0
- together/_utils/__init__.py +64 -0
- together/_utils/_compat.py +45 -0
- together/_utils/_datetime_parse.py +136 -0
- together/_utils/_logs.py +25 -0
- together/_utils/_proxy.py +65 -0
- together/_utils/_reflection.py +42 -0
- together/_utils/_resources_proxy.py +24 -0
- together/_utils/_streams.py +12 -0
- together/_utils/_sync.py +58 -0
- together/_utils/_transform.py +457 -0
- together/_utils/_typing.py +156 -0
- together/_utils/_utils.py +421 -0
- together/_version.py +4 -0
- together/lib/.keep +4 -0
- together/lib/__init__.py +23 -0
- together/{cli → lib/cli}/api/endpoints.py +108 -75
- together/lib/cli/api/evals.py +588 -0
- together/{cli → lib/cli}/api/files.py +20 -17
- together/{cli/api/finetune.py → lib/cli/api/fine_tuning.py} +161 -120
- together/lib/cli/api/models.py +140 -0
- together/{cli → lib/cli}/api/utils.py +6 -7
- together/{cli → lib/cli}/cli.py +16 -24
- together/{constants.py → lib/constants.py} +17 -12
- together/lib/resources/__init__.py +11 -0
- together/lib/resources/files.py +999 -0
- together/lib/resources/fine_tuning.py +280 -0
- together/lib/resources/models.py +35 -0
- together/lib/types/__init__.py +13 -0
- together/lib/types/error.py +9 -0
- together/lib/types/fine_tuning.py +455 -0
- together/{utils → lib/utils}/__init__.py +6 -14
- together/{utils → lib/utils}/_log.py +11 -16
- together/lib/utils/files.py +628 -0
- together/lib/utils/serializer.py +10 -0
- together/{utils → lib/utils}/tools.py +19 -55
- together/resources/__init__.py +225 -33
- together/resources/audio/__init__.py +72 -21
- together/resources/audio/audio.py +198 -0
- together/resources/audio/speech.py +574 -122
- together/resources/audio/transcriptions.py +282 -0
- together/resources/audio/translations.py +256 -0
- together/resources/audio/voices.py +135 -0
- together/resources/batches.py +417 -0
- together/resources/chat/__init__.py +30 -21
- together/resources/chat/chat.py +102 -0
- together/resources/chat/completions.py +1063 -263
- together/resources/code_interpreter/__init__.py +33 -0
- together/resources/code_interpreter/code_interpreter.py +258 -0
- together/resources/code_interpreter/sessions.py +135 -0
- together/resources/completions.py +884 -225
- together/resources/embeddings.py +172 -68
- together/resources/endpoints.py +598 -395
- together/resources/evals.py +452 -0
- together/resources/files.py +398 -121
- together/resources/fine_tuning.py +1033 -0
- together/resources/hardware.py +181 -0
- together/resources/images.py +256 -108
- together/resources/jobs.py +214 -0
- together/resources/models.py +238 -90
- together/resources/rerank.py +190 -92
- together/resources/videos.py +374 -0
- together/types/__init__.py +65 -109
- together/types/audio/__init__.py +10 -0
- together/types/audio/speech_create_params.py +75 -0
- together/types/audio/transcription_create_params.py +54 -0
- together/types/audio/transcription_create_response.py +111 -0
- together/types/audio/translation_create_params.py +40 -0
- together/types/audio/translation_create_response.py +70 -0
- together/types/audio/voice_list_response.py +23 -0
- together/types/audio_speech_stream_chunk.py +16 -0
- together/types/autoscaling.py +13 -0
- together/types/autoscaling_param.py +15 -0
- together/types/batch_create_params.py +24 -0
- together/types/batch_create_response.py +14 -0
- together/types/batch_job.py +45 -0
- together/types/batch_list_response.py +10 -0
- together/types/chat/__init__.py +18 -0
- together/types/chat/chat_completion.py +60 -0
- together/types/chat/chat_completion_chunk.py +61 -0
- together/types/chat/chat_completion_structured_message_image_url_param.py +18 -0
- together/types/chat/chat_completion_structured_message_text_param.py +13 -0
- together/types/chat/chat_completion_structured_message_video_url_param.py +18 -0
- together/types/chat/chat_completion_usage.py +13 -0
- together/types/chat/chat_completion_warning.py +9 -0
- together/types/chat/completion_create_params.py +329 -0
- together/types/code_interpreter/__init__.py +5 -0
- together/types/code_interpreter/session_list_response.py +31 -0
- together/types/code_interpreter_execute_params.py +45 -0
- together/types/completion.py +42 -0
- together/types/completion_chunk.py +66 -0
- together/types/completion_create_params.py +138 -0
- together/types/dedicated_endpoint.py +44 -0
- together/types/embedding.py +24 -0
- together/types/embedding_create_params.py +31 -0
- together/types/endpoint_create_params.py +43 -0
- together/types/endpoint_list_avzones_response.py +11 -0
- together/types/endpoint_list_params.py +18 -0
- together/types/endpoint_list_response.py +41 -0
- together/types/endpoint_update_params.py +27 -0
- together/types/eval_create_params.py +263 -0
- together/types/eval_create_response.py +16 -0
- together/types/eval_list_params.py +21 -0
- together/types/eval_list_response.py +10 -0
- together/types/eval_status_response.py +100 -0
- together/types/evaluation_job.py +139 -0
- together/types/execute_response.py +108 -0
- together/types/file_delete_response.py +13 -0
- together/types/file_list.py +12 -0
- together/types/file_purpose.py +9 -0
- together/types/file_response.py +31 -0
- together/types/file_type.py +7 -0
- together/types/fine_tuning_cancel_response.py +194 -0
- together/types/fine_tuning_content_params.py +24 -0
- together/types/fine_tuning_delete_params.py +11 -0
- together/types/fine_tuning_delete_response.py +12 -0
- together/types/fine_tuning_list_checkpoints_response.py +21 -0
- together/types/fine_tuning_list_events_response.py +12 -0
- together/types/fine_tuning_list_response.py +199 -0
- together/types/finetune_event.py +41 -0
- together/types/finetune_event_type.py +33 -0
- together/types/finetune_response.py +177 -0
- together/types/hardware_list_params.py +16 -0
- together/types/hardware_list_response.py +58 -0
- together/types/image_data_b64.py +15 -0
- together/types/image_data_url.py +15 -0
- together/types/image_file.py +23 -0
- together/types/image_generate_params.py +85 -0
- together/types/job_list_response.py +47 -0
- together/types/job_retrieve_response.py +43 -0
- together/types/log_probs.py +18 -0
- together/types/model_list_response.py +10 -0
- together/types/model_object.py +42 -0
- together/types/model_upload_params.py +36 -0
- together/types/model_upload_response.py +23 -0
- together/types/rerank_create_params.py +36 -0
- together/types/rerank_create_response.py +36 -0
- together/types/tool_choice.py +23 -0
- together/types/tool_choice_param.py +23 -0
- together/types/tools_param.py +23 -0
- together/types/training_method_dpo.py +22 -0
- together/types/training_method_sft.py +18 -0
- together/types/video_create_params.py +86 -0
- together/types/video_job.py +57 -0
- together-2.0.0a8.dist-info/METADATA +680 -0
- together-2.0.0a8.dist-info/RECORD +164 -0
- {together-1.5.17.dist-info → together-2.0.0a8.dist-info}/WHEEL +1 -1
- together-2.0.0a8.dist-info/entry_points.txt +2 -0
- {together-1.5.17.dist-info → together-2.0.0a8.dist-info/licenses}/LICENSE +1 -1
- together/abstract/api_requestor.py +0 -729
- together/cli/api/chat.py +0 -276
- together/cli/api/completions.py +0 -119
- together/cli/api/images.py +0 -93
- together/cli/api/models.py +0 -55
- together/client.py +0 -176
- together/error.py +0 -194
- together/filemanager.py +0 -389
- together/legacy/__init__.py +0 -0
- together/legacy/base.py +0 -27
- together/legacy/complete.py +0 -93
- together/legacy/embeddings.py +0 -27
- together/legacy/files.py +0 -146
- together/legacy/finetune.py +0 -177
- together/legacy/images.py +0 -27
- together/legacy/models.py +0 -44
- together/resources/batch.py +0 -136
- together/resources/code_interpreter.py +0 -82
- together/resources/finetune.py +0 -1064
- together/together_response.py +0 -50
- together/types/abstract.py +0 -26
- together/types/audio_speech.py +0 -110
- together/types/batch.py +0 -53
- together/types/chat_completions.py +0 -197
- together/types/code_interpreter.py +0 -57
- together/types/common.py +0 -66
- together/types/completions.py +0 -107
- together/types/embeddings.py +0 -35
- together/types/endpoints.py +0 -123
- together/types/error.py +0 -16
- together/types/files.py +0 -90
- together/types/finetune.py +0 -398
- together/types/images.py +0 -44
- together/types/models.py +0 -45
- together/types/rerank.py +0 -43
- together/utils/api_helpers.py +0 -124
- together/utils/files.py +0 -425
- together/version.py +0 -6
- together-1.5.17.dist-info/METADATA +0 -525
- together-1.5.17.dist-info/RECORD +0 -69
- together-1.5.17.dist-info/entry_points.txt +0 -3
- /together/{abstract → lib/cli}/__init__.py +0 -0
- /together/{cli → lib/cli/api}/__init__.py +0 -0
- /together/{cli/api/__init__.py → py.typed} +0 -0
together/resources/files.py
CHANGED
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
from together.
|
|
9
|
-
|
|
10
|
-
from
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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 =
|
|
149
|
+
purpose: FilePurpose | str = "fine-tune",
|
|
31
150
|
check: bool = True,
|
|
32
151
|
) -> FileResponse:
|
|
33
|
-
|
|
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
|
|
46
|
-
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
|
-
|
|
163
|
+
purpose = cast(FilePurpose, purpose)
|
|
51
164
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
211
|
+
cast_to=BinaryAPIResponse,
|
|
63
212
|
)
|
|
64
213
|
|
|
65
|
-
assert isinstance(response, TogetherResponse)
|
|
66
214
|
|
|
67
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
231
|
+
For more information, see https://www.github.com/togethercomputer/together-py#with_streaming_response
|
|
232
|
+
"""
|
|
233
|
+
return AsyncFilesResourceWithStreamingResponse(self)
|
|
83
234
|
|
|
84
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
) -> FileObject:
|
|
89
|
-
download_manager = DownloadManager(self._client)
|
|
249
|
+
Args:
|
|
250
|
+
extra_headers: Send extra headers
|
|
90
251
|
|
|
91
|
-
|
|
92
|
-
output = Path(output)
|
|
252
|
+
extra_query: Add additional query parameters to the request
|
|
93
253
|
|
|
94
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
317
|
+
cast_to=FileDeleteResponse,
|
|
116
318
|
)
|
|
117
319
|
|
|
118
|
-
|
|
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
|
-
|
|
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
|
-
|
|
124
|
-
def __init__(self, client: TogetherClient) -> None:
|
|
125
|
-
self._client = client
|
|
338
|
+
purpose = cast(FilePurpose, purpose)
|
|
126
339
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
) -> None:
|
|
130
|
-
raise NotImplementedError()
|
|
340
|
+
upload_manager = AsyncUploadManager(self._client)
|
|
341
|
+
result = await upload_manager.upload("/files", file, purpose)
|
|
131
342
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
|
|
386
|
+
cast_to=AsyncBinaryAPIResponse,
|
|
143
387
|
)
|
|
144
388
|
|
|
145
|
-
assert isinstance(response, TogetherResponse)
|
|
146
389
|
|
|
147
|
-
|
|
390
|
+
class FilesResourceWithRawResponse:
|
|
391
|
+
def __init__(self, files: FilesResource) -> None:
|
|
392
|
+
self._files = files
|
|
148
393
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
client=self._client,
|
|
394
|
+
self.retrieve = to_raw_response_wrapper(
|
|
395
|
+
files.retrieve,
|
|
152
396
|
)
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
raise NotImplementedError()
|
|
409
|
+
class AsyncFilesResourceWithRawResponse:
|
|
410
|
+
def __init__(self, files: AsyncFilesResource) -> None:
|
|
411
|
+
self._files = files
|
|
170
412
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
|
|
447
|
+
class AsyncFilesResourceWithStreamingResponse:
|
|
448
|
+
def __init__(self, files: AsyncFilesResource) -> None:
|
|
449
|
+
self._files = files
|
|
185
450
|
|
|
186
|
-
|
|
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
|
+
)
|