together 1.5.34__py3-none-any.whl → 2.0.0a6__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 -114
- 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 +65 -81
- together/{cli/api/evaluation.py → lib/cli/api/evals.py} +152 -43
- together/{cli → lib/cli}/api/files.py +20 -17
- together/{cli/api/finetune.py → lib/cli/api/fine_tuning.py} +116 -172
- together/{cli → lib/cli}/api/models.py +34 -27
- together/lib/cli/api/utils.py +50 -0
- together/{cli → lib/cli}/cli.py +16 -26
- together/{constants.py → lib/constants.py} +11 -24
- 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 +397 -0
- together/{utils → lib/utils}/__init__.py +6 -14
- together/{utils → lib/utils}/_log.py +11 -16
- together/{utils → lib/utils}/files.py +90 -288
- together/lib/utils/serializer.py +10 -0
- together/{utils → lib/utils}/tools.py +19 -55
- together/resources/__init__.py +225 -39
- together/resources/audio/__init__.py +72 -48
- together/resources/audio/audio.py +198 -0
- together/resources/audio/speech.py +574 -128
- together/resources/audio/transcriptions.py +247 -261
- together/resources/audio/translations.py +221 -241
- together/resources/audio/voices.py +111 -41
- 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 +589 -477
- together/resources/evals.py +452 -0
- together/resources/files.py +397 -129
- together/resources/fine_tuning.py +1033 -0
- together/resources/hardware.py +181 -0
- together/resources/images.py +258 -104
- together/resources/jobs.py +214 -0
- together/resources/models.py +223 -193
- together/resources/rerank.py +190 -92
- together/resources/videos.py +286 -214
- together/types/__init__.py +66 -167
- 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_create_response.py +10 -0
- together/types/video_job.py +57 -0
- together-2.0.0a6.dist-info/METADATA +729 -0
- together-2.0.0a6.dist-info/RECORD +165 -0
- {together-1.5.34.dist-info → together-2.0.0a6.dist-info}/WHEEL +1 -1
- together-2.0.0a6.dist-info/entry_points.txt +2 -0
- {together-1.5.34.dist-info → together-2.0.0a6.dist-info}/licenses/LICENSE +1 -1
- together/abstract/api_requestor.py +0 -770
- together/cli/api/chat.py +0 -298
- together/cli/api/completions.py +0 -119
- together/cli/api/images.py +0 -93
- together/cli/api/utils.py +0 -139
- together/client.py +0 -186
- together/error.py +0 -194
- together/filemanager.py +0 -635
- 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 -165
- together/resources/code_interpreter.py +0 -82
- together/resources/evaluation.py +0 -808
- together/resources/finetune.py +0 -1388
- together/together_response.py +0 -50
- together/types/abstract.py +0 -26
- together/types/audio_speech.py +0 -311
- together/types/batch.py +0 -54
- together/types/chat_completions.py +0 -210
- together/types/code_interpreter.py +0 -57
- together/types/common.py +0 -67
- 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/evaluation.py +0 -93
- together/types/files.py +0 -93
- together/types/finetune.py +0 -464
- together/types/images.py +0 -42
- together/types/models.py +0 -96
- together/types/rerank.py +0 -43
- together/types/videos.py +0 -69
- together/utils/api_helpers.py +0 -124
- together/version.py +0 -6
- together-1.5.34.dist-info/METADATA +0 -583
- together-1.5.34.dist-info/RECORD +0 -77
- together-1.5.34.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,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
|
-
|
|
8
|
-
|
|
9
|
-
from together.
|
|
10
|
-
|
|
11
|
-
from
|
|
12
|
-
from
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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 =
|
|
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
|
|
47
|
-
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
|
-
|
|
52
|
-
file_size_gb = file_size / NUM_BYTES_IN_GB
|
|
163
|
+
purpose = cast(FilePurpose, purpose)
|
|
53
164
|
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
211
|
+
cast_to=BinaryAPIResponse,
|
|
72
212
|
)
|
|
73
213
|
|
|
74
|
-
assert isinstance(response, TogetherResponse)
|
|
75
214
|
|
|
76
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
231
|
+
For more information, see https://www.github.com/togethercomputer/together-py#with_streaming_response
|
|
232
|
+
"""
|
|
233
|
+
return AsyncFilesResourceWithStreamingResponse(self)
|
|
92
234
|
|
|
93
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
) -> FileObject:
|
|
98
|
-
download_manager = DownloadManager(self._client)
|
|
249
|
+
Args:
|
|
250
|
+
extra_headers: Send extra headers
|
|
99
251
|
|
|
100
|
-
|
|
101
|
-
output = Path(output)
|
|
252
|
+
extra_query: Add additional query parameters to the request
|
|
102
253
|
|
|
103
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
317
|
+
cast_to=FileDeleteResponse,
|
|
125
318
|
)
|
|
126
319
|
|
|
127
|
-
|
|
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
|
-
|
|
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
|
-
|
|
133
|
-
def __init__(self, client: TogetherClient) -> None:
|
|
134
|
-
self._client = client
|
|
338
|
+
purpose = cast(FilePurpose, purpose)
|
|
135
339
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
) -> None:
|
|
139
|
-
raise NotImplementedError()
|
|
340
|
+
upload_manager = AsyncUploadManager(self._client)
|
|
341
|
+
result = await upload_manager.upload("/files", file, purpose)
|
|
140
342
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
386
|
+
cast_to=AsyncBinaryAPIResponse,
|
|
152
387
|
)
|
|
153
388
|
|
|
154
|
-
assert isinstance(response, TogetherResponse)
|
|
155
389
|
|
|
156
|
-
|
|
390
|
+
class FilesResourceWithRawResponse:
|
|
391
|
+
def __init__(self, files: FilesResource) -> None:
|
|
392
|
+
self._files = files
|
|
157
393
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
client=self._client,
|
|
394
|
+
self.retrieve = to_raw_response_wrapper(
|
|
395
|
+
files.retrieve,
|
|
161
396
|
)
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
raise NotImplementedError()
|
|
409
|
+
class AsyncFilesResourceWithRawResponse:
|
|
410
|
+
def __init__(self, files: AsyncFilesResource) -> None:
|
|
411
|
+
self._files = files
|
|
179
412
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
|
|
447
|
+
class AsyncFilesResourceWithStreamingResponse:
|
|
448
|
+
def __init__(self, files: AsyncFilesResource) -> None:
|
|
449
|
+
self._files = files
|
|
194
450
|
|
|
195
|
-
|
|
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
|
+
)
|