clarifai 11.2.3rc1__py3-none-any.whl → 11.2.3rc2__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/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/__pycache__/errors.cpython-310.pyc +0 -0
- clarifai/__pycache__/versions.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/base.cpython-310.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__/deployment.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/model_cli.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/nodepool.cpython-310.pyc +0 -0
- clarifai/cli/base.py +81 -228
- clarifai/cli/compute_cluster.py +17 -25
- clarifai/cli/deployment.py +41 -67
- clarifai/cli/model.py +39 -26
- clarifai/cli/nodepool.py +40 -59
- clarifai/client/__pycache__/__init__.cpython-310.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-39.pyc +0 -0
- clarifai/client/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/compute_cluster.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/dataset.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/deployment.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/input.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/lister.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/module.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/nodepool.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/user.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/workflow.cpython-310.pyc +0 -0
- clarifai/client/app.py +1 -1
- clarifai/client/auth/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/helper.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/register.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/stub.cpython-310.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 +88 -0
- clarifai/client/cli/model_cli.py +29 -0
- clarifai/client/model.py +159 -393
- clarifai/client/model_client.py +502 -0
- clarifai/constants/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/dataset.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/input.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/{model.cpython-312.pyc → model.cpython-310.pyc} +0 -0
- clarifai/constants/__pycache__/rag.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/workflow.cpython-310.pyc +0 -0
- clarifai/datasets/__pycache__/__init__.cpython-310.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-39.pyc +0 -0
- clarifai/datasets/export/__pycache__/inputs_annotations.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/__init__.cpython-310.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__/features.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/image.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/multimodal.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/text.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-39.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-39.pyc +0 -0
- clarifai/rag/__pycache__/rag.cpython-310.pyc +0 -0
- clarifai/rag/__pycache__/rag.cpython-39.pyc +0 -0
- clarifai/rag/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/runners/__init__.py +2 -7
- clarifai/runners/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/runners/dockerfile_template/Dockerfile.cpu.template +31 -0
- clarifai/runners/dockerfile_template/Dockerfile.cuda.template +42 -0
- clarifai/runners/dockerfile_template/Dockerfile.nim +71 -0
- clarifai/runners/models/__pycache__/__init__.cpython-310.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-39.pyc +0 -0
- clarifai/runners/models/__pycache__/model_class.cpython-310.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_runner.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_upload.cpython-310.pyc +0 -0
- clarifai/runners/models/model_builder.py +138 -51
- clarifai/runners/models/model_class.py +441 -28
- clarifai/runners/models/model_class_refract.py +80 -0
- clarifai/runners/models/model_run_locally.py +25 -89
- clarifai/runners/models/model_runner.py +8 -0
- clarifai/runners/models/model_servicer.py +11 -2
- clarifai/runners/models/model_upload.py +607 -0
- clarifai/runners/models/temp.py +25 -0
- clarifai/runners/utils/__pycache__/__init__.cpython-310.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__/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-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-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__/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-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-39.pyc +0 -0
- clarifai/runners/utils/code_script.py +217 -0
- clarifai/runners/utils/const.py +8 -9
- clarifai/runners/utils/data_handler.py +271 -210
- clarifai/runners/utils/data_handler_refract.py +213 -0
- clarifai/runners/utils/data_types.py +473 -0
- clarifai/runners/utils/data_utils.py +165 -0
- clarifai/runners/utils/loader.py +6 -36
- clarifai/runners/utils/logger.py +0 -0
- clarifai/runners/utils/method_signatures.py +518 -0
- clarifai/runners/utils/serializers.py +222 -0
- clarifai/schema/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/urls/__pycache__/helper.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/utils/__pycache__/cli.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/constants.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/logging.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/misc.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/model_train.cpython-310.pyc +0 -0
- clarifai/utils/cli.py +33 -132
- clarifai/utils/constants.py +0 -4
- clarifai/utils/evaluation/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/main.cpython-39.pyc +0 -0
- clarifai/utils/misc.py +0 -2
- clarifai/workflows/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/workflows/__pycache__/export.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/validate.cpython-310.pyc +0 -0
- {clarifai-11.2.3rc1.dist-info → clarifai-11.2.3rc2.dist-info}/METADATA +14 -3
- clarifai-11.2.3rc2.dist-info/RECORD +238 -0
- {clarifai-11.2.3rc1.dist-info → clarifai-11.2.3rc2.dist-info}/WHEEL +1 -1
- clarifai/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/__pycache__/errors.cpython-312.pyc +0 -0
- clarifai/__pycache__/versions.cpython-312.pyc +0 -0
- clarifai/cli/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/cli/__pycache__/base.cpython-312.pyc +0 -0
- clarifai/cli/__pycache__/compute_cluster.cpython-312.pyc +0 -0
- clarifai/cli/__pycache__/deployment.cpython-312.pyc +0 -0
- clarifai/cli/__pycache__/model.cpython-312.pyc +0 -0
- clarifai/cli/__pycache__/nodepool.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/app.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/base.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/compute_cluster.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/dataset.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/deployment.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/input.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/lister.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/model.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/model_client.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/module.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/nodepool.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/search.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/user.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/workflow.cpython-312.pyc +0 -0
- clarifai/client/auth/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/client/auth/__pycache__/helper.cpython-312.pyc +0 -0
- clarifai/client/auth/__pycache__/register.cpython-312.pyc +0 -0
- clarifai/client/auth/__pycache__/stub.cpython-312.pyc +0 -0
- clarifai/constants/__pycache__/base.cpython-312.pyc +0 -0
- clarifai/constants/__pycache__/dataset.cpython-312.pyc +0 -0
- clarifai/constants/__pycache__/input.cpython-312.pyc +0 -0
- clarifai/constants/__pycache__/search.cpython-312.pyc +0 -0
- clarifai/constants/__pycache__/workflow.cpython-312.pyc +0 -0
- clarifai/datasets/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/datasets/export/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/datasets/export/__pycache__/inputs_annotations.cpython-312.pyc +0 -0
- clarifai/datasets/upload/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/datasets/upload/__pycache__/base.cpython-312.pyc +0 -0
- clarifai/datasets/upload/__pycache__/features.cpython-312.pyc +0 -0
- clarifai/datasets/upload/__pycache__/image.cpython-312.pyc +0 -0
- clarifai/datasets/upload/__pycache__/multimodal.cpython-312.pyc +0 -0
- clarifai/datasets/upload/__pycache__/text.cpython-312.pyc +0 -0
- clarifai/datasets/upload/__pycache__/utils.cpython-312.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/coco_detection.cpython-312.pyc +0 -0
- clarifai/modules/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/modules/__pycache__/css.cpython-312.pyc +0 -0
- clarifai/runners/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/runners/__pycache__/server.cpython-312.pyc +0 -0
- clarifai/runners/models/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/runners/models/__pycache__/base_typed_model.cpython-312.pyc +0 -0
- clarifai/runners/models/__pycache__/model_builder.cpython-312.pyc +0 -0
- clarifai/runners/models/__pycache__/model_class.cpython-312.pyc +0 -0
- clarifai/runners/models/__pycache__/model_run_locally.cpython-312.pyc +0 -0
- clarifai/runners/models/__pycache__/model_runner.cpython-312.pyc +0 -0
- clarifai/runners/models/__pycache__/model_servicer.cpython-312.pyc +0 -0
- clarifai/runners/utils/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/runners/utils/__pycache__/const.cpython-312.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_handler.cpython-312.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_types.cpython-312.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-312.pyc +0 -0
- clarifai/runners/utils/__pycache__/loader.cpython-312.pyc +0 -0
- clarifai/runners/utils/__pycache__/method_signatures.cpython-312.pyc +0 -0
- clarifai/runners/utils/__pycache__/serializers.cpython-312.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-312.pyc +0 -0
- clarifai/schema/__pycache__/search.cpython-312.pyc +0 -0
- clarifai/urls/__pycache__/helper.cpython-312.pyc +0 -0
- clarifai/utils/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/utils/__pycache__/cli.cpython-312.pyc +0 -0
- clarifai/utils/__pycache__/config.cpython-312.pyc +0 -0
- clarifai/utils/__pycache__/constants.cpython-312.pyc +0 -0
- clarifai/utils/__pycache__/logging.cpython-312.pyc +0 -0
- clarifai/utils/__pycache__/misc.cpython-312.pyc +0 -0
- clarifai/utils/__pycache__/model_train.cpython-312.pyc +0 -0
- clarifai/utils/config.py +0 -105
- clarifai/utils/config.py~ +0 -145
- clarifai/utils/evaluation/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/helpers.cpython-312.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/main.cpython-312.pyc +0 -0
- clarifai/workflows/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/workflows/__pycache__/export.cpython-312.pyc +0 -0
- clarifai/workflows/__pycache__/utils.cpython-312.pyc +0 -0
- clarifai/workflows/__pycache__/validate.cpython-312.pyc +0 -0
- clarifai-11.2.3rc1.dist-info/RECORD +0 -185
- {clarifai-11.2.3rc1.dist-info → clarifai-11.2.3rc2.dist-info}/LICENSE +0 -0
- {clarifai-11.2.3rc1.dist-info → clarifai-11.2.3rc2.dist-info}/entry_points.txt +0 -0
- {clarifai-11.2.3rc1.dist-info → clarifai-11.2.3rc2.dist-info}/top_level.txt +0 -0
clarifai/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "11.2.
|
1
|
+
__version__ = "11.2.3rc2"
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
clarifai/cli/base.py
CHANGED
@@ -1,255 +1,108 @@
|
|
1
|
-
import json
|
2
1
|
import os
|
3
|
-
import sys
|
4
2
|
|
5
3
|
import click
|
6
|
-
import yaml
|
7
4
|
|
8
|
-
from
|
9
|
-
from clarifai.utils.config import Config, Context
|
10
|
-
from clarifai.utils.constants import DEFAULT_CONFIG
|
11
|
-
from clarifai.utils.logging import logger
|
5
|
+
from ..utils.cli import dump_yaml, from_yaml, load_command_modules, set_base_url
|
12
6
|
|
13
7
|
|
14
|
-
|
15
|
-
@click.group(cls=AliasedGroup)
|
16
|
-
@click.option('--config', default=DEFAULT_CONFIG)
|
17
|
-
@click.pass_context
|
18
|
-
def cli(ctx, config):
|
19
|
-
"""Clarifai CLI"""
|
20
|
-
ctx.ensure_object(dict)
|
21
|
-
if os.path.exists(config):
|
22
|
-
cfg = Config.from_yaml(filename=config)
|
23
|
-
ctx.obj = cfg
|
24
|
-
else:
|
25
|
-
cfg = Config(
|
26
|
-
filename=config,
|
27
|
-
current_context='default',
|
28
|
-
contexts={
|
29
|
-
'default':
|
30
|
-
Context(
|
31
|
-
'default',
|
32
|
-
CLARIFAI_PAT=os.environ.get('CLARIFAI_PAT', ''),
|
33
|
-
CLARIFAI_USER_ID=os.environ.get('CLARIFAI_USER_ID', ''),
|
34
|
-
CLARIFAI_API_BASE=os.environ.get('CLARIFAI_API_BASE', 'api.clarifai.com'),
|
35
|
-
)
|
36
|
-
})
|
37
|
-
try:
|
38
|
-
cfg.to_yaml(config)
|
39
|
-
except Exception:
|
40
|
-
logger.warning("Could not write configuration to disk. Could be a read only file system.")
|
41
|
-
ctx.obj = cfg # still have the default config even if couldn't write.
|
42
|
-
|
43
|
-
|
44
|
-
@cli.command()
|
45
|
-
@click.argument('shell', type=click.Choice(['bash', 'zsh']))
|
46
|
-
def shell_completion(shell):
|
47
|
-
"""Shell completion script"""
|
48
|
-
os.system(f"_CLARIFAI_COMPLETE={shell}_source clarifai")
|
49
|
-
|
50
|
-
|
51
|
-
@cli.group(['cfg'], cls=AliasedGroup)
|
52
|
-
def config():
|
53
|
-
"""Manage CLI configuration"""
|
8
|
+
class CustomMultiGroup(click.Group):
|
54
9
|
|
10
|
+
def group(self, *args, **kwargs):
|
11
|
+
"""Behaves the same as `click.Group.group()` except if passed
|
12
|
+
a list of names, all after the first will be aliases for the first.
|
13
|
+
"""
|
55
14
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
15
|
+
def decorator(f):
|
16
|
+
aliased_group = []
|
17
|
+
if isinstance(args[0], list):
|
18
|
+
# we have a list so create group aliases
|
19
|
+
_args = [args[0][0]] + list(args[1:])
|
20
|
+
for alias in args[0][1:]:
|
21
|
+
grp = super(CustomMultiGroup, self).group(alias, *args[1:], **kwargs)(f)
|
22
|
+
grp.short_help = "Alias for '{}'".format(_args[0])
|
23
|
+
aliased_group.append(grp)
|
24
|
+
else:
|
25
|
+
_args = args
|
61
26
|
|
27
|
+
# create the main group
|
28
|
+
grp = super(CustomMultiGroup, self).group(*_args, **kwargs)(f)
|
62
29
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
def current_context(ctx, output_format):
|
67
|
-
"""Get the current context"""
|
68
|
-
if output_format == 'name':
|
69
|
-
print(ctx.obj.current_context)
|
70
|
-
else:
|
71
|
-
if output_format == 'json':
|
72
|
-
print(json.dumps(ctx.obj.contexts[ctx.obj.current_context].to_serializable_dict()))
|
73
|
-
else:
|
74
|
-
print(yaml.safe_dump(ctx.obj.contexts[ctx.obj.current_context].to_serializable_dict()))
|
30
|
+
# for all of the aliased groups, share the main group commands
|
31
|
+
for aliased in aliased_group:
|
32
|
+
aliased.commands = grp.commands
|
75
33
|
|
34
|
+
return grp
|
76
35
|
|
77
|
-
|
78
|
-
@click.option(
|
79
|
-
'-o', '--output-format', default='wide', type=click.Choice(['wide', 'name', 'json', 'yaml']))
|
80
|
-
@click.pass_context
|
81
|
-
def get_contexts(ctx, output_format):
|
82
|
-
"""Get all contexts"""
|
83
|
-
if output_format == 'wide':
|
84
|
-
formatter = TableFormatter(custom_columns={
|
85
|
-
'': lambda c: '*' if c.name == ctx.obj.current_context else '',
|
86
|
-
'NAME': lambda c: c.name,
|
87
|
-
'USER_ID': lambda c: c.user_id,
|
88
|
-
'API_BASE': lambda c: c.api_base,
|
89
|
-
'PAT': lambda c: pat_display(c.pat),
|
90
|
-
})
|
91
|
-
print(formatter.format(ctx.obj.contexts.values(), fmt="plain"))
|
92
|
-
elif output_format == 'name':
|
93
|
-
print('\n'.join(ctx.obj.contexts))
|
94
|
-
elif output_format in ('json', 'yaml'):
|
95
|
-
dicts = [v.__dict__ for c, v in ctx.obj.contexts.items()]
|
96
|
-
for d in dicts:
|
97
|
-
d.pop('pat')
|
98
|
-
if output_format == 'json':
|
99
|
-
print(json.dumps(dicts))
|
100
|
-
elif output_format == 'yaml':
|
101
|
-
print(yaml.safe_dump(dicts))
|
36
|
+
return decorator
|
102
37
|
|
103
38
|
|
104
|
-
@
|
105
|
-
@click.argument('context-name', type=str)
|
39
|
+
@click.group(cls=CustomMultiGroup)
|
106
40
|
@click.pass_context
|
107
|
-
def
|
108
|
-
"""
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
print(f'Set {context_name} as the current context')
|
114
|
-
|
115
|
-
|
116
|
-
@config.command(['cat'])
|
117
|
-
@click.option('-o', '--output-format', default='yaml', type=click.Choice(['yaml', 'json']))
|
118
|
-
@click.pass_obj
|
119
|
-
def dump(ctx_obj, output_format):
|
120
|
-
"""Dump the configuration to stdout"""
|
121
|
-
if output_format == 'yaml':
|
122
|
-
yaml.safe_dump(ctx_obj.to_dict(), sys.stdout)
|
41
|
+
def cli(ctx):
|
42
|
+
"""Clarifai CLI"""
|
43
|
+
ctx.ensure_object(dict)
|
44
|
+
config_path = 'config.yaml'
|
45
|
+
if os.path.exists(config_path):
|
46
|
+
ctx.obj = from_yaml(config_path)
|
123
47
|
else:
|
124
|
-
|
48
|
+
ctx.obj = {}
|
125
49
|
|
126
50
|
|
127
51
|
@cli.command()
|
128
|
-
@click.
|
52
|
+
@click.option('--config', type=click.Path(), required=False, help='Path to the config file')
|
53
|
+
@click.option(
|
54
|
+
'-e',
|
55
|
+
'--env',
|
56
|
+
required=False,
|
57
|
+
help='Environment to use, choose from prod, staging and dev',
|
58
|
+
type=click.Choice(['prod', 'staging', 'dev']))
|
129
59
|
@click.option('--user_id', required=False, help='User ID')
|
130
60
|
@click.pass_context
|
131
|
-
def login(ctx,
|
61
|
+
def login(ctx, config, env, user_id):
|
132
62
|
"""Login command to set PAT and other configurations."""
|
133
63
|
|
134
|
-
|
135
|
-
|
136
|
-
pat = input_or_default(
|
137
|
-
'personal access token value (default: "ENVVAR" to get our of env var rather than config): ',
|
138
|
-
'ENVVAR')
|
139
|
-
|
140
|
-
context = Context(
|
141
|
-
name,
|
142
|
-
CLARIFAI_API_BASE=api_url,
|
143
|
-
CLARIFAI_USER_ID=user_id,
|
144
|
-
CLARIFAI_PAT=pat,
|
145
|
-
)
|
146
|
-
|
147
|
-
if context.name == '':
|
148
|
-
context.name = 'default'
|
149
|
-
|
150
|
-
ctx.obj.contexts[context.name] = context
|
151
|
-
ctx.obj.current_context = context.name
|
152
|
-
|
153
|
-
ctx.obj.to_yaml()
|
154
|
-
|
64
|
+
if config and os.path.exists(config):
|
65
|
+
ctx.obj = from_yaml(config)
|
155
66
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
pat=None,
|
196
|
-
):
|
197
|
-
"""Create a new context"""
|
198
|
-
if name in ctx.obj.contexts:
|
199
|
-
print(f'{name} already exists')
|
200
|
-
exit(1)
|
201
|
-
if not user_id:
|
202
|
-
user_id = input('user id: ')
|
203
|
-
if not base_url:
|
204
|
-
base_url = input_or_default('base url (default: https://api.clarifai.com): ',
|
205
|
-
'https://api.clarifai.com')
|
206
|
-
if not pat:
|
207
|
-
pat = input_or_default(
|
208
|
-
'personal access token value (default: "ENVVAR" to get our of env var rather than config): ',
|
209
|
-
'ENVVAR')
|
210
|
-
|
211
|
-
context = Context(name, CLARIFAI_USER_ID=user_id, CLARIFAI_API_BASE=base_url, CLARIFAI_PAT=pat)
|
212
|
-
ctx.obj.contexts[context.name] = context
|
213
|
-
ctx.obj.to_yaml()
|
214
|
-
|
215
|
-
|
216
|
-
# write a click command to delete a context
|
217
|
-
@context.command(['rm'])
|
218
|
-
@click.argument('name')
|
219
|
-
@click.pass_context
|
220
|
-
def delete(ctx, name):
|
221
|
-
"""Delete a context"""
|
222
|
-
if name not in ctx.obj.contexts:
|
223
|
-
print(f'{name} is not a valid context')
|
224
|
-
exit(1)
|
225
|
-
ctx.obj.contexts.pop(name)
|
226
|
-
ctx.obj.to_yaml()
|
227
|
-
print(f'{name} deleted')
|
228
|
-
|
229
|
-
|
230
|
-
@context.command()
|
231
|
-
@click.argument('name', type=str)
|
232
|
-
@click.pass_context
|
233
|
-
def use(ctx, name):
|
234
|
-
"""Set the current context"""
|
235
|
-
if name not in ctx.obj.contexts:
|
236
|
-
raise click.UsageError('Context not found')
|
237
|
-
ctx.obj.current_context = name
|
238
|
-
ctx.obj.to_yaml()
|
239
|
-
print(f'Set {name} as the current context')
|
240
|
-
|
241
|
-
|
242
|
-
@cli.command()
|
243
|
-
@click.argument('script', type=str)
|
244
|
-
@click.option('--context', type=str, help='Context to use')
|
245
|
-
@click.pass_context
|
246
|
-
def run(ctx, script, context=None):
|
247
|
-
"""Execute a script with the current context's environment"""
|
248
|
-
context = ctx.obj.current if not context else context
|
249
|
-
cmd = f'CLARIFAI_USER_ID={context.user_id} CLARIFAI_API_BASE={context.base_url} CLARIFAI_PAT={context.pat} '
|
250
|
-
cmd += ' '.join([f'{k}={v}' for k, v in context.env.items()])
|
251
|
-
cmd += f' {script}'
|
252
|
-
os.system(cmd)
|
67
|
+
if 'pat' in ctx.obj:
|
68
|
+
os.environ["CLARIFAI_PAT"] = ctx.obj['pat']
|
69
|
+
click.echo("Loaded PAT from config file.")
|
70
|
+
elif 'CLARIFAI_PAT' in os.environ:
|
71
|
+
ctx.obj['pat'] = os.environ["CLARIFAI_PAT"]
|
72
|
+
click.echo("Loaded PAT from environment variable.")
|
73
|
+
else:
|
74
|
+
_pat = click.prompt(
|
75
|
+
"Get your PAT from https://clarifai.com/settings/security and pass it here", type=str)
|
76
|
+
os.environ["CLARIFAI_PAT"] = _pat
|
77
|
+
ctx.obj['pat'] = _pat
|
78
|
+
click.echo("PAT saved successfully.")
|
79
|
+
|
80
|
+
if user_id:
|
81
|
+
ctx.obj['user_id'] = user_id
|
82
|
+
os.environ["CLARIFAI_USER_ID"] = ctx.obj['user_id']
|
83
|
+
elif 'user_id' in ctx.obj:
|
84
|
+
ctx.obj['user_id'] = ctx.obj.get('user_id', "")
|
85
|
+
os.environ["CLARIFAI_USER_ID"] = ctx.obj['user_id']
|
86
|
+
elif 'CLARIFAI_USER_ID' in os.environ:
|
87
|
+
ctx.obj['user_id'] = os.environ["CLARIFAI_USER_ID"]
|
88
|
+
else:
|
89
|
+
user_id = click.prompt("Pass the User ID here", type=str)
|
90
|
+
os.environ["CLARIFAI_USER_ID"] = user_id
|
91
|
+
ctx.obj['user_id'] = user_id
|
92
|
+
click.echo("User ID saved successfully.")
|
93
|
+
|
94
|
+
if env:
|
95
|
+
ctx.obj['env'] = env
|
96
|
+
ctx.obj['base_url'] = set_base_url(env)
|
97
|
+
os.environ["CLARIFAI_API_BASE"] = ctx.obj['base_url']
|
98
|
+
elif 'env' in ctx.obj:
|
99
|
+
ctx.obj['env'] = ctx.obj.get('env', "prod")
|
100
|
+
ctx.obj['base_url'] = set_base_url(ctx.obj['env'])
|
101
|
+
os.environ["CLARIFAI_API_BASE"] = ctx.obj['base_url']
|
102
|
+
elif 'CLARIFAI_API_BASE' in os.environ:
|
103
|
+
ctx.obj['base_url'] = os.environ["CLARIFAI_API_BASE"]
|
104
|
+
|
105
|
+
dump_yaml(ctx.obj, 'config.yaml')
|
253
106
|
|
254
107
|
|
255
108
|
# Import the CLI commands to register them
|
clarifai/cli/compute_cluster.py
CHANGED
@@ -1,59 +1,51 @@
|
|
1
1
|
import click
|
2
|
-
|
3
2
|
from clarifai.cli.base import cli
|
4
3
|
from clarifai.client.user import User
|
5
|
-
from clarifai.utils.cli import
|
4
|
+
from clarifai.utils.cli import display_co_resources
|
6
5
|
|
7
6
|
|
8
|
-
@cli.group(['computecluster', 'cc']
|
7
|
+
@cli.group(['computecluster', 'cc'])
|
9
8
|
def computecluster():
|
10
9
|
"""Manage Compute Clusters: create, delete, list"""
|
10
|
+
pass
|
11
11
|
|
12
12
|
|
13
|
-
@computecluster.command(
|
14
|
-
@click.argument('compute_cluster_id')
|
13
|
+
@computecluster.command()
|
15
14
|
@click.option(
|
16
15
|
'--config',
|
17
16
|
type=click.Path(exists=True),
|
18
17
|
required=True,
|
19
18
|
help='Path to the compute cluster config file.')
|
19
|
+
@click.option(
|
20
|
+
'-cc_id',
|
21
|
+
'--compute_cluster_id',
|
22
|
+
required=False,
|
23
|
+
help='New Compute Cluster ID for the compute cluster to create.')
|
20
24
|
@click.pass_context
|
21
|
-
def create(ctx,
|
25
|
+
def create(ctx, config, compute_cluster_id):
|
22
26
|
"""Create a new Compute Cluster with the given config file."""
|
23
|
-
|
24
|
-
user = User(
|
25
|
-
user_id=ctx.obj.current.user_id, pat=ctx.obj.current.pat, base_url=ctx.obj.current.api_base)
|
27
|
+
user = User(user_id=ctx.obj['user_id'], pat=ctx.obj['pat'], base_url=ctx.obj['base_url'])
|
26
28
|
if compute_cluster_id:
|
27
29
|
user.create_compute_cluster(config, compute_cluster_id=compute_cluster_id)
|
28
30
|
else:
|
29
31
|
user.create_compute_cluster(config)
|
30
32
|
|
31
33
|
|
32
|
-
@computecluster.command(
|
34
|
+
@computecluster.command()
|
33
35
|
@click.option('--page_no', required=False, help='Page number to list.', default=1)
|
34
36
|
@click.option('--per_page', required=False, help='Number of items per page.', default=16)
|
35
37
|
@click.pass_context
|
36
38
|
def list(ctx, page_no, per_page):
|
37
39
|
"""List all compute clusters for the user."""
|
38
|
-
|
39
|
-
user = User(
|
40
|
-
user_id=ctx.obj.current.user_id, pat=ctx.obj.current.pat, base_url=ctx.obj.current.api_base)
|
40
|
+
user = User(user_id=ctx.obj['user_id'], pat=ctx.obj['pat'], base_url=ctx.obj['base_url'])
|
41
41
|
response = user.list_compute_clusters(page_no, per_page)
|
42
|
-
display_co_resources(
|
43
|
-
response,
|
44
|
-
custom_columns={
|
45
|
-
'ID': lambda c: c.id,
|
46
|
-
'USER_ID': lambda c: c.user_id,
|
47
|
-
'DESCRIPTION': lambda c: c.description,
|
48
|
-
})
|
42
|
+
display_co_resources(response, "Compute Cluster")
|
49
43
|
|
50
44
|
|
51
|
-
@computecluster.command(
|
52
|
-
@click.
|
45
|
+
@computecluster.command()
|
46
|
+
@click.option('-cc_id', '--compute_cluster_id', help='Compute Cluster ID of the user to delete.')
|
53
47
|
@click.pass_context
|
54
48
|
def delete(ctx, compute_cluster_id):
|
55
49
|
"""Deletes a compute cluster for the user."""
|
56
|
-
|
57
|
-
user = User(
|
58
|
-
user_id=ctx.obj.current.user_id, pat=ctx.obj.current.pat, base_url=ctx.obj.current.api_base)
|
50
|
+
user = User(user_id=ctx.obj['user_id'], pat=ctx.obj['pat'], base_url=ctx.obj['base_url'])
|
59
51
|
user.delete_compute_clusters([compute_cluster_id])
|
clarifai/cli/deployment.py
CHANGED
@@ -1,110 +1,84 @@
|
|
1
1
|
import click
|
2
|
-
|
3
2
|
from clarifai.cli.base import cli
|
4
|
-
from clarifai.client.compute_cluster import ComputeCluster
|
5
3
|
from clarifai.client.nodepool import Nodepool
|
6
|
-
from clarifai.
|
7
|
-
from clarifai.utils.cli import AliasedGroup, display_co_resources, from_yaml, validate_context
|
4
|
+
from clarifai.utils.cli import display_co_resources, from_yaml
|
8
5
|
|
9
6
|
|
10
|
-
@cli.group(['deployment', '
|
7
|
+
@cli.group(['deployment', 'dpl'])
|
11
8
|
def deployment():
|
12
9
|
"""Manage Deployments: create, delete, list"""
|
10
|
+
pass
|
13
11
|
|
14
12
|
|
15
|
-
@deployment.command(
|
16
|
-
@click.
|
17
|
-
|
13
|
+
@deployment.command()
|
14
|
+
@click.option(
|
15
|
+
'-np_id',
|
16
|
+
'--nodepool_id',
|
17
|
+
required=False,
|
18
|
+
help='Nodepool ID for the Nodepool to interact with.')
|
18
19
|
@click.option(
|
19
20
|
'--config',
|
20
21
|
type=click.Path(exists=True),
|
21
22
|
required=True,
|
22
23
|
help='Path to the deployment config file.')
|
24
|
+
@click.option(
|
25
|
+
'-dpl_id',
|
26
|
+
'--deployment_id',
|
27
|
+
required=False,
|
28
|
+
help='New deployment ID for the deployment to create.')
|
23
29
|
@click.pass_context
|
24
|
-
def create(ctx, nodepool_id,
|
30
|
+
def create(ctx, nodepool_id, config, deployment_id):
|
25
31
|
"""Create a new Deployment with the given config file."""
|
26
|
-
|
27
|
-
validate_context(ctx)
|
28
32
|
if not nodepool_id:
|
29
33
|
deployment_config = from_yaml(config)
|
30
34
|
nodepool_id = deployment_config['deployment']['nodepools'][0]['id']
|
31
35
|
|
32
36
|
nodepool = Nodepool(
|
33
37
|
nodepool_id=nodepool_id,
|
34
|
-
user_id=ctx.obj
|
35
|
-
pat=ctx.obj
|
36
|
-
base_url=ctx.obj
|
38
|
+
user_id=ctx.obj['user_id'],
|
39
|
+
pat=ctx.obj['pat'],
|
40
|
+
base_url=ctx.obj['base_url'])
|
37
41
|
if deployment_id:
|
38
42
|
nodepool.create_deployment(config, deployment_id=deployment_id)
|
39
43
|
else:
|
40
44
|
nodepool.create_deployment(config)
|
41
45
|
|
42
46
|
|
43
|
-
@deployment.command(
|
44
|
-
@click.
|
47
|
+
@deployment.command()
|
48
|
+
@click.option(
|
49
|
+
'-np_id',
|
50
|
+
'--nodepool_id',
|
51
|
+
required=True,
|
52
|
+
help='Nodepool ID for the Nodepool to interact with.')
|
45
53
|
@click.option('--page_no', required=False, help='Page number to list.', default=1)
|
46
54
|
@click.option('--per_page', required=False, help='Number of items per page.', default=16)
|
47
55
|
@click.pass_context
|
48
56
|
def list(ctx, nodepool_id, page_no, per_page):
|
49
57
|
"""List all deployments for the nodepool."""
|
50
58
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
response = nodepool.list_deployments(page_no=page_no, per_page=per_page)
|
59
|
-
else:
|
60
|
-
user = User(
|
61
|
-
user_id=ctx.obj.current.user_id,
|
62
|
-
pat=ctx.obj.current.pat,
|
63
|
-
base_url=ctx.obj.current.api_base)
|
64
|
-
ccs = user.list_compute_clusters(page_no, per_page)
|
65
|
-
nps = []
|
66
|
-
for cc in ccs:
|
67
|
-
compute_cluster = ComputeCluster(
|
68
|
-
compute_cluster_id=cc.id,
|
69
|
-
user_id=ctx.obj.current.user_id,
|
70
|
-
pat=ctx.obj.current.pat,
|
71
|
-
base_url=ctx.obj.current.api_base)
|
72
|
-
nps.extend([i for i in compute_cluster.list_nodepools(page_no, per_page)])
|
73
|
-
response = []
|
74
|
-
for np in nps:
|
75
|
-
nodepool = Nodepool(
|
76
|
-
nodepool_id=np.id,
|
77
|
-
user_id=ctx.obj.current.user_id,
|
78
|
-
pat=ctx.obj.current.pat,
|
79
|
-
base_url=ctx.obj.current.api_base)
|
80
|
-
response.extend([i for i in nodepool.list_deployments(page_no=page_no, per_page=per_page)])
|
81
|
-
|
82
|
-
display_co_resources(
|
83
|
-
response,
|
84
|
-
custom_columns={
|
85
|
-
'ID': lambda c: c.id,
|
86
|
-
'USER_ID': lambda c: c.user_id,
|
87
|
-
'COMPUTE_CLUSTER_ID': lambda c: c.nodepools[0].compute_cluster.id,
|
88
|
-
'NODEPOOL_ID': lambda c: c.nodepools[0].id,
|
89
|
-
'MODEL_USER_ID': lambda c: c.worker.model.user_id,
|
90
|
-
'MODEL_APP_ID': lambda c: c.worker.model.app_id,
|
91
|
-
'MODEL_ID': lambda c: c.worker.model.id,
|
92
|
-
'MODEL_VERSION_ID': lambda c: c.worker.model.model_version.id,
|
93
|
-
'DESCRIPTION': lambda c: c.description,
|
94
|
-
})
|
59
|
+
nodepool = Nodepool(
|
60
|
+
nodepool_id=nodepool_id,
|
61
|
+
user_id=ctx.obj['user_id'],
|
62
|
+
pat=ctx.obj['pat'],
|
63
|
+
base_url=ctx.obj['base_url'])
|
64
|
+
response = nodepool.list_deployments(page_no=page_no, per_page=per_page)
|
65
|
+
display_co_resources(response, "Deployment")
|
95
66
|
|
96
67
|
|
97
|
-
@deployment.command(
|
98
|
-
@click.
|
99
|
-
|
68
|
+
@deployment.command()
|
69
|
+
@click.option(
|
70
|
+
'-np_id',
|
71
|
+
'--nodepool_id',
|
72
|
+
required=True,
|
73
|
+
help='Nodepool ID for the Nodepool to interact with.')
|
74
|
+
@click.option('-dpl_id', '--deployment_id', help='Deployment ID of the nodepool to delete.')
|
100
75
|
@click.pass_context
|
101
76
|
def delete(ctx, nodepool_id, deployment_id):
|
102
77
|
"""Deletes a deployment for the nodepool."""
|
103
78
|
|
104
|
-
validate_context(ctx)
|
105
79
|
nodepool = Nodepool(
|
106
80
|
nodepool_id=nodepool_id,
|
107
|
-
user_id=ctx.obj
|
108
|
-
pat=ctx.obj
|
109
|
-
base_url=ctx.obj
|
81
|
+
user_id=ctx.obj['user_id'],
|
82
|
+
pat=ctx.obj['pat'],
|
83
|
+
base_url=ctx.obj['base_url'])
|
110
84
|
nodepool.delete_deployments([deployment_id])
|