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
together/filemanager.py DELETED
@@ -1,389 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import os
4
- import shutil
5
- import stat
6
- import tempfile
7
- import uuid
8
- from functools import partial
9
- from pathlib import Path
10
- from typing import Tuple
11
-
12
- import requests
13
- from filelock import FileLock
14
- from requests.structures import CaseInsensitiveDict
15
- from tqdm import tqdm
16
- from tqdm.utils import CallbackIOWrapper
17
-
18
- import together.utils
19
- from together.abstract import api_requestor
20
- from together.constants import DISABLE_TQDM, DOWNLOAD_BLOCK_SIZE, MAX_RETRIES
21
- from together.error import (
22
- APIError,
23
- AuthenticationError,
24
- DownloadError,
25
- FileTypeError,
26
- )
27
- from together.together_response import TogetherResponse
28
- from together.types import (
29
- FilePurpose,
30
- FileResponse,
31
- FileType,
32
- TogetherClient,
33
- TogetherRequest,
34
- )
35
-
36
-
37
- def chmod_and_replace(src: Path, dst: Path) -> None:
38
- """Set correct permission before moving a blob from tmp directory to cache dir.
39
-
40
- Do not take into account the `umask` from the process as there is no convenient way
41
- to get it that is thread-safe.
42
- """
43
-
44
- # Get umask by creating a temporary file in the cache folder.
45
- tmp_file = dst.parent / f"tmp_{uuid.uuid4()}"
46
-
47
- try:
48
- tmp_file.touch()
49
-
50
- cache_dir_mode = Path(tmp_file).stat().st_mode
51
-
52
- os.chmod(src.as_posix(), stat.S_IMODE(cache_dir_mode))
53
-
54
- finally:
55
- tmp_file.unlink()
56
-
57
- shutil.move(src.as_posix(), dst.as_posix())
58
-
59
-
60
- def _get_file_size(
61
- headers: CaseInsensitiveDict[str],
62
- ) -> int:
63
- """
64
- Extracts file size from header
65
- """
66
- total_size_in_bytes = 0
67
-
68
- parts = headers.get("Content-Range", "").split(" ")
69
-
70
- if len(parts) == 2:
71
- range_parts = parts[1].split("/")
72
-
73
- if len(range_parts) == 2:
74
- total_size_in_bytes = int(range_parts[1])
75
-
76
- assert total_size_in_bytes != 0, "Unable to retrieve remote file."
77
-
78
- return total_size_in_bytes
79
-
80
-
81
- def _prepare_output(
82
- headers: CaseInsensitiveDict[str],
83
- step: int = -1,
84
- output: Path | None = None,
85
- remote_name: str | None = None,
86
- ) -> Path:
87
- """
88
- Generates output file name from remote name and headers
89
- """
90
- if output:
91
- return output
92
-
93
- content_type = str(headers.get("content-type"))
94
-
95
- assert remote_name, (
96
- "No model name found in fine_tune object. "
97
- "Please specify an `output` file name."
98
- )
99
-
100
- if step > 0:
101
- remote_name += f"-checkpoint-{step}"
102
-
103
- if "x-tar" in content_type.lower():
104
- remote_name += ".tar.gz"
105
-
106
- else:
107
- remote_name += ".tar.zst"
108
-
109
- return Path(remote_name)
110
-
111
-
112
- class DownloadManager:
113
- def __init__(self, client: TogetherClient) -> None:
114
- self._client = client
115
-
116
- def get_file_metadata(
117
- self,
118
- url: str,
119
- output: Path | None = None,
120
- remote_name: str | None = None,
121
- fetch_metadata: bool = False,
122
- ) -> Tuple[Path, int]:
123
- """
124
- gets remote file head and parses out file name and file size
125
- """
126
-
127
- if not fetch_metadata:
128
- if isinstance(output, Path):
129
- file_path = output
130
- else:
131
- assert isinstance(remote_name, str)
132
- file_path = Path(remote_name)
133
-
134
- return file_path, 0
135
-
136
- requestor = api_requestor.APIRequestor(
137
- client=self._client,
138
- )
139
-
140
- response = requestor.request_raw(
141
- options=TogetherRequest(
142
- method="GET",
143
- url=url,
144
- headers={"Range": "bytes=0-1"},
145
- ),
146
- remaining_retries=MAX_RETRIES,
147
- stream=False,
148
- )
149
-
150
- try:
151
- response.raise_for_status()
152
- except requests.exceptions.HTTPError as e:
153
- raise APIError(
154
- "Error fetching file metadata", http_status=response.status_code
155
- ) from e
156
-
157
- headers = response.headers
158
-
159
- assert isinstance(headers, CaseInsensitiveDict)
160
-
161
- file_path = _prepare_output(
162
- headers=headers,
163
- output=output,
164
- remote_name=remote_name,
165
- )
166
-
167
- file_size = _get_file_size(headers)
168
-
169
- return file_path, file_size
170
-
171
- def download(
172
- self,
173
- url: str,
174
- output: Path | None = None,
175
- remote_name: str | None = None,
176
- fetch_metadata: bool = False,
177
- ) -> Tuple[str, int]:
178
- requestor = api_requestor.APIRequestor(
179
- client=self._client,
180
- )
181
-
182
- # pre-fetch remote file name and file size
183
- file_path, file_size = self.get_file_metadata(
184
- url, output, remote_name, fetch_metadata
185
- )
186
-
187
- temp_file_manager = partial(
188
- tempfile.NamedTemporaryFile, mode="wb", dir=file_path.parent, delete=False
189
- )
190
-
191
- # Prevent parallel downloads of the same file with a lock.
192
- lock_path = Path(file_path.as_posix() + ".lock")
193
-
194
- with FileLock(lock_path.as_posix()):
195
- with temp_file_manager() as temp_file:
196
- response = requestor.request_raw(
197
- options=TogetherRequest(
198
- method="GET",
199
- url=url,
200
- ),
201
- remaining_retries=MAX_RETRIES,
202
- stream=True,
203
- )
204
-
205
- try:
206
- response.raise_for_status()
207
- except Exception as e:
208
- os.remove(lock_path)
209
- raise APIError(
210
- "Error downloading file", http_status=response.status_code
211
- ) from e
212
-
213
- if not fetch_metadata:
214
- file_size = int(response.headers.get("content-length", 0))
215
-
216
- assert file_size != 0, "Unable to retrieve remote file."
217
-
218
- with tqdm(
219
- total=file_size,
220
- unit="B",
221
- unit_scale=True,
222
- desc=f"Downloading file {file_path.name}",
223
- disable=bool(DISABLE_TQDM),
224
- ) as pbar:
225
- for chunk in response.iter_content(DOWNLOAD_BLOCK_SIZE):
226
- pbar.update(len(chunk))
227
- temp_file.write(chunk)
228
-
229
- # Raise exception if remote file size does not match downloaded file size
230
- if os.stat(temp_file.name).st_size != file_size:
231
- DownloadError(
232
- f"Downloaded file size `{pbar.n}` bytes does not match "
233
- f"remote file size `{file_size}` bytes."
234
- )
235
-
236
- # Moves temp file to output file path
237
- chmod_and_replace(Path(temp_file.name), file_path)
238
-
239
- os.remove(lock_path)
240
-
241
- return str(file_path.resolve()), file_size
242
-
243
-
244
- class UploadManager:
245
- def __init__(self, client: TogetherClient) -> None:
246
- self._client = client
247
-
248
- @classmethod
249
- def _redirect_error_handler(
250
- cls, requestor: api_requestor.APIRequestor, response: requests.Response
251
- ) -> None:
252
- if response.status_code == 401:
253
- raise AuthenticationError(
254
- "This job would exceed your free trial credits. "
255
- "Please upgrade to a paid account through "
256
- "Settings -> Billing on api.together.ai to continue.",
257
- )
258
- elif response.status_code != 302:
259
- raise APIError(
260
- f"Unexpected error raised by endpoint: {response.content.decode()}, headers: {response.headers}",
261
- http_status=response.status_code,
262
- )
263
-
264
- def get_upload_url(
265
- self,
266
- url: str,
267
- file: Path,
268
- purpose: FilePurpose,
269
- filetype: FileType,
270
- ) -> Tuple[str, str]:
271
- data = {
272
- "purpose": purpose.value,
273
- "file_name": file.name,
274
- "file_type": filetype.value,
275
- }
276
-
277
- requestor = api_requestor.APIRequestor(
278
- client=self._client,
279
- )
280
-
281
- method = "POST"
282
-
283
- headers = together.utils.get_headers(method, requestor.api_key)
284
-
285
- response = requestor.request_raw(
286
- options=TogetherRequest(
287
- method=method,
288
- url=url,
289
- params=data,
290
- allow_redirects=False,
291
- override_headers=True,
292
- headers=headers,
293
- ),
294
- remaining_retries=MAX_RETRIES,
295
- )
296
-
297
- self._redirect_error_handler(requestor, response)
298
-
299
- redirect_url = response.headers["Location"]
300
- file_id = response.headers["X-Together-File-Id"]
301
-
302
- return redirect_url, file_id
303
-
304
- def callback(self, url: str) -> TogetherResponse:
305
- requestor = api_requestor.APIRequestor(
306
- client=self._client,
307
- )
308
-
309
- response, _, _ = requestor.request(
310
- options=TogetherRequest(
311
- method="POST",
312
- url=url,
313
- ),
314
- )
315
-
316
- return response
317
-
318
- def upload(
319
- self,
320
- url: str,
321
- file: Path,
322
- purpose: FilePurpose,
323
- redirect: bool = False,
324
- ) -> FileResponse:
325
- file_id = None
326
-
327
- requestor = api_requestor.APIRequestor(
328
- client=self._client,
329
- )
330
-
331
- redirect_url = None
332
- if redirect:
333
- if file.suffix == ".jsonl":
334
- filetype = FileType.jsonl
335
- elif file.suffix == ".parquet":
336
- filetype = FileType.parquet
337
- else:
338
- raise FileTypeError(
339
- f"Unknown extension of file {file}. "
340
- "Only files with extensions .jsonl and .parquet are supported."
341
- )
342
- redirect_url, file_id = self.get_upload_url(url, file, purpose, filetype)
343
-
344
- file_size = os.stat(file.as_posix()).st_size
345
-
346
- with tqdm(
347
- total=file_size,
348
- unit="B",
349
- unit_scale=True,
350
- desc=f"Uploading file {file.name}",
351
- disable=bool(DISABLE_TQDM),
352
- ) as pbar:
353
- with file.open("rb") as f:
354
- wrapped_file = CallbackIOWrapper(pbar.update, f, "read")
355
-
356
- if redirect:
357
- callback_response = requestor.request_raw(
358
- options=TogetherRequest(
359
- method="PUT",
360
- url=redirect_url,
361
- params=wrapped_file,
362
- override_headers=True,
363
- ),
364
- absolute=True,
365
- remaining_retries=MAX_RETRIES,
366
- )
367
- else:
368
- response, _, _ = requestor.request(
369
- options=TogetherRequest(
370
- method="PUT",
371
- url=url,
372
- params=wrapped_file,
373
- ),
374
- )
375
-
376
- if redirect:
377
- assert isinstance(callback_response, requests.Response)
378
-
379
- if not callback_response.status_code == 200:
380
- raise APIError(
381
- f"Error during file upload: {callback_response.content.decode()}, headers: {callback_response.headers}",
382
- http_status=callback_response.status_code,
383
- )
384
-
385
- response = self.callback(f"{url}/{file_id}/preprocess")
386
-
387
- assert isinstance(response, TogetherResponse)
388
-
389
- return FileResponse(**response.data)
File without changes
together/legacy/base.py DELETED
@@ -1,27 +0,0 @@
1
- import functools
2
- import warnings
3
-
4
-
5
- API_KEY_WARNING = (
6
- "The use of together.api_key is deprecated and will be removed in the next major release. "
7
- "Please set the TOGETHER_API_KEY environment variable instead."
8
- )
9
-
10
-
11
- def deprecated(func): # type: ignore
12
- """
13
- This is a decorator which can be used to mark functions
14
- as deprecated. It will result in a warning being emitted
15
- when the function is used.
16
- """
17
-
18
- @functools.wraps(func)
19
- def new_func(*args, **kwargs): # type: ignore
20
- warnings.warn(
21
- f"Call to deprecated function {func.__name__}.",
22
- category=DeprecationWarning,
23
- stacklevel=2,
24
- )
25
- return func(*args, **kwargs)
26
-
27
- return new_func
@@ -1,93 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import warnings
4
- from typing import Any, AsyncGenerator, Dict, Iterator
5
-
6
- import together
7
- from together.legacy.base import API_KEY_WARNING, deprecated
8
- from together.types import CompletionChunk, CompletionResponse
9
-
10
-
11
- class Complete:
12
- @classmethod
13
- @deprecated # type: ignore
14
- def create(
15
- cls,
16
- prompt: str,
17
- **kwargs: Any,
18
- ) -> Dict[str, Any]:
19
- """Legacy completion function."""
20
-
21
- api_key = None
22
- if together.api_key:
23
- warnings.warn(API_KEY_WARNING)
24
- api_key = together.api_key
25
-
26
- client = together.Together(api_key=api_key)
27
-
28
- result = client.completions.create(prompt=prompt, stream=False, **kwargs)
29
-
30
- assert isinstance(result, CompletionResponse)
31
-
32
- return result.model_dump(exclude_none=True)
33
-
34
- @classmethod
35
- @deprecated # type: ignore
36
- def create_streaming(
37
- cls,
38
- prompt: str,
39
- **kwargs: Any,
40
- ) -> Iterator[Dict[str, Any]]:
41
- """Legacy streaming completion function."""
42
-
43
- api_key = None
44
- if together.api_key:
45
- warnings.warn(API_KEY_WARNING)
46
- api_key = together.api_key
47
-
48
- client = together.Together(api_key=api_key)
49
-
50
- return (
51
- token.model_dump(exclude_none=True) # type: ignore
52
- for token in client.completions.create(prompt=prompt, stream=True, **kwargs)
53
- )
54
-
55
-
56
- class Completion:
57
- @classmethod
58
- @deprecated # type: ignore
59
- def create(
60
- cls,
61
- prompt: str,
62
- **kwargs: Any,
63
- ) -> CompletionResponse | Iterator[CompletionChunk]:
64
- """Completion function."""
65
-
66
- api_key = None
67
- if together.api_key:
68
- warnings.warn(API_KEY_WARNING)
69
- api_key = together.api_key
70
-
71
- client = together.Together(api_key=api_key)
72
-
73
- return client.completions.create(prompt=prompt, **kwargs)
74
-
75
-
76
- class AsyncComplete:
77
- @classmethod
78
- @deprecated # type: ignore
79
- async def create(
80
- cls,
81
- prompt: str,
82
- **kwargs: Any,
83
- ) -> CompletionResponse | AsyncGenerator[CompletionChunk, None]:
84
- """Async completion function."""
85
-
86
- api_key = None
87
- if together.api_key:
88
- warnings.warn(API_KEY_WARNING)
89
- api_key = together.api_key
90
-
91
- client = together.AsyncTogether(api_key=api_key)
92
-
93
- return await client.completions.create(prompt=prompt, **kwargs)
@@ -1,27 +0,0 @@
1
- import warnings
2
- from typing import Any, Dict
3
-
4
- import together
5
- from together.legacy.base import API_KEY_WARNING, deprecated
6
-
7
-
8
- class Embeddings:
9
- @classmethod
10
- @deprecated # type: ignore
11
- def create(
12
- cls,
13
- input: str,
14
- **kwargs: Any,
15
- ) -> Dict[str, Any]:
16
- """Legacy embeddings function."""
17
-
18
- api_key = None
19
- if together.api_key:
20
- warnings.warn(API_KEY_WARNING)
21
- api_key = together.api_key
22
-
23
- client = together.Together(api_key=api_key)
24
-
25
- return client.embeddings.create(input=input, **kwargs).model_dump(
26
- exclude_none=True
27
- )
together/legacy/files.py DELETED
@@ -1,146 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import json
4
- import warnings
5
- from typing import Any, Dict, List
6
-
7
- import together
8
- from together.legacy.base import API_KEY_WARNING, deprecated
9
- from together.utils.files import check_file as check_json
10
-
11
-
12
- class Files:
13
- @classmethod
14
- @deprecated # type: ignore
15
- def list(
16
- cls,
17
- ) -> Dict[str, Any]:
18
- """Legacy file list function."""
19
-
20
- api_key = None
21
- if together.api_key:
22
- warnings.warn(API_KEY_WARNING)
23
- api_key = together.api_key
24
-
25
- client = together.Together(api_key=api_key)
26
-
27
- return client.files.list().model_dump(exclude_none=True)
28
-
29
- @classmethod
30
- def check(self, file: str) -> Dict[str, object]:
31
- return check_json(file)
32
-
33
- @classmethod
34
- @deprecated # type: ignore
35
- def upload(
36
- cls,
37
- file: str,
38
- check: bool = True,
39
- ) -> Dict[str, Any]:
40
- """Legacy file upload function."""
41
-
42
- api_key = None
43
- if together.api_key:
44
- warnings.warn(API_KEY_WARNING)
45
- api_key = together.api_key
46
-
47
- if check:
48
- report_dict = check_json(file)
49
- if not report_dict["is_check_passed"]:
50
- raise together.error.FileTypeError(
51
- f"Invalid file supplied. Failed to upload.\nReport:\n {report_dict}"
52
- )
53
-
54
- client = together.Together(api_key=api_key)
55
-
56
- # disabling the check, because it was run previously
57
- response = client.files.upload(file=file, check=False).model_dump(
58
- exclude_none=True
59
- )
60
-
61
- if check:
62
- response["report_dict"] = report_dict
63
-
64
- return response
65
-
66
- @classmethod
67
- @deprecated # type: ignore
68
- def delete(
69
- cls,
70
- file_id: str,
71
- ) -> Dict[str, Any]:
72
- """Legacy file delete function."""
73
-
74
- api_key = None
75
- if together.api_key:
76
- warnings.warn(API_KEY_WARNING)
77
- api_key = together.api_key
78
-
79
- client = together.Together(api_key=api_key)
80
-
81
- return client.files.delete(id=file_id).model_dump(exclude_none=True)
82
-
83
- @classmethod
84
- @deprecated # type: ignore
85
- def retrieve(
86
- cls,
87
- file_id: str,
88
- ) -> Dict[str, Any]:
89
- """Legacy file retrieve function."""
90
-
91
- api_key = None
92
- if together.api_key:
93
- warnings.warn(API_KEY_WARNING)
94
- api_key = together.api_key
95
-
96
- client = together.Together(api_key=api_key)
97
-
98
- return client.files.retrieve(id=file_id).model_dump(exclude_none=True)
99
-
100
- @classmethod
101
- @deprecated # type: ignore
102
- def retrieve_content(
103
- cls,
104
- file_id: str,
105
- output: str | None = None,
106
- ) -> Dict[str, Any]:
107
- """Legacy file retrieve content function."""
108
-
109
- api_key = None
110
- if together.api_key:
111
- warnings.warn(API_KEY_WARNING)
112
- api_key = together.api_key
113
-
114
- client = together.Together(api_key=api_key)
115
-
116
- return client.files.retrieve_content(id=file_id, output=output).dict(
117
- exclude_none=True
118
- )
119
-
120
- @classmethod
121
- @deprecated # type: ignore
122
- def save_jsonl(
123
- self, data: Dict[str, str], output_path: str, append: bool = False
124
- ) -> None:
125
- """
126
- Write list of objects to a JSON lines file.
127
- """
128
- mode = "a+" if append else "w"
129
- with open(output_path, mode, encoding="utf-8") as f:
130
- for line in data:
131
- json_record = json.dumps(line, ensure_ascii=False)
132
- f.write(json_record + "\n")
133
- print("Wrote {} records to {}".format(len(data), output_path))
134
-
135
- @classmethod
136
- @deprecated # type: ignore
137
- def load_jsonl(self, input_path: str) -> List[Dict[str, str]]:
138
- """
139
- Read list of objects from a JSON lines file.
140
- """
141
- data = []
142
- with open(input_path, "r", encoding="utf-8") as f:
143
- for line in f:
144
- data.append(json.loads(line.rstrip("\n|\r")))
145
- print("Loaded {} records from {}".format(len(data), input_path))
146
- return data