44# Copyright (c) 2024 Oracle and/or its affiliates.
55# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
66import os
7- import sys
87
98from ads .aqua import (
109 ENV_VAR_LOG_LEVEL ,
11- set_log_level ,
1210 ODSC_MODEL_COMPARTMENT_OCID ,
1311 logger ,
12+ set_log_level ,
1413)
15- from ads .aqua .deployment import AquaDeploymentApp
14+ from ads .aqua .common . errors import AquaCLIError , AquaConfigError
1615from ads .aqua .evaluation import AquaEvaluationApp
17- from ads .aqua .finetune import AquaFineTuningApp
16+ from ads .aqua .finetuning import AquaFineTuningApp
1817from ads .aqua .model import AquaModelApp
19- from ads .config import NB_SESSION_OCID
18+ from ads .aqua . modeldeployment import AquaDeploymentApp
2019from ads .common .utils import LOG_LEVELS
20+ from ads .config import NB_SESSION_OCID
2121
2222
2323class AquaCommand :
@@ -35,6 +35,8 @@ class AquaCommand:
3535
3636 def __init__ (
3737 self ,
38+ debug : bool = None ,
39+ verbose : bool = None ,
3840 log_level : str = os .environ .get (ENV_VAR_LOG_LEVEL , "ERROR" ).upper (),
3941 ):
4042 """
@@ -44,24 +46,64 @@ def __init__(
4446 -----
4547 log_level (str):
4648 Sets the logging level for the application.
47- Default is retrieved from environment variable `LOG_LEVEL `,
49+ Default is retrieved from environment variable `ADS_AQUA_LOG_LEVEL `,
4850 or 'ERROR' if not set. Example values include 'DEBUG', 'INFO',
4951 'WARNING', 'ERROR', and 'CRITICAL'.
52+ debug (bool):
53+ Sets the logging level for the application to `DEBUG`.
54+ verbose (bool):
55+ Sets the logging level for the application to `INFO`.
56+
57+ Raises
58+ ------
59+ AquaCLIError:
60+ When `--verbose` and `--debug` being used together.
61+ When missing required `ODSC_MODEL_COMPARTMENT_OCID` env var.
5062 """
51- if log_level .upper () not in LOG_LEVELS :
52- logger .error (
53- f"Log level should be one of { LOG_LEVELS } . Setting default to ERROR."
63+ if verbose is not None and debug is not None :
64+ raise AquaCLIError (
65+ "Cannot use `--debug` and `--verbose` at the same time. "
66+ "Please select either `--debug` for `DEBUG` level logging or "
67+ "`--verbose` for `INFO` level logging."
5468 )
55- log_level = "ERROR"
56- set_log_level (log_level )
57- # gracefully exit if env var is not set
69+ elif verbose is not None :
70+ self ._validate_value ("--verbose" , verbose )
71+ aqua_log_level = "INFO"
72+ elif debug is not None :
73+ self ._validate_value ("--debug" , debug )
74+ aqua_log_level = "DEBUG"
75+ else :
76+ if log_level .upper () not in LOG_LEVELS :
77+ logger .warning (
78+ f"Log level should be one of { LOG_LEVELS } . Setting default to ERROR."
79+ )
80+ log_level = "ERROR"
81+ aqua_log_level = log_level .upper ()
82+
83+ set_log_level (aqua_log_level )
84+
5885 if not ODSC_MODEL_COMPARTMENT_OCID :
59- logger .debug (
60- "ODSC_MODEL_COMPARTMENT_OCID environment variable is not set for Aqua."
61- )
6286 if NB_SESSION_OCID :
63- logger . error (
87+ raise AquaConfigError (
6488 f"Aqua is not available for the notebook session { NB_SESSION_OCID } . For more information, "
6589 f"please refer to the documentation."
6690 )
67- sys .exit (1 )
91+ raise AquaConfigError (
92+ "ODSC_MODEL_COMPARTMENT_OCID environment variable is not set for Aqua."
93+ )
94+
95+ @staticmethod
96+ def _validate_value (flag , value ):
97+ """Check if the given value for bool flag is valid.
98+
99+ Raises
100+ ------
101+ AquaCLIError:
102+ When the given value for bool flag is invalid.
103+ """
104+ if value not in [True , False ]:
105+ raise AquaCLIError (
106+ f"Invalid input `{ value } ` for flag: { flag } , a boolean value is required. "
107+ "If you intend to chain a function call to the result, please separate the "
108+ "flag and the subsequent function call with separator `-`."
109+ )
0 commit comments