clarifai 11.3.0rc1__py3-none-any.whl → 11.3.0rc3__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 +351 -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 +388 -348
- 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.0rc1.dist-info → clarifai-11.3.0rc3.dist-info}/METADATA +5 -6
- clarifai-11.3.0rc3.dist-info/RECORD +109 -0
- {clarifai-11.3.0rc1.dist-info → clarifai-11.3.0rc3.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.0rc1.dist-info/RECORD +0 -322
- {clarifai-11.3.0rc1.dist-info → clarifai-11.3.0rc3.dist-info}/entry_points.txt +0 -0
- {clarifai-11.3.0rc1.dist-info → clarifai-11.3.0rc3.dist-info/licenses}/LICENSE +0 -0
- {clarifai-11.3.0rc1.dist-info → clarifai-11.3.0rc3.dist-info}/top_level.txt +0 -0
clarifai/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "11.3.
|
1
|
+
__version__ = "11.3.0rc3"
|
clarifai/cli/__main__.py
CHANGED
clarifai/cli/base.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import json
|
2
2
|
import os
|
3
|
+
import shutil
|
3
4
|
import sys
|
4
5
|
|
5
6
|
import click
|
@@ -11,117 +12,135 @@ from clarifai.utils.constants import DEFAULT_CONFIG
|
|
11
12
|
from clarifai.utils.logging import logger
|
12
13
|
|
13
14
|
|
14
|
-
|
15
|
+
# @click.group(cls=CustomMultiGroup)
|
15
16
|
@click.group(cls=AliasedGroup)
|
16
17
|
@click.option('--config', default=DEFAULT_CONFIG)
|
17
18
|
@click.pass_context
|
18
19
|
def cli(ctx, config):
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
Context(
|
20
|
+
"""Clarifai CLI"""
|
21
|
+
ctx.ensure_object(dict)
|
22
|
+
if os.path.exists(config):
|
23
|
+
cfg = Config.from_yaml(filename=config)
|
24
|
+
ctx.obj = cfg
|
25
|
+
else:
|
26
|
+
cfg = Config(
|
27
|
+
filename=config,
|
28
|
+
current_context='default',
|
29
|
+
contexts={
|
30
|
+
'default': Context(
|
31
31
|
'default',
|
32
32
|
CLARIFAI_PAT=os.environ.get('CLARIFAI_PAT', ''),
|
33
33
|
CLARIFAI_USER_ID=os.environ.get('CLARIFAI_USER_ID', ''),
|
34
34
|
CLARIFAI_API_BASE=os.environ.get('CLARIFAI_API_BASE', 'api.clarifai.com'),
|
35
35
|
)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
},
|
37
|
+
)
|
38
|
+
try:
|
39
|
+
cfg.to_yaml(config)
|
40
|
+
except Exception:
|
41
|
+
logger.warning(
|
42
|
+
"Could not write configuration to disk. Could be a read only file system."
|
43
|
+
)
|
44
|
+
ctx.obj = cfg # still have the default config even if couldn't write.
|
42
45
|
|
43
46
|
|
44
47
|
@cli.command()
|
45
48
|
@click.argument('shell', type=click.Choice(['bash', 'zsh']))
|
46
49
|
def shell_completion(shell):
|
47
|
-
|
48
|
-
|
50
|
+
"""Shell completion script"""
|
51
|
+
os.system(f"_CLARIFAI_COMPLETE={shell}_source clarifai")
|
49
52
|
|
50
53
|
|
51
|
-
@cli.group(
|
54
|
+
@cli.group(
|
55
|
+
['cfg'],
|
56
|
+
cls=AliasedGroup,
|
57
|
+
context_settings={'max_content_width': shutil.get_terminal_size().columns - 10},
|
58
|
+
)
|
52
59
|
def config():
|
53
|
-
|
60
|
+
"""Manage CLI configuration"""
|
54
61
|
|
55
62
|
|
56
63
|
@config.command(['e'])
|
57
64
|
@click.pass_context
|
58
65
|
def edit(ctx):
|
59
|
-
|
60
|
-
|
66
|
+
"""Edit the configuration file"""
|
67
|
+
os.system(f'{os.environ.get("EDITOR", "vi")} {ctx.obj.filename}')
|
61
68
|
|
62
69
|
|
63
70
|
@config.command(['current'])
|
64
71
|
@click.option('-o', '--output-format', default='name', type=click.Choice(['name', 'json', 'yaml']))
|
65
72
|
@click.pass_context
|
66
73
|
def current_context(ctx, output_format):
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
print(json.dumps(ctx.obj.contexts[ctx.obj.current_context].to_serializable_dict()))
|
74
|
+
"""Get the current context"""
|
75
|
+
if output_format == 'name':
|
76
|
+
print(ctx.obj.current_context)
|
77
|
+
elif output_format == 'json':
|
78
|
+
print(json.dumps(ctx.obj.contexts[ctx.obj.current_context].to_serializable_dict()))
|
73
79
|
else:
|
74
|
-
|
80
|
+
print(yaml.safe_dump(ctx.obj.contexts[ctx.obj.current_context].to_serializable_dict()))
|
75
81
|
|
76
82
|
|
77
83
|
@config.command(['list', 'ls'])
|
78
84
|
@click.option(
|
79
|
-
'-o', '--output-format', default='wide', type=click.Choice(['wide', 'name', 'json', 'yaml'])
|
85
|
+
'-o', '--output-format', default='wide', type=click.Choice(['wide', 'name', 'json', 'yaml'])
|
86
|
+
)
|
80
87
|
@click.pass_context
|
81
88
|
def get_contexts(ctx, output_format):
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
89
|
+
"""Get all contexts"""
|
90
|
+
if output_format == 'wide':
|
91
|
+
columns = {
|
92
|
+
'': lambda c: '*' if c.name == ctx.obj.current_context else '',
|
93
|
+
'NAME': lambda c: c.name,
|
94
|
+
'USER_ID': lambda c: c.user_id,
|
95
|
+
'API_BASE': lambda c: c.api_base,
|
96
|
+
'PAT': lambda c: pat_display(c.pat),
|
97
|
+
}
|
98
|
+
additional_columns = set()
|
99
|
+
for cont in ctx.obj.contexts.values():
|
100
|
+
if 'env' in cont:
|
101
|
+
for key in cont.to_column_names():
|
102
|
+
if key not in columns:
|
103
|
+
additional_columns.add(key)
|
104
|
+
for key in sorted(additional_columns):
|
105
|
+
columns[key] = lambda c, k=key: getattr(c, k) if hasattr(c, k) else ""
|
106
|
+
|
107
|
+
formatter = TableFormatter(
|
108
|
+
custom_columns=columns,
|
109
|
+
)
|
110
|
+
print(formatter.format(ctx.obj.contexts.values(), fmt="plain"))
|
111
|
+
elif output_format == 'name':
|
112
|
+
print('\n'.join(ctx.obj.contexts))
|
113
|
+
elif output_format in ('json', 'yaml'):
|
114
|
+
dicts = [v.__dict__ for c, v in ctx.obj.contexts.items()]
|
115
|
+
for d in dicts:
|
116
|
+
d.pop('pat')
|
117
|
+
if output_format == 'json':
|
118
|
+
print(json.dumps(dicts))
|
119
|
+
elif output_format == 'yaml':
|
120
|
+
print(yaml.safe_dump(dicts))
|
102
121
|
|
103
122
|
|
104
123
|
@config.command(['use'])
|
105
124
|
@click.argument('context-name', type=str)
|
106
125
|
@click.pass_context
|
107
126
|
def use_context(ctx, context_name):
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
127
|
+
"""Set the current context"""
|
128
|
+
if context_name not in ctx.obj.contexts:
|
129
|
+
raise click.UsageError('Context not found')
|
130
|
+
ctx.obj.current_context = context_name
|
131
|
+
ctx.obj.to_yaml()
|
132
|
+
print(f'Set {context_name} as the current context')
|
114
133
|
|
115
134
|
|
116
135
|
@config.command(['cat'])
|
117
136
|
@click.option('-o', '--output-format', default='yaml', type=click.Choice(['yaml', 'json']))
|
118
137
|
@click.pass_obj
|
119
138
|
def dump(ctx_obj, output_format):
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
139
|
+
"""Dump the configuration to stdout"""
|
140
|
+
if output_format == 'yaml':
|
141
|
+
yaml.safe_dump(ctx_obj.to_dict(), sys.stdout)
|
142
|
+
else:
|
143
|
+
json.dump(ctx_obj.to_dict(), sys.stdout, indent=2)
|
125
144
|
|
126
145
|
|
127
146
|
@cli.command()
|
@@ -129,56 +148,43 @@ def dump(ctx_obj, output_format):
|
|
129
148
|
@click.option('--user_id', required=False, help='User ID')
|
130
149
|
@click.pass_context
|
131
150
|
def login(ctx, api_url, user_id):
|
132
|
-
|
151
|
+
"""Login command to set PAT and other configurations."""
|
133
152
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
153
|
+
name = input('context name (default: "default"): ')
|
154
|
+
user_id = user_id if user_id is not None else input('user id: ')
|
155
|
+
pat = input_or_default(
|
156
|
+
'personal access token value (default: "ENVVAR" to get our of env var rather than config): ',
|
157
|
+
'ENVVAR',
|
158
|
+
)
|
139
159
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
160
|
+
context = Context(
|
161
|
+
name,
|
162
|
+
CLARIFAI_API_BASE=api_url,
|
163
|
+
CLARIFAI_USER_ID=user_id,
|
164
|
+
CLARIFAI_PAT=pat,
|
165
|
+
)
|
146
166
|
|
147
|
-
|
148
|
-
|
167
|
+
if context.name == '':
|
168
|
+
context.name = 'default'
|
149
169
|
|
150
|
-
|
151
|
-
|
170
|
+
ctx.obj.contexts[context.name] = context
|
171
|
+
ctx.obj.current_context = context.name
|
152
172
|
|
153
|
-
|
173
|
+
ctx.obj.to_yaml()
|
154
174
|
|
155
175
|
|
156
176
|
@cli.group(cls=AliasedGroup)
|
157
177
|
def context():
|
158
|
-
|
178
|
+
"""Manage contexts"""
|
159
179
|
|
160
180
|
|
161
181
|
def pat_display(pat):
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
@context.command(['ls'])
|
166
|
-
@click.pass_context
|
167
|
-
def list(ctx):
|
168
|
-
"""List available contexts"""
|
169
|
-
formatter = TableFormatter(custom_columns={
|
170
|
-
'': lambda c: '*' if c.name == ctx.obj.current_context else '',
|
171
|
-
'NAME': lambda c: c.name,
|
172
|
-
'USER_ID': lambda c: c.user_id,
|
173
|
-
'API_BASE': lambda c: c.api_base,
|
174
|
-
'PAT': lambda c: pat_display(c.pat)
|
175
|
-
})
|
176
|
-
print(formatter.format(ctx.obj.contexts.values(), fmt="plain"))
|
182
|
+
return pat[:5] + "****"
|
177
183
|
|
178
184
|
|
179
185
|
def input_or_default(prompt, default):
|
180
|
-
|
181
|
-
|
186
|
+
value = input(prompt)
|
187
|
+
return value if value else default
|
182
188
|
|
183
189
|
|
184
190
|
@context.command()
|
@@ -194,23 +200,25 @@ def create(
|
|
194
200
|
base_url=None,
|
195
201
|
pat=None,
|
196
202
|
):
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
203
|
+
"""Create a new context"""
|
204
|
+
if name in ctx.obj.contexts:
|
205
|
+
print(f'{name} already exists')
|
206
|
+
sys.exit(1)
|
207
|
+
if not user_id:
|
208
|
+
user_id = input('user id: ')
|
209
|
+
if not base_url:
|
210
|
+
base_url = input_or_default(
|
211
|
+
'base url (default: https://api.clarifai.com): ', 'https://api.clarifai.com'
|
212
|
+
)
|
213
|
+
if not pat:
|
214
|
+
pat = input_or_default(
|
215
|
+
'personal access token value (default: "ENVVAR" to get our of env var rather than config): ',
|
216
|
+
'ENVVAR',
|
217
|
+
)
|
218
|
+
|
219
|
+
context = Context(name, CLARIFAI_USER_ID=user_id, CLARIFAI_API_BASE=base_url, CLARIFAI_PAT=pat)
|
220
|
+
ctx.obj.contexts[context.name] = context
|
221
|
+
ctx.obj.to_yaml()
|
214
222
|
|
215
223
|
|
216
224
|
# write a click command to delete a context
|
@@ -218,25 +226,25 @@ def create(
|
|
218
226
|
@click.argument('name')
|
219
227
|
@click.pass_context
|
220
228
|
def delete(ctx, name):
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
229
|
+
"""Delete a context"""
|
230
|
+
if name not in ctx.obj.contexts:
|
231
|
+
print(f'{name} is not a valid context')
|
232
|
+
sys.exit(1)
|
233
|
+
ctx.obj.contexts.pop(name)
|
234
|
+
ctx.obj.to_yaml()
|
235
|
+
print(f'{name} deleted')
|
228
236
|
|
229
237
|
|
230
238
|
@context.command()
|
231
239
|
@click.argument('name', type=str)
|
232
240
|
@click.pass_context
|
233
241
|
def use(ctx, name):
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
242
|
+
"""Set the current context"""
|
243
|
+
if name not in ctx.obj.contexts:
|
244
|
+
raise click.UsageError('Context not found')
|
245
|
+
ctx.obj.current_context = name
|
246
|
+
ctx.obj.to_yaml()
|
247
|
+
print(f'Set {name} as the current context')
|
240
248
|
|
241
249
|
|
242
250
|
@cli.command()
|
@@ -244,12 +252,12 @@ def use(ctx, name):
|
|
244
252
|
@click.option('--context', type=str, help='Context to use')
|
245
253
|
@click.pass_context
|
246
254
|
def run(ctx, script, context=None):
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
255
|
+
"""Execute a script with the current context's environment"""
|
256
|
+
context = ctx.obj.current if not context else context
|
257
|
+
cmd = f'CLARIFAI_USER_ID={context.user_id} CLARIFAI_API_BASE={context.base_url} CLARIFAI_PAT={context.pat} '
|
258
|
+
cmd += ' '.join([f'{k}={v}' for k, v in context.env.items()])
|
259
|
+
cmd += f' {script}'
|
260
|
+
os.system(cmd)
|
253
261
|
|
254
262
|
|
255
263
|
# Import the CLI commands to register them
|
@@ -257,4 +265,4 @@ load_command_modules()
|
|
257
265
|
|
258
266
|
|
259
267
|
def main():
|
260
|
-
|
268
|
+
cli()
|
clarifai/cli/compute_cluster.py
CHANGED
@@ -1,12 +1,18 @@
|
|
1
|
+
import shutil
|
2
|
+
|
1
3
|
import click
|
2
4
|
|
3
5
|
from clarifai.cli.base import cli
|
4
6
|
from clarifai.utils.cli import AliasedGroup, display_co_resources, validate_context
|
5
7
|
|
6
8
|
|
7
|
-
@cli.group(
|
9
|
+
@cli.group(
|
10
|
+
['computecluster', 'cc'],
|
11
|
+
cls=AliasedGroup,
|
12
|
+
context_settings={'max_content_width': shutil.get_terminal_size().columns - 10},
|
13
|
+
)
|
8
14
|
def computecluster():
|
9
|
-
|
15
|
+
"""Manage Compute Clusters: create, delete, list"""
|
10
16
|
|
11
17
|
|
12
18
|
@computecluster.command(['c'])
|
@@ -15,18 +21,21 @@ def computecluster():
|
|
15
21
|
'--config',
|
16
22
|
type=click.Path(exists=True),
|
17
23
|
required=True,
|
18
|
-
help='Path to the compute cluster config file.'
|
24
|
+
help='Path to the compute cluster config file.',
|
25
|
+
)
|
19
26
|
@click.pass_context
|
20
27
|
def create(ctx, compute_cluster_id, config):
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
"""Create a new Compute Cluster with the given config file."""
|
29
|
+
from clarifai.client.user import User
|
30
|
+
|
31
|
+
validate_context(ctx)
|
32
|
+
user = User(
|
33
|
+
user_id=ctx.obj.current.user_id, pat=ctx.obj.current.pat, base_url=ctx.obj.current.api_base
|
34
|
+
)
|
35
|
+
if compute_cluster_id:
|
36
|
+
user.create_compute_cluster(config, compute_cluster_id=compute_cluster_id)
|
37
|
+
else:
|
38
|
+
user.create_compute_cluster(config)
|
30
39
|
|
31
40
|
|
32
41
|
@computecluster.command(['ls'])
|
@@ -34,28 +43,33 @@ def create(ctx, compute_cluster_id, config):
|
|
34
43
|
@click.option('--per_page', required=False, help='Number of items per page.', default=16)
|
35
44
|
@click.pass_context
|
36
45
|
def list(ctx, page_no, per_page):
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
"""List all compute clusters for the user."""
|
47
|
+
from clarifai.client.user import User
|
48
|
+
|
49
|
+
validate_context(ctx)
|
50
|
+
user = User(
|
51
|
+
user_id=ctx.obj.current.user_id, pat=ctx.obj.current.pat, base_url=ctx.obj.current.api_base
|
52
|
+
)
|
53
|
+
response = user.list_compute_clusters(page_no, per_page)
|
54
|
+
display_co_resources(
|
55
|
+
response,
|
56
|
+
custom_columns={
|
57
|
+
'ID': lambda c: c.id,
|
58
|
+
'USER_ID': lambda c: c.user_id,
|
59
|
+
'DESCRIPTION': lambda c: c.description,
|
60
|
+
},
|
61
|
+
)
|
50
62
|
|
51
63
|
|
52
64
|
@computecluster.command(['rm'])
|
53
65
|
@click.argument('compute_cluster_id')
|
54
66
|
@click.pass_context
|
55
67
|
def delete(ctx, compute_cluster_id):
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
68
|
+
"""Deletes a compute cluster for the user."""
|
69
|
+
from clarifai.client.user import User
|
70
|
+
|
71
|
+
validate_context(ctx)
|
72
|
+
user = User(
|
73
|
+
user_id=ctx.obj.current.user_id, pat=ctx.obj.current.pat, base_url=ctx.obj.current.api_base
|
74
|
+
)
|
75
|
+
user.delete_compute_clusters([compute_cluster_id])
|