Skip to content

Commit 1659644

Browse files
authored
Check uploaded files by default (#132)
1 parent 941a30e commit 1659644

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ build-backend = "poetry.masonry.api"
1212

1313
[tool.poetry]
1414
name = "together"
15-
version = "1.1.5"
15+
version = "1.2.0"
1616
authors = [
1717
"Together AI <[email protected]>"
1818
]

src/together/cli/api/files.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,17 @@ def files(ctx: click.Context) -> None:
3232
default=FilePurpose.FineTune.value,
3333
help="Purpose of file upload. Acceptable values in enum `together.types.FilePurpose`. Defaults to `fine-tunes`.",
3434
)
35-
def upload(ctx: click.Context, file: pathlib.Path, purpose: str) -> None:
35+
@click.option(
36+
"--check/--no-check",
37+
default=True,
38+
help="Whether to check the file before uploading.",
39+
)
40+
def upload(ctx: click.Context, file: pathlib.Path, purpose: str, check: bool) -> None:
3641
"""Upload file"""
3742

3843
client: Together = ctx.obj
3944

40-
response = client.files.upload(file=file, purpose=purpose)
45+
response = client.files.upload(file=file, purpose=purpose, check=check)
4146

4247
click.echo(json.dumps(response.model_dump(), indent=4))
4348

src/together/error.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ def __init__(
2323
if isinstance(message, TogetherErrorResponse)
2424
else message
2525
)
26-
self._message = f"Error code: {http_status} - {_message}"
26+
if http_status is not None:
27+
self._message = f"Error code: {http_status} - {_message}"
28+
else:
29+
self._message = str(_message)
2730

28-
super(TogetherException, self).__init__(self._message)
31+
super().__init__(self._message)
2932

3033
self.http_status = http_status
3134
self.headers = headers or {}

src/together/legacy/files.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ def upload(
5353

5454
client = together.Together(api_key=api_key)
5555

56-
response = client.files.upload(file=file).model_dump()
56+
# disabling the check, because it was run previously
57+
response = client.files.upload(file=file, check=False).model_dump()
5758

58-
response["report_dict"] = report_dict
59+
if check:
60+
response["report_dict"] = report_dict
5961

6062
return response
6163

src/together/resources/files.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from __future__ import annotations
22

33
from pathlib import Path
4+
from pprint import pformat
45

56
from together.abstract import api_requestor
7+
from together.error import FileTypeError
68
from together.filemanager import DownloadManager, UploadManager
79
from together.together_response import TogetherResponse
810
from together.types import (
@@ -14,18 +16,29 @@
1416
TogetherClient,
1517
TogetherRequest,
1618
)
17-
from together.utils import normalize_key
19+
from together.utils import check_file, normalize_key
1820

1921

2022
class Files:
2123
def __init__(self, client: TogetherClient) -> None:
2224
self._client = client
2325

2426
def upload(
25-
self, file: Path | str, *, purpose: FilePurpose | str = FilePurpose.FineTune
27+
self,
28+
file: Path | str,
29+
*,
30+
purpose: FilePurpose | str = FilePurpose.FineTune,
31+
check: bool = True,
2632
) -> FileResponse:
2733
upload_manager = UploadManager(self._client)
2834

35+
if check:
36+
report_dict = check_file(file)
37+
if not report_dict["is_check_passed"]:
38+
raise FileTypeError(
39+
f"Invalid file supplied, failed to upload. Report:\n{pformat(report_dict)}"
40+
)
41+
2942
if isinstance(file, str):
3043
file = Path(file)
3144

0 commit comments

Comments
 (0)