@@ -410,6 +410,75 @@ def get_conversation_summary(self) -> dict[str, Any]:
410410 }
411411
412412
413+ def run_health_check (
414+ base_url : str ,
415+ auth_token : str ,
416+ model : str ,
417+ debug : bool = False ,
418+ system_prompt : str | None = None ,
419+ context_window_size : int | None = None ,
420+ ) -> tuple [bool , str ]:
421+ """
422+ Run a health check by sending 'hello' and waiting for a response.
423+
424+ Args:
425+ base_url: Base URL of the deployed API
426+ auth_token: Authentication token
427+ model: Model name to use
428+ debug: Show debug and info log messages if True
429+ system_prompt: Optional system prompt for conversation context
430+ context_window_size: Optional context window size (defaults to 2048 if not provided)
431+
432+ Returns:
433+ Tuple of (success: bool, message: str)
434+ """
435+ # Configure logging level based on debug flag
436+ if not debug :
437+ logging .getLogger ("merle" ).setLevel (logging .WARNING )
438+ logging .getLogger ("httpx" ).setLevel (logging .WARNING )
439+ else :
440+ logging .getLogger ("merle" ).setLevel (logging .INFO )
441+ logging .getLogger ("httpx" ).setLevel (logging .INFO )
442+
443+ if context_window_size is None :
444+ context_window_size = 2048
445+
446+ client = ChatClient (
447+ base_url , auth_token , model , system_prompt = system_prompt , context_window_size = context_window_size
448+ )
449+
450+ print (f"Testing connection to { model } at { base_url } ..." )
451+ print ("Sending: hello" )
452+ print ("-" * 40 )
453+
454+ try :
455+ response = client .chat ("hello" , prompt = "Response: " )
456+ print () # Newline after response
457+ print ("-" * 40 )
458+
459+ if response :
460+ print ("Status: OK" )
461+ return True , response
462+ except httpx .HTTPStatusError as e :
463+ print (f"\n Status: FAILED (HTTP { e .response .status_code } )" )
464+ return False , f"HTTP error { e .response .status_code } "
465+ except httpx .ConnectError as e :
466+ print ("\n Status: FAILED (connection error)" )
467+ logger .debug (f"Connection error details: { e } " )
468+ return False , f"Connection error: { e } "
469+ except httpx .TimeoutException as e :
470+ print ("\n Status: FAILED (timeout)" )
471+ logger .debug (f"Timeout details: { e } " )
472+ return False , f"Timeout: { e } "
473+ except Exception as e :
474+ print (f"\n Status: FAILED ({ type (e ).__name__ } )" )
475+ logger .exception (f"Health check error: { e } " )
476+ return False , str (e )
477+ else :
478+ print ("Status: FAILED (empty response)" )
479+ return False , "Empty response received"
480+
481+
413482def run_interactive_chat ( # noqa: PLR0915, PLR0912, C901
414483 base_url : str ,
415484 auth_token : str ,
0 commit comments