4
4
# Copyright (c) 2024 Oracle and/or its affiliates.
5
5
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
6
6
import os
7
- import sys
8
7
9
8
from ads .aqua import (
10
9
ENV_VAR_LOG_LEVEL ,
11
- set_log_level ,
12
10
ODSC_MODEL_COMPARTMENT_OCID ,
13
11
logger ,
12
+ set_log_level ,
14
13
)
15
- from ads .aqua .deployment import AquaDeploymentApp
14
+ from ads .aqua .common . errors import AquaCLIError , AquaConfigError
16
15
from ads .aqua .evaluation import AquaEvaluationApp
17
- from ads .aqua .finetune import AquaFineTuningApp
16
+ from ads .aqua .finetuning import AquaFineTuningApp
18
17
from ads .aqua .model import AquaModelApp
19
- from ads .config import NB_SESSION_OCID
18
+ from ads .aqua . modeldeployment import AquaDeploymentApp
20
19
from ads .common .utils import LOG_LEVELS
20
+ from ads .config import NB_SESSION_OCID
21
21
22
22
23
23
class AquaCommand :
@@ -35,6 +35,8 @@ class AquaCommand:
35
35
36
36
def __init__ (
37
37
self ,
38
+ debug : bool = None ,
39
+ verbose : bool = None ,
38
40
log_level : str = os .environ .get (ENV_VAR_LOG_LEVEL , "ERROR" ).upper (),
39
41
):
40
42
"""
@@ -44,24 +46,64 @@ def __init__(
44
46
-----
45
47
log_level (str):
46
48
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 `,
48
50
or 'ERROR' if not set. Example values include 'DEBUG', 'INFO',
49
51
'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.
50
62
"""
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."
54
68
)
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
+
58
85
if not ODSC_MODEL_COMPARTMENT_OCID :
59
- logger .debug (
60
- "ODSC_MODEL_COMPARTMENT_OCID environment variable is not set for Aqua."
61
- )
62
86
if NB_SESSION_OCID :
63
- logger . error (
87
+ raise AquaConfigError (
64
88
f"Aqua is not available for the notebook session { NB_SESSION_OCID } . For more information, "
65
89
f"please refer to the documentation."
66
90
)
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