clarifai 11.3.0rc2__py3-none-any.whl → 11.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- clarifai/__init__.py +1 -1
- clarifai/cli/__main__.py +1 -1
- clarifai/cli/base.py +144 -136
- clarifai/cli/compute_cluster.py +45 -31
- clarifai/cli/deployment.py +93 -76
- clarifai/cli/model.py +578 -180
- clarifai/cli/nodepool.py +100 -82
- clarifai/client/__init__.py +12 -2
- clarifai/client/app.py +973 -911
- clarifai/client/auth/helper.py +345 -342
- clarifai/client/auth/register.py +7 -7
- clarifai/client/auth/stub.py +107 -106
- clarifai/client/base.py +185 -178
- clarifai/client/compute_cluster.py +214 -180
- clarifai/client/dataset.py +793 -698
- clarifai/client/deployment.py +55 -50
- clarifai/client/input.py +1223 -1088
- clarifai/client/lister.py +47 -45
- clarifai/client/model.py +1939 -1717
- clarifai/client/model_client.py +525 -502
- clarifai/client/module.py +82 -73
- clarifai/client/nodepool.py +358 -213
- clarifai/client/runner.py +58 -0
- clarifai/client/search.py +342 -309
- clarifai/client/user.py +419 -414
- clarifai/client/workflow.py +294 -274
- clarifai/constants/dataset.py +11 -17
- clarifai/constants/model.py +8 -2
- clarifai/datasets/export/inputs_annotations.py +233 -217
- clarifai/datasets/upload/base.py +63 -51
- clarifai/datasets/upload/features.py +43 -38
- clarifai/datasets/upload/image.py +237 -207
- clarifai/datasets/upload/loaders/coco_captions.py +34 -32
- clarifai/datasets/upload/loaders/coco_detection.py +72 -65
- clarifai/datasets/upload/loaders/imagenet_classification.py +57 -53
- clarifai/datasets/upload/loaders/xview_detection.py +274 -132
- clarifai/datasets/upload/multimodal.py +55 -46
- clarifai/datasets/upload/text.py +55 -47
- clarifai/datasets/upload/utils.py +250 -234
- clarifai/errors.py +51 -50
- clarifai/models/api.py +260 -238
- clarifai/modules/css.py +50 -50
- clarifai/modules/pages.py +33 -33
- clarifai/rag/rag.py +312 -288
- clarifai/rag/utils.py +91 -84
- clarifai/runners/models/model_builder.py +906 -802
- clarifai/runners/models/model_class.py +370 -331
- clarifai/runners/models/model_run_locally.py +459 -419
- clarifai/runners/models/model_runner.py +170 -162
- clarifai/runners/models/model_servicer.py +78 -70
- clarifai/runners/server.py +111 -101
- clarifai/runners/utils/code_script.py +225 -187
- clarifai/runners/utils/const.py +4 -1
- clarifai/runners/utils/data_types/__init__.py +12 -0
- clarifai/runners/utils/data_types/data_types.py +598 -0
- clarifai/runners/utils/data_utils.py +387 -440
- clarifai/runners/utils/loader.py +247 -227
- clarifai/runners/utils/method_signatures.py +411 -386
- clarifai/runners/utils/openai_convertor.py +108 -109
- clarifai/runners/utils/serializers.py +175 -179
- clarifai/runners/utils/url_fetcher.py +35 -35
- clarifai/schema/search.py +56 -63
- clarifai/urls/helper.py +125 -102
- clarifai/utils/cli.py +129 -123
- clarifai/utils/config.py +127 -87
- clarifai/utils/constants.py +49 -0
- clarifai/utils/evaluation/helpers.py +503 -466
- clarifai/utils/evaluation/main.py +431 -393
- clarifai/utils/evaluation/testset_annotation_parser.py +154 -144
- clarifai/utils/logging.py +324 -306
- clarifai/utils/misc.py +60 -56
- clarifai/utils/model_train.py +165 -146
- clarifai/utils/protobuf.py +126 -103
- clarifai/versions.py +3 -1
- clarifai/workflows/export.py +48 -50
- clarifai/workflows/utils.py +39 -36
- clarifai/workflows/validate.py +55 -43
- {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/METADATA +16 -6
- clarifai-11.4.0.dist-info/RECORD +109 -0
- {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/WHEEL +1 -1
- clarifai/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/__pycache__/errors.cpython-310.pyc +0 -0
- clarifai/__pycache__/errors.cpython-311.pyc +0 -0
- clarifai/__pycache__/versions.cpython-310.pyc +0 -0
- clarifai/__pycache__/versions.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/base.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/base_cli.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/compute_cluster.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/compute_cluster.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/deployment.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/deployment.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/model.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/model_cli.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/nodepool.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/nodepool.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/client/__pycache__/app.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/app.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/app.cpython-39.pyc +0 -0
- clarifai/client/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/base.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/compute_cluster.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/compute_cluster.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/dataset.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/dataset.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/deployment.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/deployment.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/input.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/input.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/lister.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/lister.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/model.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/module.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/module.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/nodepool.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/nodepool.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/search.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/user.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/user.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/workflow.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/workflow.cpython-311.pyc +0 -0
- clarifai/client/auth/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/client/auth/__pycache__/helper.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/helper.cpython-311.pyc +0 -0
- clarifai/client/auth/__pycache__/register.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/register.cpython-311.pyc +0 -0
- clarifai/client/auth/__pycache__/stub.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/stub.cpython-311.pyc +0 -0
- clarifai/client/cli/__init__.py +0 -0
- clarifai/client/cli/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/client/cli/__pycache__/base_cli.cpython-310.pyc +0 -0
- clarifai/client/cli/__pycache__/model_cli.cpython-310.pyc +0 -0
- clarifai/client/cli/base_cli.py +0 -88
- clarifai/client/cli/model_cli.py +0 -29
- clarifai/constants/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/base.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/dataset.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/dataset.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/input.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/input.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/model.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/rag.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/rag.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/search.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/workflow.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/workflow.cpython-311.pyc +0 -0
- clarifai/datasets/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/datasets/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/datasets/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/datasets/export/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/datasets/export/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/datasets/export/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/datasets/export/__pycache__/inputs_annotations.cpython-310.pyc +0 -0
- clarifai/datasets/export/__pycache__/inputs_annotations.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/datasets/upload/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/base.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/features.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/features.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/image.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/image.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/multimodal.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/multimodal.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/text.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/text.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/utils.cpython-311.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/coco_detection.cpython-311.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/imagenet_classification.cpython-311.pyc +0 -0
- clarifai/models/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/modules/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/rag/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/rag/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/rag/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/rag/__pycache__/rag.cpython-310.pyc +0 -0
- clarifai/rag/__pycache__/rag.cpython-311.pyc +0 -0
- clarifai/rag/__pycache__/rag.cpython-39.pyc +0 -0
- clarifai/rag/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/rag/__pycache__/utils.cpython-311.pyc +0 -0
- clarifai/runners/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/runners/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/runners/dockerfile_template/Dockerfile.cpu.template +0 -31
- clarifai/runners/dockerfile_template/Dockerfile.cuda.template +0 -42
- clarifai/runners/dockerfile_template/Dockerfile.nim +0 -71
- clarifai/runners/models/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/runners/models/__pycache__/base_typed_model.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/base_typed_model.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/base_typed_model.cpython-39.pyc +0 -0
- clarifai/runners/models/__pycache__/model_builder.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/model_class.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_class.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/model_run_locally.cpython-310-pytest-7.1.2.pyc +0 -0
- clarifai/runners/models/__pycache__/model_run_locally.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_run_locally.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/model_runner.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_runner.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/model_upload.cpython-310.pyc +0 -0
- clarifai/runners/models/base_typed_model.py +0 -238
- clarifai/runners/models/model_class_refract.py +0 -80
- clarifai/runners/models/model_upload.py +0 -607
- clarifai/runners/models/temp.py +0 -25
- clarifai/runners/utils/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/__init__.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/buffered_stream.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/buffered_stream.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/buffered_stream.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/const.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/const.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/constants.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/constants.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/constants.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_handler.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_handler.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_handler.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_handler.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/grpc_server.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/grpc_server.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/grpc_server.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/health.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/health.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/health.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/loader.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/loader.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/logging.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/logging.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/logging.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/stream_source.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/stream_source.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-39.pyc +0 -0
- clarifai/runners/utils/data_handler.py +0 -231
- clarifai/runners/utils/data_handler_refract.py +0 -213
- clarifai/runners/utils/data_types.py +0 -469
- clarifai/runners/utils/logger.py +0 -0
- clarifai/runners/utils/openai_format.py +0 -87
- clarifai/schema/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/schema/__pycache__/search.cpython-311.pyc +0 -0
- clarifai/urls/__pycache__/helper.cpython-310.pyc +0 -0
- clarifai/urls/__pycache__/helper.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/utils/__pycache__/cli.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/cli.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/config.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/constants.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/constants.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/logging.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/logging.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/misc.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/misc.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/model_train.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/model_train.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/protobuf.cpython-311.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/helpers.cpython-311.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/main.cpython-311.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/main.cpython-39.pyc +0 -0
- clarifai/workflows/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/workflows/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/workflows/__pycache__/export.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/export.cpython-311.pyc +0 -0
- clarifai/workflows/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/utils.cpython-311.pyc +0 -0
- clarifai/workflows/__pycache__/validate.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/validate.cpython-311.pyc +0 -0
- clarifai-11.3.0rc2.dist-info/RECORD +0 -322
- {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/entry_points.txt +0 -0
- {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info/licenses}/LICENSE +0 -0
- {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/top_level.txt +0 -0
clarifai/utils/cli.py
CHANGED
@@ -12,157 +12,163 @@ from tabulate import tabulate
|
|
12
12
|
|
13
13
|
|
14
14
|
def from_yaml(filename: str):
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
try:
|
16
|
+
with open(filename, 'r') as f:
|
17
|
+
return yaml.safe_load(f)
|
18
|
+
except yaml.YAMLError as e:
|
19
|
+
click.echo(f"Error reading YAML file: {e}", err=True)
|
20
|
+
return {}
|
21
21
|
|
22
22
|
|
23
23
|
def dump_yaml(data, filename: str):
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
try:
|
25
|
+
with open(filename, 'w') as f:
|
26
|
+
yaml.dump(data, f)
|
27
|
+
except Exception as e:
|
28
|
+
click.echo(f"Error writing YAML file: {e}", err=True)
|
29
29
|
|
30
30
|
|
31
31
|
# Dynamically find and import all command modules from the cli directory
|
32
32
|
def load_command_modules():
|
33
|
-
|
33
|
+
package_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'cli')
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
for _, module_name, _ in pkgutil.iter_modules([package_dir]):
|
36
|
+
if module_name not in ['base', '__main__']: # Skip the base.py and __main__ file itself
|
37
|
+
importlib.import_module(f'clarifai.cli.{module_name}')
|
38
38
|
|
39
39
|
|
40
|
-
def display_co_resources(
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
40
|
+
def display_co_resources(
|
41
|
+
response,
|
42
|
+
custom_columns={
|
43
|
+
'ID': lambda c: c.id,
|
44
|
+
'USER_ID': lambda c: c.user_id,
|
45
|
+
'DESCRIPTION': lambda c: c.description,
|
46
|
+
},
|
47
|
+
):
|
48
|
+
"""Display compute orchestration resources listing results using rich."""
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
+
formatter = TableFormatter(custom_columns)
|
51
|
+
print(formatter.format(list(response), fmt="plain"))
|
50
52
|
|
51
53
|
|
52
54
|
class TableFormatter:
|
53
|
-
|
54
|
-
|
55
|
-
"""
|
55
|
+
def __init__(self, custom_columns: OrderedDict):
|
56
|
+
"""
|
56
57
|
Initializes the TableFormatter with column headers and custom column mappings.
|
57
58
|
|
58
59
|
:param headers: List of column headers for the table.
|
59
60
|
"""
|
60
|
-
|
61
|
+
self.custom_columns = custom_columns
|
61
62
|
|
62
|
-
|
63
|
-
|
63
|
+
def format(self, objects, fmt='plain'):
|
64
|
+
"""
|
64
65
|
Formats a list of objects into a table with custom columns.
|
65
66
|
|
66
67
|
:param objects: List of objects to format into a table.
|
67
68
|
:return: A string representing the table.
|
68
69
|
"""
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
70
|
+
# Prepare the rows by applying the custom column functions to each object
|
71
|
+
rows = []
|
72
|
+
for obj in objects:
|
73
|
+
# row = [self.custom_columns[header](obj) for header in self.headers]
|
74
|
+
row = [f(obj) for f in self.custom_columns.values()]
|
75
|
+
rows.append(row)
|
75
76
|
|
76
|
-
|
77
|
-
|
78
|
-
|
77
|
+
# Create the table
|
78
|
+
table = tabulate(rows, headers=self.custom_columns.keys(), tablefmt=fmt)
|
79
|
+
return table
|
79
80
|
|
80
81
|
|
81
82
|
class AliasedGroup(click.Group):
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
83
|
+
def __init__(
|
84
|
+
self,
|
85
|
+
name: t.Optional[str] = None,
|
86
|
+
commands: t.Optional[
|
87
|
+
t.Union[t.MutableMapping[str, click.Command], t.Sequence[click.Command]]
|
88
|
+
] = None,
|
89
|
+
**attrs: t.Any,
|
90
|
+
) -> None:
|
91
|
+
super().__init__(name, commands, **attrs)
|
92
|
+
self.alias_map = {}
|
93
|
+
self.command_to_aliases = defaultdict(list)
|
94
|
+
|
95
|
+
def add_alias(self, cmd: click.Command, alias: str) -> None:
|
96
|
+
self.alias_map[alias] = cmd
|
97
|
+
if alias != cmd.name:
|
98
|
+
self.command_to_aliases[cmd].append(alias)
|
99
|
+
|
100
|
+
def command(
|
101
|
+
self, aliases=None, *args, **kwargs
|
102
|
+
) -> t.Callable[[t.Callable[..., t.Any]], click.Command]:
|
103
|
+
cmd_decorator = super().command(*args, **kwargs)
|
104
|
+
if aliases is None:
|
105
|
+
aliases = []
|
106
|
+
|
107
|
+
def aliased_decorator(f):
|
108
|
+
cmd = cmd_decorator(f)
|
109
|
+
if cmd.name:
|
110
|
+
self.add_alias(cmd, cmd.name)
|
111
|
+
for alias in aliases:
|
112
|
+
self.add_alias(cmd, alias)
|
113
|
+
return cmd
|
114
|
+
|
115
|
+
f = None
|
116
|
+
if args and callable(args[0]):
|
117
|
+
(f,) = args
|
118
|
+
if f is not None:
|
119
|
+
return aliased_decorator(f)
|
120
|
+
return aliased_decorator
|
121
|
+
|
122
|
+
def group(
|
123
|
+
self, aliases=None, *args, **kwargs
|
124
|
+
) -> t.Callable[[t.Callable[..., t.Any]], click.Group]:
|
125
|
+
cmd_decorator = super().group(*args, **kwargs)
|
126
|
+
if aliases is None:
|
127
|
+
aliases = []
|
128
|
+
|
129
|
+
def aliased_decorator(f):
|
130
|
+
cmd = cmd_decorator(f)
|
131
|
+
if cmd.name:
|
132
|
+
self.add_alias(cmd, cmd.name)
|
133
|
+
for alias in aliases:
|
134
|
+
self.add_alias(cmd, alias)
|
135
|
+
return cmd
|
136
|
+
|
137
|
+
f = None
|
138
|
+
if args and callable(args[0]):
|
139
|
+
(f,) = args
|
140
|
+
if f is not None:
|
141
|
+
return aliased_decorator(f)
|
142
|
+
return aliased_decorator
|
143
|
+
|
144
|
+
def get_command(self, ctx: click.Context, cmd_name: str) -> t.Optional[click.Command]:
|
145
|
+
rv = click.Group.get_command(self, ctx, cmd_name)
|
146
|
+
if rv is not None:
|
147
|
+
return rv
|
148
|
+
return self.alias_map.get(cmd_name)
|
149
|
+
|
150
|
+
def format_commands(self, ctx, formatter):
|
151
|
+
sub_commands = self.list_commands(ctx)
|
152
|
+
|
153
|
+
rows = []
|
154
|
+
for sub_command in sub_commands:
|
155
|
+
cmd = self.get_command(ctx, sub_command)
|
156
|
+
if cmd is None or getattr(cmd, 'hidden', False):
|
157
|
+
continue
|
158
|
+
if cmd in self.command_to_aliases:
|
159
|
+
aliases = ', '.join(self.command_to_aliases[cmd])
|
160
|
+
sub_command = f'{sub_command} ({aliases})'
|
161
|
+
cmd_help = cmd.help
|
162
|
+
rows.append((sub_command, cmd_help))
|
163
|
+
|
164
|
+
if rows:
|
165
|
+
with formatter.section("Commands"):
|
166
|
+
formatter.write_dl(rows)
|
162
167
|
|
163
168
|
|
164
169
|
def validate_context(ctx):
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
170
|
+
from clarifai.utils.logging import logger
|
171
|
+
|
172
|
+
if ctx.obj == {}:
|
173
|
+
logger.error("CLI config file missing. Run `clarifai login` to set up the CLI config.")
|
174
|
+
sys.exit(1)
|
clarifai/utils/config.py
CHANGED
@@ -8,98 +8,138 @@ from clarifai.utils.constants import DEFAULT_CONFIG
|
|
8
8
|
|
9
9
|
|
10
10
|
class Context(OrderedDict):
|
11
|
-
|
11
|
+
"""
|
12
12
|
A context which has a name and a set of key-values as a dict under env.
|
13
13
|
|
14
14
|
You can access the keys directly.
|
15
15
|
"""
|
16
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
|
-
|
17
|
+
def __init__(self, name, **kwargs):
|
18
|
+
self['name'] = name
|
19
|
+
# when loading from config we may have the env: section in yaml already so we get it here.
|
20
|
+
if 'env' in kwargs:
|
21
|
+
self['env'] = kwargs['env']
|
22
|
+
else: # when consructing as Context(name, key=value) we set it here.
|
23
|
+
self['env'] = kwargs
|
24
|
+
|
25
|
+
def __getattr__(self, key):
|
26
|
+
try:
|
27
|
+
if key == 'name':
|
28
|
+
return self[key]
|
29
|
+
if key == 'env':
|
30
|
+
raise AttributeError("Don't access .env directly")
|
31
|
+
|
32
|
+
# Allow accessing CLARIFAI_PAT type env var names from config as .pat
|
33
|
+
envvar_name = 'CLARIFAI_' + key.upper()
|
34
|
+
env = self['env']
|
35
|
+
if envvar_name in env:
|
36
|
+
value = env[envvar_name]
|
37
|
+
if value == "ENVVAR":
|
38
|
+
if envvar_name not in os.environ:
|
39
|
+
raise AttributeError(
|
40
|
+
f"Environment variable '{envvar_name}' not set. Attempting to load it for config '{self['name']}'. Please set it in your terminal."
|
41
|
+
)
|
42
|
+
return os.environ[envvar_name]
|
43
|
+
else:
|
44
|
+
value = env[key]
|
45
|
+
|
46
|
+
if isinstance(value, dict):
|
47
|
+
return Context(value)
|
48
|
+
|
49
|
+
return value
|
50
|
+
except KeyError as e:
|
51
|
+
raise AttributeError(f"'{type(self).__name__}' object has no attribute '{key}'") from e
|
52
|
+
|
53
|
+
def __hasattr__(self, key):
|
54
|
+
if key == "name":
|
55
|
+
return True
|
56
|
+
else:
|
57
|
+
envvar_name = 'CLARIFAI_' + key.upper()
|
58
|
+
return envvar_name in self['env'] or key in self['env']
|
59
|
+
|
60
|
+
def __setattr__(self, key, value):
|
61
|
+
if key == "name":
|
62
|
+
self['name'] = value
|
63
|
+
else:
|
64
|
+
self['env'][key] = value
|
65
|
+
|
66
|
+
def __delattr__(self, key):
|
67
|
+
try:
|
68
|
+
del self['env'][key]
|
69
|
+
except KeyError as e:
|
70
|
+
raise AttributeError(f"'{type(self).__name__}' object has no attribute '{key}'") from e
|
71
|
+
|
72
|
+
def to_column_names(self):
|
73
|
+
"""used for displaying on terminal."""
|
74
|
+
keys = []
|
75
|
+
for k in self['env'].keys():
|
76
|
+
if k.startswith("CLARIFAI_"):
|
77
|
+
keys.append(k.replace("CLARIFAI_", "", 1))
|
78
|
+
return keys
|
79
|
+
|
80
|
+
def to_stripped_lowercase(self):
|
81
|
+
dict(self['env'])
|
82
|
+
|
83
|
+
def to_serializable_dict(self):
|
84
|
+
return dict(self['env'])
|
85
|
+
|
86
|
+
def set_to_env(self):
|
87
|
+
"""sets the context env vars to the current os.environ
|
88
|
+
|
89
|
+
Example:
|
90
|
+
# This is helpful in scripts so you can do
|
91
|
+
|
92
|
+
from clarifai.utils.config import Config
|
93
|
+
|
94
|
+
Config.from_yaml().current.set_to_env()
|
95
|
+
|
96
|
+
"""
|
97
|
+
for k, v in self['env'].items():
|
98
|
+
if isinstance(v, dict):
|
99
|
+
continue
|
100
|
+
envvar_name = k.upper()
|
101
|
+
if not envvar_name.startswith('CLARIFAI_'):
|
102
|
+
envvar_name = 'CLARIFAI_' + envvar_name
|
103
|
+
os.environ[envvar_name] = str(v)
|
63
104
|
|
64
105
|
|
65
106
|
@dataclass
|
66
|
-
class Config
|
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
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
return self.contexts[self.current_context]
|
107
|
+
class Config:
|
108
|
+
current_context: str
|
109
|
+
filename: str
|
110
|
+
contexts: OrderedDict[str, Context] = field(default_factory=OrderedDict)
|
111
|
+
|
112
|
+
def __post_init__(self):
|
113
|
+
for k, v in self.contexts.items():
|
114
|
+
if 'name' not in v:
|
115
|
+
v['name'] = k
|
116
|
+
self.contexts = {k: Context(**v) for k, v in self.contexts.items()}
|
117
|
+
|
118
|
+
@classmethod
|
119
|
+
def from_yaml(cls, filename: str = DEFAULT_CONFIG):
|
120
|
+
with open(filename, 'r') as f:
|
121
|
+
cfg = yaml.safe_load(f)
|
122
|
+
return cls(**cfg, filename=filename)
|
123
|
+
|
124
|
+
def to_dict(self):
|
125
|
+
return {
|
126
|
+
'current_context': self.current_context,
|
127
|
+
'contexts': {k: v.to_serializable_dict() for k, v in self.contexts.items()},
|
128
|
+
}
|
129
|
+
|
130
|
+
def to_yaml(self, filename: str = None):
|
131
|
+
if filename is None:
|
132
|
+
filename = self.filename
|
133
|
+
dir = os.path.dirname(filename)
|
134
|
+
if len(dir):
|
135
|
+
os.makedirs(dir, exist_ok=True)
|
136
|
+
_dict = self.to_dict()
|
137
|
+
for k, v in _dict['contexts'].items():
|
138
|
+
v.pop('name', None)
|
139
|
+
with open(filename, 'w') as f:
|
140
|
+
yaml.safe_dump(_dict, f)
|
141
|
+
|
142
|
+
@property
|
143
|
+
def current(self) -> Context:
|
144
|
+
"""get the current Context"""
|
145
|
+
return self.contexts[self.current_context]
|
clarifai/utils/constants.py
CHANGED
@@ -5,3 +5,52 @@ CLARIFAI_SESSION_TOKEN_ENV_VAR = "CLARIFAI_SESSION_TOKEN"
|
|
5
5
|
CLARIFAI_USER_ID_ENV_VAR = "CLARIFAI_USER_ID"
|
6
6
|
|
7
7
|
DEFAULT_CONFIG = f'{os.environ["HOME"]}/.config/clarifai/config'
|
8
|
+
|
9
|
+
# Default clusters, etc. for local dev runner easy setup
|
10
|
+
DEFAULT_LOCAL_DEV_COMPUTE_CLUSTER_ID = "local-dev-compute-cluster"
|
11
|
+
DEFAULT_LOCAL_DEV_NODEPOOL_ID = "local-dev-nodepool"
|
12
|
+
DEFAULT_LOCAL_DEV_DEPLOYMENT_ID = "local-dev-deployment"
|
13
|
+
DEFAULT_LOCAL_DEV_MODEL_ID = "local-dev-model"
|
14
|
+
DEFAULT_LOCAL_DEV_APP_ID = "local-dev-runner-app"
|
15
|
+
|
16
|
+
# FIXME: should have any-to-any for these cases.
|
17
|
+
DEFAULT_LOCAL_DEV_MODEL_TYPE = "text-to-text"
|
18
|
+
|
19
|
+
DEFAULT_LOCAL_DEV_COMPUTE_CLUSTER_CONFIG = {
|
20
|
+
"compute_cluster": {
|
21
|
+
"id": DEFAULT_LOCAL_DEV_COMPUTE_CLUSTER_ID,
|
22
|
+
"description": "Default Local Dev Compute Cluster",
|
23
|
+
"cloud_provider": {
|
24
|
+
"id": "local",
|
25
|
+
},
|
26
|
+
"region": "na",
|
27
|
+
"managed_by": "user",
|
28
|
+
"cluster_type": "local-dev",
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
DEFAULT_LOCAL_DEV_NODEPOOL_CONFIG = {
|
33
|
+
"nodepool": {
|
34
|
+
"id": DEFAULT_LOCAL_DEV_NODEPOOL_ID,
|
35
|
+
"description": "Default Local Dev Nodepool",
|
36
|
+
"compute_cluster": {
|
37
|
+
"id": DEFAULT_LOCAL_DEV_COMPUTE_CLUSTER_ID,
|
38
|
+
"user_id": None, # This will be set when creating the compute cluster
|
39
|
+
},
|
40
|
+
"instance_types": [
|
41
|
+
{
|
42
|
+
"id": "local-cpu",
|
43
|
+
"compute_info": {
|
44
|
+
"cpu_limit": str(os.cpu_count()),
|
45
|
+
"cpu_memory": "16Gi", # made up as we don't schedule based on this for local dev.
|
46
|
+
"num_accelerators": 0, # TODO if we need accelerator detection for local dev.
|
47
|
+
},
|
48
|
+
}
|
49
|
+
],
|
50
|
+
"node_capacity_type": {
|
51
|
+
"capacity_types": [1],
|
52
|
+
},
|
53
|
+
"min_instances": 1,
|
54
|
+
"max_instances": 1,
|
55
|
+
}
|
56
|
+
}
|