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 , get_logger , parse_timestamp
12+
13+
14+ logger = get_logger (str (__name__ ))
1115
1216
1317def add_parser (subparsers : argparse ._SubParsersAction [argparse .ArgumentParser ]) -> None :
@@ -24,7 +28,6 @@ def add_parser(subparsers: argparse._SubParsersAction[argparse.ArgumentParser])
2428 _add_download (child_parsers )
2529 _add_status (child_parsers )
2630 _add_checkpoints (child_parsers )
27- # _add_delete_model(child_parsers)
2831
2932
3033def _add_create (parser : argparse ._SubParsersAction [argparse .ArgumentParser ]) -> None :
@@ -252,25 +255,32 @@ def _run_create(args: argparse.Namespace) -> None:
252255 args .batch_size = 144
253256 else :
254257 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- )
258+ try :
259+ response = finetune .create (
260+ training_file = args .training_file , # training file_id
261+ model = args .model ,
262+ n_epochs = args .n_epochs ,
263+ n_checkpoints = args .n_checkpoints ,
264+ batch_size = args .batch_size ,
265+ learning_rate = args .learning_rate ,
266+ suffix = args .suffix ,
267+ estimate_price = args .estimate_price ,
268+ wandb_api_key = args .wandb_api_key if not args .no_wandb_api_key else None ,
269+ confirm_inputs = not args .quiet ,
270+ )
271+ except together .AuthenticationError :
272+ logger .critical (together .MISSING_API_KEY_MESSAGE )
273+ exit (0 )
268274
269275 print (json .dumps (response , indent = 4 ))
270276
271277
272278def _run_list (args : argparse .Namespace ) -> None :
273- response = Finetune .list ()
279+ try :
280+ response = Finetune .list ()
281+ except together .AuthenticationError :
282+ logger .critical (together .MISSING_API_KEY_MESSAGE )
283+ exit (0 )
274284 response ["data" ].sort (key = lambda x : parse_timestamp (x ["created_at" ]))
275285 if args .raw :
276286 print (json .dumps (response , indent = 4 ))
@@ -293,7 +303,11 @@ def _run_list(args: argparse.Namespace) -> None:
293303
294304
295305def _run_retrieve (args : argparse .Namespace ) -> None :
296- response = Finetune .retrieve (args .fine_tune_id )
306+ try :
307+ response = Finetune .retrieve (args .fine_tune_id )
308+ except together .AuthenticationError :
309+ logger .critical (together .MISSING_API_KEY_MESSAGE )
310+ exit (0 )
297311 if args .raw :
298312 print (json .dumps (response , indent = 4 ))
299313 else :
@@ -307,12 +321,20 @@ def _run_retrieve(args: argparse.Namespace) -> None:
307321
308322
309323def _run_cancel (args : argparse .Namespace ) -> None :
310- response = Finetune .cancel (args .fine_tune_id )
324+ try :
325+ response = Finetune .cancel (args .fine_tune_id )
326+ except together .AuthenticationError :
327+ logger .critical (together .MISSING_API_KEY_MESSAGE )
328+ exit (0 )
311329 print (json .dumps (response , indent = 4 ))
312330
313331
314332def _run_list_events (args : argparse .Namespace ) -> None :
315- response = Finetune .list_events (args .fine_tune_id )
333+ try :
334+ response = Finetune .list_events (args .fine_tune_id )
335+ except together .AuthenticationError :
336+ logger .critical (together .MISSING_API_KEY_MESSAGE )
337+ exit (0 )
316338 if args .raw :
317339 print (json .dumps (response , indent = 4 ))
318340 else :
@@ -330,16 +352,30 @@ def _run_list_events(args: argparse.Namespace) -> None:
330352
331353
332354def _run_download (args : argparse .Namespace ) -> None :
333- response = Finetune .download (args .fine_tune_id , args .output , args .checkpoint_step )
355+ try :
356+ response = Finetune .download (
357+ args .fine_tune_id , args .output , args .checkpoint_step
358+ )
359+ except together .AuthenticationError :
360+ logger .critical (together .MISSING_API_KEY_MESSAGE )
361+ exit (0 )
334362 print (response )
335363
336364
337365def _run_status (args : argparse .Namespace ) -> None :
338- response = Finetune .get_job_status (args .fine_tune_id )
366+ try :
367+ response = Finetune .get_job_status (args .fine_tune_id )
368+ except together .AuthenticationError :
369+ logger .critical (together .MISSING_API_KEY_MESSAGE )
370+ exit (0 )
339371 print (response )
340372
341373
342374def _run_checkpoint (args : argparse .Namespace ) -> None :
343- checkpoints = Finetune .get_checkpoints (args .fine_tune_id )
375+ try :
376+ checkpoints = Finetune .get_checkpoints (args .fine_tune_id )
377+ except together .AuthenticationError :
378+ logger .critical (together .MISSING_API_KEY_MESSAGE )
379+ exit (0 )
344380 print (json .dumps (checkpoints , indent = 4 ))
345381 print (f"\n { len (checkpoints )} checkpoints found" )
0 commit comments