Skip to content

Commit eced2af

Browse files
add fine-tuning job deletion (#363)
* add deletion
1 parent 8745e78 commit eced2af

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed

src/together/cli/api/finetune.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,3 +543,30 @@ def download(
543543
)
544544

545545
click.echo(json.dumps(response.model_dump(exclude_none=True), indent=4))
546+
547+
548+
@fine_tuning.command()
549+
@click.pass_context
550+
@click.argument("fine_tune_id", type=str, required=True)
551+
@click.option("--force", is_flag=True, help="Force deletion without confirmation")
552+
@click.option(
553+
"--quiet", is_flag=True, help="Do not prompt for confirmation before deleting job"
554+
)
555+
def delete(
556+
ctx: click.Context, fine_tune_id: str, force: bool = False, quiet: bool = False
557+
) -> None:
558+
"""Delete fine-tuning job"""
559+
client: Together = ctx.obj
560+
561+
if not quiet:
562+
confirm_response = input(
563+
f"Are you sure you want to delete fine-tuning job {fine_tune_id}? "
564+
"This action cannot be undone. [y/N] "
565+
)
566+
if confirm_response.lower() != "y":
567+
click.echo("Deletion cancelled")
568+
return
569+
570+
response = client.fine_tuning.delete(fine_tune_id, force=force)
571+
572+
click.echo(json.dumps(response.model_dump(exclude_none=True), indent=4))

src/together/resources/finetune.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
CosineLRScheduler,
1414
CosineLRSchedulerArgs,
1515
FinetuneCheckpoint,
16+
FinetuneDeleteResponse,
1617
FinetuneDownloadResult,
1718
FinetuneList,
1819
FinetuneListEvents,
@@ -570,6 +571,37 @@ def cancel(self, id: str) -> FinetuneResponse:
570571

571572
return FinetuneResponse(**response.data)
572573

574+
def delete(self, id: str, force: bool = False) -> FinetuneDeleteResponse:
575+
"""
576+
Method to delete a fine-tuning job
577+
578+
Args:
579+
id (str): Fine-tune ID to delete. A string that starts with `ft-`.
580+
force (bool, optional): Force deletion. Defaults to False.
581+
582+
Returns:
583+
FinetuneDeleteResponse: Object containing deletion confirmation message.
584+
"""
585+
586+
requestor = api_requestor.APIRequestor(
587+
client=self._client,
588+
)
589+
590+
params = {"force": str(force).lower()}
591+
592+
response, _, _ = requestor.request(
593+
options=TogetherRequest(
594+
method="DELETE",
595+
url=f"fine-tunes/{id}",
596+
params=params,
597+
),
598+
stream=False,
599+
)
600+
601+
assert isinstance(response, TogetherResponse)
602+
603+
return FinetuneDeleteResponse(**response.data)
604+
573605
def list_events(self, id: str) -> FinetuneListEvents:
574606
"""
575607
Lists events of a fine-tune job
@@ -1007,6 +1039,37 @@ async def cancel(self, id: str) -> FinetuneResponse:
10071039

10081040
return FinetuneResponse(**response.data)
10091041

1042+
async def delete(self, id: str, force: bool = False) -> FinetuneDeleteResponse:
1043+
"""
1044+
Async method to delete a fine-tuning job
1045+
1046+
Args:
1047+
id (str): Fine-tune ID to delete. A string that starts with `ft-`.
1048+
force (bool, optional): Force deletion. Defaults to False.
1049+
1050+
Returns:
1051+
FinetuneDeleteResponse: Object containing deletion confirmation message.
1052+
"""
1053+
1054+
requestor = api_requestor.APIRequestor(
1055+
client=self._client,
1056+
)
1057+
1058+
params = {"force": str(force).lower()}
1059+
1060+
response, _, _ = await requestor.arequest(
1061+
options=TogetherRequest(
1062+
method="DELETE",
1063+
url=f"fine-tunes/{id}",
1064+
params=params,
1065+
),
1066+
stream=False,
1067+
)
1068+
1069+
assert isinstance(response, TogetherResponse)
1070+
1071+
return FinetuneDeleteResponse(**response.data)
1072+
10101073
async def list_events(self, id: str) -> FinetuneListEvents:
10111074
"""
10121075
List fine-tuning events

src/together/types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
FinetuneListEvents,
5353
FinetuneRequest,
5454
FinetuneResponse,
55+
FinetuneDeleteResponse,
5556
FinetuneTrainingLimits,
5657
FullTrainingType,
5758
LoRATrainingType,
@@ -92,6 +93,7 @@
9293
"FinetuneResponse",
9394
"FinetuneList",
9495
"FinetuneListEvents",
96+
"FinetuneDeleteResponse",
9597
"FinetuneDownloadResult",
9698
"FinetuneLRScheduler",
9799
"LinearLRScheduler",

src/together/types/finetune.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ class FinetuneListEvents(BaseModel):
322322
data: List[FinetuneEvent] | None = None
323323

324324

325+
class FinetuneDeleteResponse(BaseModel):
326+
# delete message
327+
message: str
328+
329+
325330
class FinetuneDownloadResult(BaseModel):
326331
# object type
327332
object: Literal["local"] | None = None

0 commit comments

Comments
 (0)