-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathcli.py
96 lines (84 loc) · 3.28 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
# Copyright (c) 2024, 2025 Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
import os
from ads.aqua import (
ENV_VAR_LOG_LEVEL,
logger,
set_log_level,
)
from ads.aqua.common.errors import AquaCLIError
from ads.aqua.evaluation import AquaEvaluationApp
from ads.aqua.finetuning import AquaFineTuningApp
from ads.aqua.model import AquaModelApp
from ads.aqua.modeldeployment import AquaDeploymentApp
from ads.common.utils import LOG_LEVELS
class AquaCommand:
"""Contains the command groups for project Aqua.
Acts as an entry point for managing different components of the Aqua
project including model management, fine-tuning, deployment, and
evaluation.
"""
model = AquaModelApp
fine_tuning = AquaFineTuningApp
deployment = AquaDeploymentApp
evaluation = AquaEvaluationApp
def __init__(
self,
debug: bool = None,
verbose: bool = None,
log_level: str = os.environ.get(ENV_VAR_LOG_LEVEL, "ERROR").upper(),
):
"""
Initialize the command line interface settings for the Aqua project.
FLAGS
-----
log_level (str):
Sets the logging level for the application.
Default is retrieved from environment variable `ADS_AQUA_LOG_LEVEL`,
or 'ERROR' if not set. Example values include 'DEBUG', 'INFO',
'WARNING', 'ERROR', and 'CRITICAL'.
debug (bool):
Sets the logging level for the application to `DEBUG`.
verbose (bool):
Sets the logging level for the application to `INFO`.
Raises
------
AquaCLIError:
When `--verbose` and `--debug` being used together.
When missing required `ODSC_MODEL_COMPARTMENT_OCID` env var.
"""
if verbose is not None and debug is not None:
raise AquaCLIError(
"Cannot use `--debug` and `--verbose` at the same time. "
"Please select either `--debug` for `DEBUG` level logging or "
"`--verbose` for `INFO` level logging."
)
elif verbose is not None:
self._validate_value("--verbose", verbose)
aqua_log_level = "INFO"
elif debug is not None:
self._validate_value("--debug", debug)
aqua_log_level = "DEBUG"
else:
if log_level.upper() not in LOG_LEVELS:
logger.warning(
f"Log level should be one of {LOG_LEVELS}. Setting default to ERROR."
)
log_level = "ERROR"
aqua_log_level = log_level.upper()
set_log_level(aqua_log_level)
@staticmethod
def _validate_value(flag, value):
"""Check if the given value for bool flag is valid.
Raises
------
AquaCLIError:
When the given value for bool flag is invalid.
"""
if value not in [True, False]:
raise AquaCLIError(
f"Invalid input `{value}` for flag: {flag}, a boolean value is required. "
"If you intend to chain a function call to the result, please separate the "
"flag and the subsequent function call with separator `-`."
)