66
77from tabulate import tabulate
88
9+ import together
910from together import Finetune
10- from together .utils import finetune_price_to_dollars , parse_timestamp
11+ from together .utils import finetune_price_to_dollars , parse_timestamp , get_logger
12+
13+ logger = get_logger (str (__name__ ))
1114
1215
1316def add_parser (subparsers : argparse ._SubParsersAction [argparse .ArgumentParser ]) -> None :
@@ -24,7 +27,6 @@ def add_parser(subparsers: argparse._SubParsersAction[argparse.ArgumentParser])
2427 _add_download (child_parsers )
2528 _add_status (child_parsers )
2629 _add_checkpoints (child_parsers )
27- # _add_delete_model(child_parsers)
2830
2931
3032def _add_create (parser : argparse ._SubParsersAction [argparse .ArgumentParser ]) -> None :
@@ -252,25 +254,32 @@ def _run_create(args: argparse.Namespace) -> None:
252254 args .batch_size = 144
253255 else :
254256 args .batch_size = 32
255-
256- response = finetune .create (
257- training_file = args .training_file , # training file_id
258- model = args .model ,
259- n_epochs = args .n_epochs ,
260- n_checkpoints = args .n_checkpoints ,
261- batch_size = args .batch_size ,
262- learning_rate = args .learning_rate ,
263- suffix = args .suffix ,
264- estimate_price = args .estimate_price ,
265- wandb_api_key = args .wandb_api_key if not args .no_wandb_api_key else None ,
266- confirm_inputs = not args .quiet ,
267- )
257+ try :
258+ response = finetune .create (
259+ training_file = args .training_file , # training file_id
260+ model = args .model ,
261+ n_epochs = args .n_epochs ,
262+ n_checkpoints = args .n_checkpoints ,
263+ batch_size = args .batch_size ,
264+ learning_rate = args .learning_rate ,
265+ suffix = args .suffix ,
266+ estimate_price = args .estimate_price ,
267+ wandb_api_key = args .wandb_api_key if not args .no_wandb_api_key else None ,
268+ confirm_inputs = not args .quiet ,
269+ )
270+ except together .AuthenticationError :
271+ logger .critical (together .MISSING_API_KEY_MESSAGE )
272+ exit (0 )
268273
269274 print (json .dumps (response , indent = 4 ))
270275
271276
272277def _run_list (args : argparse .Namespace ) -> None :
273- response = Finetune .list ()
278+ try :
279+ response = Finetune .list ()
280+ except together .AuthenticationError :
281+ logger .critical (together .MISSING_API_KEY_MESSAGE )
282+ exit (0 )
274283 response ["data" ].sort (key = lambda x : parse_timestamp (x ["created_at" ]))
275284 if args .raw :
276285 print (json .dumps (response , indent = 4 ))
@@ -293,7 +302,11 @@ def _run_list(args: argparse.Namespace) -> None:
293302
294303
295304def _run_retrieve (args : argparse .Namespace ) -> None :
296- response = Finetune .retrieve (args .fine_tune_id )
305+ try :
306+ response = Finetune .retrieve (args .fine_tune_id )
307+ except together .AuthenticationError :
308+ logger .critical (together .MISSING_API_KEY_MESSAGE )
309+ exit (0 )
297310 if args .raw :
298311 print (json .dumps (response , indent = 4 ))
299312 else :
@@ -307,12 +320,20 @@ def _run_retrieve(args: argparse.Namespace) -> None:
307320
308321
309322def _run_cancel (args : argparse .Namespace ) -> None :
310- response = Finetune .cancel (args .fine_tune_id )
323+ try :
324+ response = Finetune .cancel (args .fine_tune_id )
325+ except together .AuthenticationError :
326+ logger .critical (together .MISSING_API_KEY_MESSAGE )
327+ exit (0 )
311328 print (json .dumps (response , indent = 4 ))
312329
313330
314331def _run_list_events (args : argparse .Namespace ) -> None :
315- response = Finetune .list_events (args .fine_tune_id )
332+ try :
333+ response = Finetune .list_events (args .fine_tune_id )
334+ except together .AuthenticationError :
335+ logger .critical (together .MISSING_API_KEY_MESSAGE )
336+ exit (0 )
316337 if args .raw :
317338 print (json .dumps (response , indent = 4 ))
318339 else :
@@ -330,16 +351,28 @@ def _run_list_events(args: argparse.Namespace) -> None:
330351
331352
332353def _run_download (args : argparse .Namespace ) -> None :
333- response = Finetune .download (args .fine_tune_id , args .output , args .checkpoint_step )
354+ try :
355+ response = Finetune .download (args .fine_tune_id , args .output , args .checkpoint_step )
356+ except together .AuthenticationError :
357+ logger .critical (together .MISSING_API_KEY_MESSAGE )
358+ exit (0 )
334359 print (response )
335360
336361
337362def _run_status (args : argparse .Namespace ) -> None :
338- response = Finetune .get_job_status (args .fine_tune_id )
363+ try :
364+ response = Finetune .get_job_status (args .fine_tune_id )
365+ except together .AuthenticationError :
366+ logger .critical (together .MISSING_API_KEY_MESSAGE )
367+ exit (0 )
339368 print (response )
340369
341370
342371def _run_checkpoint (args : argparse .Namespace ) -> None :
343- checkpoints = Finetune .get_checkpoints (args .fine_tune_id )
372+ try :
373+ checkpoints = Finetune .get_checkpoints (args .fine_tune_id )
374+ except together .AuthenticationError :
375+ logger .critical (together .MISSING_API_KEY_MESSAGE )
376+ exit (0 )
344377 print (json .dumps (checkpoints , indent = 4 ))
345378 print (f"\n { len (checkpoints )} checkpoints found" )
0 commit comments