Skip to content

Commit 8d2a18b

Browse files
authored
chore: Add example usage for file commands (#359)
1 parent 1316203 commit 8d2a18b

4 files changed

Lines changed: 53 additions & 19 deletions

File tree

src/together/lib/cli/__init__.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,20 @@
2828
from together.lib.cli.utils._completion import install_completion
2929
from together.lib.cli.utils._help_examples import (
3030
EVALS_HELP_EXAMPLES,
31+
FILES_HELP_EXAMPLES,
3132
MODELS_HELP_EXAMPLES,
3233
ENDPOINTS_HELP_EXAMPLES,
3334
TOP_LEVEL_HELP_EXAMPLES,
3435
FINE_TUNING_HELP_EXAMPLES,
3536
EVALS_CREATE_HELP_EXAMPLES,
37+
FILES_UPLOAD_HELP_EXAMPLES,
3638
MODELS_UPLOAD_HELP_EXAMPLES,
3739
ENDPOINTS_CREATE_HELP_EXAMPLES,
3840
ENDPOINTS_UPDATE_HELP_EXAMPLES,
3941
ENDPOINTS_HARDWARE_HELP_EXAMPLES,
4042
FINE_TUNING_CREATE_HELP_EXAMPLES,
4143
FINE_TUNING_DOWNLOAD_HELP_EXAMPLES,
44+
FILES_RETRIEVE_CONTENT_HELP_EXAMPLES,
4245
)
4346
from together.lib.cli.utils._help_formatter import help_formatter
4447
from together.lib.cli.utils._preparse_tokens import preparse_tokens
@@ -308,11 +311,21 @@ async def run_command() -> None:
308311
_CLI = "together.lib.cli.api"
309312

310313
## Files API commands
311-
files_app = app.command(App(name="files", help="Upload and manage files"))
312-
files_app.command(f"{_CLI}.files.upload:upload", help="Upload a file for fine-tuning, evals, or inference")
314+
files_app = app.command(App(name="files", help="Upload and manage files", help_epilogue=FILES_HELP_EXAMPLES))
315+
files_app.command(
316+
f"{_CLI}.files.upload:upload",
317+
help="Upload a file for fine-tuning, evals, or inference",
318+
help_epilogue=FILES_UPLOAD_HELP_EXAMPLES,
319+
)
313320
files_app.command(f"{_CLI}.files.list:list", alias="ls", help="List your files")
314321
files_app.command(f"{_CLI}.files.retrieve:retrieve", help="Get file details")
315-
files_app.command(f"{_CLI}.files.retrieve_content:retrieve_content", help="Download file contents")
322+
files_app.command(f"{_CLI}.files.retrieve_content:retrieve_content", help="Download file contents", show=False)
323+
files_app.command(
324+
f"{_CLI}.files.retrieve_content:retrieve_content",
325+
name="download",
326+
help="Download file contents",
327+
help_epilogue=FILES_RETRIEVE_CONTENT_HELP_EXAMPLES,
328+
)
316329
files_app.command(f"{_CLI}.files.delete:delete", alias="-d", help="Delete a file")
317330
files_app.command(f"{_CLI}.files.check:check", help="Check a local file for issues")
318331

src/together/lib/cli/api/files/upload.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
async def upload(
2020
file: Annotated[Path, Parameter(required=True, help="The file to upload")],
2121
purpose: Annotated[Optional[FilePurpose], Parameter(help="The purpose of the file")] = "fine-tune",
22-
check: Annotated[Optional[bool], Parameter(help="Whether to check the file")] = True,
22+
no_check: Annotated[Optional[bool], Parameter(negative=(), help="Skip checking the file for issues")] = False,
2323
*,
2424
config: CLIConfigParameter,
2525
) -> None:
@@ -28,7 +28,7 @@ async def upload(
2828
os.environ.setdefault("TOGETHER_DISABLE_TQDM", "true")
2929

3030
# Manually handle check here so we can exit and provide the user good error messages
31-
if check:
31+
if not no_check:
3232
report = check_file(file)
3333
if report["is_check_passed"] is False:
3434
if config.json:

src/together/lib/cli/utils/_help_examples.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,41 @@
1111
[primary]tg models upload --model-name my-org/my-model --model-source s3-or-hugging-face[/primary]
1212
"""
1313

14+
## Files API commands
15+
16+
FILES_HELP_EXAMPLES = """[dim]Examples:[/dim]
17+
[dim]-[/dim] Upload a file for fine-tuning:
18+
[primary]tg files upload ./my-dataset.jsonl --purpose fine-tune[/primary]
19+
20+
[dim]-[/dim] Check a local file for issues:
21+
[primary]tg files check ./my-dataset.jsonl[/primary]
22+
23+
[dim]-[/dim] Remove a file from Together:
24+
[primary]tg files delete <file-id>[/primary]
25+
26+
[dim]-[/dim] Download a file:
27+
[primary]tg files download <file-id> --output ./datasets[/primary]
28+
"""
29+
30+
FILES_UPLOAD_HELP_EXAMPLES = """[dim]Examples:[/dim]
31+
[dim]-[/dim] Upload a file for fine-tuning:
32+
[primary]tg files upload ./my-dataset.jsonl --purpose fine-tune[/primary]
33+
34+
[dim]-[/dim] Upload a file for evals:
35+
[primary]tg files upload ./my-dataset.jsonl --purpose evals[/primary]
36+
37+
[dim]-[/dim] Skip file checks:
38+
[primary]tg files upload ./my-dataset.jsonl --no-check[/primary]
39+
"""
40+
41+
FILES_RETRIEVE_CONTENT_HELP_EXAMPLES = """[dim]Examples:[/dim]
42+
[dim]-[/dim] Download a file:
43+
[primary]tg files download <file-id> --output ./datasets[/primary]
44+
45+
[dim]-[/dim] Print file contents to stdout:
46+
[primary]tg files download <file-id> --stdout[/primary]
47+
"""
48+
1449
## Models API commands
1550
MODELS_HELP_EXAMPLES = """[dim]Examples:[/dim]
1651
[dim]-[/dim] List all models:

tests/cli/test_files.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,3 @@ def test_upload_does_not_check_if_disabled(self, tmp_path: Path, cli_runner: Cli
197197
call_kw = upload_mock.call_args.kwargs
198198
assert call_kw["check"] is False
199199
assert "uploaded-id" in result.output
200-
201-
def test_upload_does_check_if_enabled(self, tmp_path: Path, cli_runner: CliRunner) -> None:
202-
f = tmp_path / "data.jsonl"
203-
f.write_text("{}\n")
204-
uploaded = _file_response()
205-
with patch.object(_files_upload_cli, "check_file") as check_mock, patch(
206-
"together.resources.files.AsyncFilesResource.upload", new_callable=AsyncMock
207-
) as upload_mock:
208-
upload_mock.return_value = uploaded
209-
check_mock.return_value = {"is_check_passed": True, "message": "Checks passed"}
210-
result = cli_runner.invoke(["files", "upload", str(f), "--check"])
211-
assert result.exit_code == 0
212-
check_mock.assert_called_once()
213-
upload_mock.assert_called_once()

0 commit comments

Comments
 (0)