99
1010import vec_inf .client ._utils as utils
1111from vec_inf .cli ._helper import (
12- CLIMetricsCollector ,
13- CLIModelLauncher ,
14- CLIModelRegistry ,
15- CLIModelStatusMonitor ,
12+ LaunchResponseFormatter ,
13+ ListCmdDisplay ,
14+ MetricsResponseFormatter ,
15+ StatusResponseFormatter ,
1616)
17+ from vec_inf .client ._models import LaunchOptions
18+ from vec_inf .client .api import VecInfClient
1719
1820
1921CONSOLE = Console ()
@@ -131,14 +133,19 @@ def launch(
131133) -> None :
132134 """Launch a model on the cluster."""
133135 try :
134- model_launcher = CLIModelLauncher (model_name , cli_kwargs )
135- # Launch model inference server
136- model_launcher .launch ()
136+ # Convert cli_kwargs to LaunchOptions
137+ launch_options = LaunchOptions (** {k : v for k , v in cli_kwargs .items () if k != "json_mode" })
138+
139+ # Start the client and launch model inference server
140+ client = VecInfClient ()
141+ launch_response = client .launch_model (model_name , launch_options )
142+
137143 # Display launch information
144+ launch_formatter = LaunchResponseFormatter (model_name , launch_response .config )
138145 if cli_kwargs .get ("json_mode" ):
139- click .echo (model_launcher . params )
146+ click .echo (launch_response . config )
140147 else :
141- launch_info_table = model_launcher .format_table_output ()
148+ launch_info_table = launch_formatter .format_table_output ()
142149 CONSOLE .print (launch_info_table )
143150
144151 except click .ClickException as e :
@@ -164,14 +171,16 @@ def status(
164171) -> None :
165172 """Get the status of a running model on the cluster."""
166173 try :
167- # Get model inference server status
168- model_status_monitor = CLIModelStatusMonitor ( slurm_job_id , log_dir )
169- model_status_monitor . process_model_status ( )
174+ # Start the client and get model inference server status
175+ client = VecInfClient ( )
176+ status_response = client . get_status ( slurm_job_id , log_dir )
170177 # Display status information
178+ status_formatter = StatusResponseFormatter (status_response )
171179 if json_mode :
172- model_status_monitor .output_json ()
180+ status_formatter .output_json ()
173181 else :
174- model_status_monitor .output_table (CONSOLE )
182+ status_info_table = status_formatter .output_table ()
183+ CONSOLE .print (status_info_table )
175184
176185 except click .ClickException as e :
177186 raise e
@@ -197,8 +206,15 @@ def shutdown(slurm_job_id: int) -> None:
197206def list_models (model_name : Optional [str ] = None , json_mode : bool = False ) -> None :
198207 """List all available models, or get default setup of a specific model."""
199208 try :
200- model_registry = CLIModelRegistry (json_mode )
201- model_registry .process_list_command (CONSOLE , model_name )
209+ # Start the client
210+ client = VecInfClient ()
211+ list_display = ListCmdDisplay (CONSOLE , json_mode )
212+ if model_name :
213+ model_config = client .get_model_config (model_name )
214+ list_display .display_single_model_output (model_config )
215+ else :
216+ model_infos = client .list_models ()
217+ list_display .display_all_models_output (model_infos )
202218 except click .ClickException as e :
203219 raise e
204220 except Exception as e :
@@ -213,30 +229,29 @@ def list_models(model_name: Optional[str] = None, json_mode: bool = False) -> No
213229def metrics (slurm_job_id : int , log_dir : Optional [str ] = None ) -> None :
214230 """Stream real-time performance metrics from the model endpoint."""
215231 try :
216- metrics_collector = CLIMetricsCollector (slurm_job_id , log_dir )
217-
218- # Check if metrics URL is ready
219- if not metrics_collector .metrics_url .startswith ("http" ):
220- table = utils .create_table ("Metric" , "Value" )
221- metrics_collector .display_failed_metrics (
222- table ,
223- f"Metrics endpoint unavailable or server not ready - { metrics_collector .metrics_url } " ,
224- )
225- CONSOLE .print (table )
232+ # Start the client and get inference server metrics
233+ client = VecInfClient ()
234+ metrics_response = client .get_metrics (slurm_job_id , log_dir )
235+ metrics_formatter = MetricsResponseFormatter (metrics_response .metrics )
236+
237+ # Check if metrics response is ready
238+ if isinstance (metrics_response .metrics , str ):
239+ metrics_formatter .format_failed_metrics (metrics_response .metrics )
240+ CONSOLE .print (metrics_formatter .table )
226241 return
227242
228243 with Live (refresh_per_second = 1 , console = CONSOLE ) as live :
229244 while True :
230- metrics = metrics_collector . fetch_metrics ( )
231- table = utils . create_table ( "Metric" , "Value" )
245+ metrics_response = client . get_metrics ( slurm_job_id , log_dir )
246+ metrics_formatter = MetricsResponseFormatter ( metrics_response . metrics )
232247
233- if isinstance (metrics , str ):
248+ if isinstance (metrics_response . metrics , str ):
234249 # Show status information if metrics aren't available
235- metrics_collector . display_failed_metrics ( table , metrics )
250+ metrics_formatter . format_failed_metrics ( metrics_response . metrics )
236251 else :
237- metrics_collector . display_metrics ( table , metrics )
252+ metrics_formatter . format_metrics ( )
238253
239- live .update (table )
254+ live .update (metrics_formatter . table )
240255 time .sleep (2 )
241256 except click .ClickException as e :
242257 raise e
0 commit comments