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/client/user.py
CHANGED
@@ -16,419 +16,424 @@ from clarifai.utils.logging import logger
|
|
16
16
|
|
17
17
|
|
18
18
|
class User(Lister, BaseClient):
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
19
|
+
"""User is a class that provides access to Clarifai API endpoints related to user information."""
|
20
|
+
|
21
|
+
def __init__(
|
22
|
+
self,
|
23
|
+
user_id: str = None,
|
24
|
+
base_url: str = "https://api.clarifai.com",
|
25
|
+
pat: str = None,
|
26
|
+
token: str = None,
|
27
|
+
root_certificates_path: str = None,
|
28
|
+
**kwargs,
|
29
|
+
):
|
30
|
+
"""Initializes an User object.
|
31
|
+
|
32
|
+
Args:
|
33
|
+
user_id (str): The user ID for the user to interact with.
|
34
|
+
base_url (str): Base API url. Default "https://api.clarifai.com"
|
35
|
+
pat (str): A personal access token for authentication. Can be set as env var CLARIFAI_PAT
|
36
|
+
token (str): A session token for authentication. Accepts either a session token or a pat. Can be set as env var CLARIFAI_SESSION_TOKEN
|
37
|
+
root_certificates_path (str): Path to the SSL root certificates file, used to establish secure gRPC connections.
|
38
|
+
**kwargs: Additional keyword arguments to be passed to the User.
|
39
|
+
"""
|
40
|
+
self.kwargs = {**kwargs, 'id': user_id}
|
41
|
+
self.user_info = resources_pb2.User(**self.kwargs)
|
42
|
+
self.logger = logger
|
43
|
+
BaseClient.__init__(
|
44
|
+
self,
|
45
|
+
user_id=self.id,
|
46
|
+
app_id="",
|
47
|
+
base=base_url,
|
48
|
+
pat=pat,
|
49
|
+
token=token,
|
50
|
+
root_certificates_path=root_certificates_path,
|
51
|
+
)
|
52
|
+
Lister.__init__(self)
|
53
|
+
|
54
|
+
def list_apps(
|
55
|
+
self, filter_by: Dict[str, Any] = {}, page_no: int = None, per_page: int = None
|
56
|
+
) -> Generator[App, None, None]:
|
57
|
+
"""Lists all the apps for the user.
|
58
|
+
|
59
|
+
Args:
|
60
|
+
filter_by (dict): A dictionary of filters to be applied to the list of apps.
|
61
|
+
page_no (int): The page number to list.
|
62
|
+
per_page (int): The number of items per page.
|
63
|
+
|
64
|
+
Yields:
|
65
|
+
App: App objects for the user.
|
66
|
+
|
67
|
+
Example:
|
68
|
+
>>> from clarifai.client.user import User
|
69
|
+
>>> apps = list(User("user_id").list_apps())
|
70
|
+
|
71
|
+
Note:
|
72
|
+
Defaults to 16 per page if page_no is specified and per_page is not specified.
|
73
|
+
If both page_no and per_page are None, then lists all the resources.
|
74
|
+
"""
|
75
|
+
request_data = dict(user_app_id=self.user_app_id, **filter_by)
|
76
|
+
all_apps_info = self.list_pages_generator(
|
77
|
+
self.STUB.ListApps,
|
78
|
+
service_pb2.ListAppsRequest,
|
79
|
+
request_data,
|
80
|
+
per_page=per_page,
|
81
|
+
page_no=page_no,
|
82
|
+
)
|
83
|
+
for app_info in all_apps_info:
|
84
|
+
yield App.from_auth_helper(
|
85
|
+
self.auth_helper, **app_info
|
86
|
+
) # (base_url=self.base, pat=self.pat, token=self.token, **app_info)
|
87
|
+
|
88
|
+
def list_runners(
|
89
|
+
self, filter_by: Dict[str, Any] = {}, page_no: int = None, per_page: int = None
|
90
|
+
) -> Generator[dict, None, None]:
|
91
|
+
"""List all runners for the user
|
92
|
+
|
93
|
+
Args:
|
94
|
+
filter_by (dict): A dictionary of filters to apply to the list of runners.
|
95
|
+
page_no (int): The page number to list.
|
96
|
+
per_page (int): The number of items per page.
|
97
|
+
|
98
|
+
Yields:
|
99
|
+
Dict: Dictionaries containing information about the runners.
|
100
|
+
|
101
|
+
Example:
|
102
|
+
>>> from clarifai.client.user import User
|
103
|
+
>>> client = User(user_id="user_id")
|
104
|
+
>>> all_runners= list(client.list_runners())
|
105
|
+
|
106
|
+
Note:
|
107
|
+
Defaults to 16 per page if page_no is specified and per_page is not specified.
|
108
|
+
If both page_no and per_page are None, then lists all the resources.
|
109
|
+
"""
|
110
|
+
request_data = dict(user_app_id=self.user_app_id, **filter_by)
|
111
|
+
all_runners_info = self.list_pages_generator(
|
112
|
+
self.STUB.ListRunners,
|
113
|
+
service_pb2.ListRunnersRequest,
|
114
|
+
request_data,
|
115
|
+
per_page=per_page,
|
116
|
+
page_no=page_no,
|
117
|
+
)
|
118
|
+
|
119
|
+
for runner_info in all_runners_info:
|
120
|
+
yield dict(auth=self.auth_helper, check_runner_exists=False, **runner_info)
|
121
|
+
|
122
|
+
def list_compute_clusters(
|
123
|
+
self, page_no: int = None, per_page: int = None
|
124
|
+
) -> Generator[dict, None, None]:
|
125
|
+
"""List all compute clusters for the user
|
126
|
+
|
127
|
+
Args:
|
128
|
+
page_no (int): The page number to list.
|
129
|
+
per_page (int): The number of items per page.
|
130
|
+
|
131
|
+
Yields:
|
132
|
+
Dict: Dictionaries containing information about the compute clusters.
|
133
|
+
|
134
|
+
Example:
|
135
|
+
>>> from clarifai.client.user import User
|
136
|
+
>>> client = User(user_id="user_id")
|
137
|
+
>>> all_compute_clusters= list(client.list_compute_clusters())
|
138
|
+
|
139
|
+
Note:
|
140
|
+
Defaults to 16 per page if page_no is specified and per_page is not specified.
|
141
|
+
If both page_no and per_page are None, then lists all the resources.
|
142
|
+
"""
|
143
|
+
request_data = dict(user_app_id=self.user_app_id)
|
144
|
+
all_compute_clusters_info = self.list_pages_generator(
|
145
|
+
self.STUB.ListComputeClusters,
|
146
|
+
service_pb2.ListComputeClustersRequest,
|
147
|
+
request_data,
|
148
|
+
per_page=per_page,
|
149
|
+
page_no=page_no,
|
150
|
+
)
|
151
|
+
|
152
|
+
for compute_cluster_info in all_compute_clusters_info:
|
153
|
+
yield ComputeCluster.from_auth_helper(self.auth_helper, **compute_cluster_info)
|
154
|
+
|
155
|
+
def create_app(self, app_id: str, base_workflow: str = 'Empty', **kwargs) -> App:
|
156
|
+
"""Creates an app for the user.
|
157
|
+
|
158
|
+
Args:
|
159
|
+
app_id (str): The app ID for the app to create.
|
160
|
+
base_workflow (str): The base workflow to use for the app.(Examples: 'Universal', 'Language-Understanding', 'General')
|
161
|
+
**kwargs: Additional keyword arguments to be passed to the App.
|
162
|
+
|
163
|
+
Returns:
|
164
|
+
App: An App object for the specified app ID.
|
165
|
+
|
166
|
+
Example:
|
167
|
+
>>> from clarifai.client.user import User
|
168
|
+
>>> client = User(user_id="user_id")
|
169
|
+
>>> app = client.create_app(app_id="app_id",base_workflow="Universal")
|
170
|
+
"""
|
171
|
+
workflow = resources_pb2.Workflow(id=base_workflow, app_id="main", user_id="clarifai")
|
172
|
+
request = service_pb2.PostAppsRequest(
|
173
|
+
user_app_id=self.user_app_id,
|
174
|
+
apps=[resources_pb2.App(id=app_id, default_workflow=workflow, **kwargs)],
|
175
|
+
)
|
176
|
+
response = self._grpc_request(self.STUB.PostApps, request)
|
177
|
+
if response.status.code != status_code_pb2.SUCCESS:
|
178
|
+
raise Exception(response.status)
|
179
|
+
self.logger.info("\nApp created\n%s", response.status)
|
180
|
+
return App.from_auth_helper(auth=self.auth_helper, app_id=app_id)
|
181
|
+
|
182
|
+
def _process_compute_cluster_config(
|
183
|
+
self, compute_cluster_config: Dict[str, Any]
|
184
|
+
) -> Dict[str, Any]:
|
185
|
+
assert "compute_cluster" in compute_cluster_config, (
|
186
|
+
"compute cluster info not found in the config file"
|
187
|
+
)
|
188
|
+
compute_cluster = compute_cluster_config['compute_cluster']
|
189
|
+
assert "region" in compute_cluster, "region not found in the config file"
|
190
|
+
assert "managed_by" in compute_cluster, "managed_by not found in the config file"
|
191
|
+
assert "cluster_type" in compute_cluster, "cluster_type not found in the config file"
|
192
|
+
compute_cluster['cloud_provider'] = resources_pb2.CloudProvider(
|
193
|
+
**compute_cluster['cloud_provider']
|
194
|
+
)
|
195
|
+
compute_cluster['key'] = resources_pb2.Key(id=self.pat)
|
196
|
+
if "visibility" in compute_cluster:
|
197
|
+
compute_cluster["visibility"] = resources_pb2.Visibility(
|
198
|
+
**compute_cluster["visibility"]
|
199
|
+
)
|
200
|
+
return compute_cluster
|
201
|
+
|
202
|
+
def create_compute_cluster(
|
42
203
|
self,
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
-
yield ComputeCluster.from_auth_helper(self.auth_helper, **compute_cluster_info)
|
145
|
-
|
146
|
-
def create_app(self, app_id: str, base_workflow: str = 'Empty', **kwargs) -> App:
|
147
|
-
"""Creates an app for the user.
|
148
|
-
|
149
|
-
Args:
|
150
|
-
app_id (str): The app ID for the app to create.
|
151
|
-
base_workflow (str): The base workflow to use for the app.(Examples: 'Universal', 'Language-Understanding', 'General')
|
152
|
-
**kwargs: Additional keyword arguments to be passed to the App.
|
153
|
-
|
154
|
-
Returns:
|
155
|
-
App: An App object for the specified app ID.
|
156
|
-
|
157
|
-
Example:
|
158
|
-
>>> from clarifai.client.user import User
|
159
|
-
>>> client = User(user_id="user_id")
|
160
|
-
>>> app = client.create_app(app_id="app_id",base_workflow="Universal")
|
161
|
-
"""
|
162
|
-
workflow = resources_pb2.Workflow(id=base_workflow, app_id="main", user_id="clarifai")
|
163
|
-
request = service_pb2.PostAppsRequest(
|
164
|
-
user_app_id=self.user_app_id,
|
165
|
-
apps=[resources_pb2.App(id=app_id, default_workflow=workflow, **kwargs)])
|
166
|
-
response = self._grpc_request(self.STUB.PostApps, request)
|
167
|
-
if response.status.code != status_code_pb2.SUCCESS:
|
168
|
-
raise Exception(response.status)
|
169
|
-
self.logger.info("\nApp created\n%s", response.status)
|
170
|
-
return App.from_auth_helper(auth=self.auth_helper, app_id=app_id)
|
171
|
-
|
172
|
-
def create_runner(self, runner_id: str, labels: List[str], description: str) -> dict:
|
173
|
-
"""Create a runner
|
174
|
-
|
175
|
-
Args:
|
176
|
-
runner_id (str): The Id of runner to create
|
177
|
-
labels (List[str]): Labels to match runner
|
178
|
-
description (str): Description of Runner
|
179
|
-
|
180
|
-
Returns:
|
181
|
-
Dict: A dictionary containing information about the specified Runner ID.
|
182
|
-
|
183
|
-
Example:
|
184
|
-
>>> from clarifai.client.user import User
|
185
|
-
>>> client = User(user_id="user_id")
|
186
|
-
>>> runner_info = client.create_runner(runner_id="runner_id", labels=["label to link runner"], description="laptop runner")
|
187
|
-
"""
|
188
|
-
|
189
|
-
if not isinstance(labels, List):
|
190
|
-
raise UserError("Labels must be a List of strings")
|
191
|
-
|
192
|
-
request = service_pb2.PostRunnersRequest(
|
193
|
-
user_app_id=self.user_app_id,
|
194
|
-
runners=[resources_pb2.Runner(id=runner_id, labels=labels, description=description)])
|
195
|
-
response = self._grpc_request(self.STUB.PostRunners, request)
|
196
|
-
|
197
|
-
if response.status.code != status_code_pb2.SUCCESS:
|
198
|
-
raise Exception(response.status)
|
199
|
-
self.logger.info("\nRunner created\n%s", response.status)
|
200
|
-
|
201
|
-
return dict(
|
202
|
-
auth=self.auth_helper,
|
203
|
-
runner_id=runner_id,
|
204
|
-
user_id=self.id,
|
205
|
-
labels=labels,
|
206
|
-
description=description,
|
207
|
-
check_runner_exists=False)
|
208
|
-
|
209
|
-
def _process_compute_cluster_config(self, config_filepath: str) -> Dict[str, Any]:
|
210
|
-
with open(config_filepath, "r") as file:
|
211
|
-
compute_cluster_config = yaml.safe_load(file)
|
212
|
-
|
213
|
-
assert "compute_cluster" in compute_cluster_config, "compute cluster info not found in the config file"
|
214
|
-
compute_cluster = compute_cluster_config['compute_cluster']
|
215
|
-
assert "region" in compute_cluster, "region not found in the config file"
|
216
|
-
assert "managed_by" in compute_cluster, "managed_by not found in the config file"
|
217
|
-
assert "cluster_type" in compute_cluster, "cluster_type not found in the config file"
|
218
|
-
compute_cluster['cloud_provider'] = resources_pb2.CloudProvider(
|
219
|
-
**compute_cluster['cloud_provider'])
|
220
|
-
compute_cluster['key'] = resources_pb2.Key(id=self.pat)
|
221
|
-
if "visibility" in compute_cluster:
|
222
|
-
compute_cluster["visibility"] = resources_pb2.Visibility(**compute_cluster["visibility"])
|
223
|
-
return compute_cluster
|
224
|
-
|
225
|
-
def create_compute_cluster(self, config_filepath: str,
|
226
|
-
compute_cluster_id: str = None) -> ComputeCluster:
|
227
|
-
"""Creates a compute cluster for the user.
|
228
|
-
|
229
|
-
Args:
|
230
|
-
config_filepath (str): The path to the compute cluster config file.
|
231
|
-
compute_cluster_id (str): New compute cluster ID for the compute cluster to create.
|
232
|
-
|
233
|
-
Returns:
|
234
|
-
ComputeCluster: A Compute Cluster object for the specified compute cluster ID.
|
235
|
-
|
236
|
-
Example:
|
237
|
-
>>> from clarifai.client.user import User
|
238
|
-
>>> client = User(user_id="user_id")
|
239
|
-
>>> compute_cluster = client.create_compute_cluster(config_filepath="config.yml")
|
240
|
-
"""
|
241
|
-
if not os.path.exists(config_filepath):
|
242
|
-
raise UserError(f"Compute Cluster config file not found at {config_filepath}")
|
243
|
-
|
244
|
-
compute_cluster_config = self._process_compute_cluster_config(config_filepath)
|
245
|
-
|
246
|
-
if 'id' in compute_cluster_config:
|
247
|
-
if compute_cluster_id is None:
|
248
|
-
compute_cluster_id = compute_cluster_config['id']
|
249
|
-
compute_cluster_config.pop('id')
|
250
|
-
|
251
|
-
request = service_pb2.PostComputeClustersRequest(
|
252
|
-
user_app_id=self.user_app_id,
|
253
|
-
compute_clusters=[
|
254
|
-
resources_pb2.ComputeCluster(id=compute_cluster_id, **compute_cluster_config)
|
255
|
-
])
|
256
|
-
response = self._grpc_request(self.STUB.PostComputeClusters, request)
|
257
|
-
if response.status.code != status_code_pb2.SUCCESS:
|
258
|
-
raise Exception(response.status)
|
259
|
-
self.logger.info("\nCompute Cluster created\n%s", response.status)
|
260
|
-
return ComputeCluster.from_auth_helper(
|
261
|
-
auth=self.auth_helper, compute_cluster_id=compute_cluster_id)
|
262
|
-
|
263
|
-
def app(self, app_id: str, **kwargs) -> App:
|
264
|
-
"""Returns an App object for the specified app ID.
|
265
|
-
|
266
|
-
Args:
|
267
|
-
app_id (str): The app ID for the app to interact with.
|
268
|
-
**kwargs: Additional keyword arguments to be passed to the App.
|
269
|
-
|
270
|
-
Returns:
|
271
|
-
App: An App object for the specified app ID.
|
272
|
-
|
273
|
-
Example:
|
274
|
-
>>> from clarifai.client.user import User
|
275
|
-
>>> app = User("user_id").app("app_id")
|
276
|
-
"""
|
277
|
-
request = service_pb2.GetAppRequest(
|
278
|
-
user_app_id=resources_pb2.UserAppIDSet(user_id=self.id, app_id=app_id))
|
279
|
-
response = self._grpc_request(self.STUB.GetApp, request)
|
280
|
-
if response.status.code != status_code_pb2.SUCCESS:
|
281
|
-
raise Exception(response.status)
|
282
|
-
|
283
|
-
kwargs['user_id'] = self.id
|
284
|
-
return App.from_auth_helper(auth=self.auth_helper, app_id=app_id, **kwargs)
|
285
|
-
|
286
|
-
def runner(self, runner_id: str) -> dict:
|
287
|
-
"""Returns a Runner object if exists.
|
288
|
-
|
289
|
-
Args:
|
290
|
-
runner_id (str): The runner ID to interact with
|
291
|
-
|
292
|
-
Returns:
|
293
|
-
Dict: A dictionary containing information about the existing runner ID.
|
294
|
-
|
295
|
-
Example:
|
296
|
-
>>> from clarifai.client.user import User
|
297
|
-
>>> client = User(user_id="user_id")
|
298
|
-
>>> runner_info = client.runner(runner_id="runner_id")
|
299
|
-
"""
|
300
|
-
request = service_pb2.GetRunnerRequest(user_app_id=self.user_app_id, runner_id=runner_id)
|
301
|
-
response = self._grpc_request(self.STUB.GetRunner, request)
|
302
|
-
if response.status.code != status_code_pb2.SUCCESS:
|
303
|
-
raise Exception(
|
304
|
-
f"""Error getting runner, are you use this is a valid runner id {runner_id} at the user_id/app_id
|
204
|
+
config_filepath: str = None,
|
205
|
+
compute_cluster_id: str = None,
|
206
|
+
compute_cluster_config: Dict[str, Any] = None,
|
207
|
+
) -> ComputeCluster:
|
208
|
+
"""Creates a compute cluster for the user.
|
209
|
+
|
210
|
+
Args:
|
211
|
+
config_filepath (str): The path to the compute cluster config file.
|
212
|
+
compute_cluster_id (str): New compute cluster ID for the compute cluster to create.
|
213
|
+
compute_cluster_config (Dict[str, Any]): Optional dictionary containing compute cluster configuration.
|
214
|
+
|
215
|
+
Returns:
|
216
|
+
ComputeCluster: A Compute Cluster object for the specified compute cluster ID.
|
217
|
+
|
218
|
+
Example:
|
219
|
+
>>> from clarifai.client.user import User
|
220
|
+
>>> client = User(user_id="user_id")
|
221
|
+
>>> compute_cluster = client.create_compute_cluster(config_filepath="config.yml")
|
222
|
+
"""
|
223
|
+
|
224
|
+
if config_filepath is not None:
|
225
|
+
assert compute_cluster_config is None, (
|
226
|
+
"Either config_filepath or compute_cluster_config should be provided, not both."
|
227
|
+
)
|
228
|
+
if not os.path.exists(config_filepath):
|
229
|
+
raise UserError(f"Compute Cluster config file not found at {config_filepath}")
|
230
|
+
with open(config_filepath, "r") as f:
|
231
|
+
compute_cluster_config = yaml.safe_load(f)
|
232
|
+
elif compute_cluster_config is not None:
|
233
|
+
assert isinstance(compute_cluster_config, dict), (
|
234
|
+
"compute_cluster_config should be a dictionary if provided."
|
235
|
+
)
|
236
|
+
else:
|
237
|
+
raise AssertionError(
|
238
|
+
"Either config_filepath or compute_cluster_config should be provided."
|
239
|
+
)
|
240
|
+
|
241
|
+
compute_cluster_config = self._process_compute_cluster_config(compute_cluster_config)
|
242
|
+
|
243
|
+
if 'id' in compute_cluster_config:
|
244
|
+
if compute_cluster_id is None:
|
245
|
+
compute_cluster_id = compute_cluster_config['id']
|
246
|
+
compute_cluster_config.pop('id')
|
247
|
+
|
248
|
+
request = service_pb2.PostComputeClustersRequest(
|
249
|
+
user_app_id=self.user_app_id,
|
250
|
+
compute_clusters=[
|
251
|
+
resources_pb2.ComputeCluster(id=compute_cluster_id, **compute_cluster_config)
|
252
|
+
],
|
253
|
+
)
|
254
|
+
response = self._grpc_request(self.STUB.PostComputeClusters, request)
|
255
|
+
if response.status.code != status_code_pb2.SUCCESS:
|
256
|
+
raise Exception(response.status)
|
257
|
+
self.logger.info("\nCompute Cluster created\n%s", response.status)
|
258
|
+
return ComputeCluster.from_auth_helper(
|
259
|
+
auth=self.auth_helper, compute_cluster_id=compute_cluster_id
|
260
|
+
)
|
261
|
+
|
262
|
+
def app(self, app_id: str, **kwargs) -> App:
|
263
|
+
"""Returns an App object for the specified app ID.
|
264
|
+
|
265
|
+
Args:
|
266
|
+
app_id (str): The app ID for the app to interact with.
|
267
|
+
**kwargs: Additional keyword arguments to be passed to the App.
|
268
|
+
|
269
|
+
Returns:
|
270
|
+
App: An App object for the specified app ID.
|
271
|
+
|
272
|
+
Example:
|
273
|
+
>>> from clarifai.client.user import User
|
274
|
+
>>> app = User("user_id").app("app_id")
|
275
|
+
"""
|
276
|
+
request = service_pb2.GetAppRequest(
|
277
|
+
user_app_id=resources_pb2.UserAppIDSet(user_id=self.id, app_id=app_id)
|
278
|
+
)
|
279
|
+
response = self._grpc_request(self.STUB.GetApp, request)
|
280
|
+
if response.status.code != status_code_pb2.SUCCESS:
|
281
|
+
raise Exception(response.status)
|
282
|
+
|
283
|
+
kwargs['user_id'] = self.id
|
284
|
+
return App.from_auth_helper(auth=self.auth_helper, app_id=app_id, **kwargs)
|
285
|
+
|
286
|
+
def runner(self, runner_id: str) -> dict:
|
287
|
+
"""Returns a Runner object if exists.
|
288
|
+
|
289
|
+
Args:
|
290
|
+
runner_id (str): The runner ID to interact with
|
291
|
+
|
292
|
+
Returns:
|
293
|
+
Dict: A dictionary containing information about the existing runner ID.
|
294
|
+
|
295
|
+
Example:
|
296
|
+
>>> from clarifai.client.user import User
|
297
|
+
>>> client = User(user_id="user_id")
|
298
|
+
>>> runner_info = client.runner(runner_id="runner_id")
|
299
|
+
"""
|
300
|
+
request = service_pb2.GetRunnerRequest(user_app_id=self.user_app_id, runner_id=runner_id)
|
301
|
+
response = self._grpc_request(self.STUB.GetRunner, request)
|
302
|
+
if response.status.code != status_code_pb2.SUCCESS:
|
303
|
+
raise Exception(
|
304
|
+
f"""Error getting runner, are you use this is a valid runner id {runner_id} at the user_id/app_id
|
305
305
|
{self.user_app_id.user_id}/{self.user_app_id.app_id}.
|
306
|
-
Error: {response.status.description}"""
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
306
|
+
Error: {response.status.description}"""
|
307
|
+
)
|
308
|
+
|
309
|
+
dict_response = MessageToDict(response, preserving_proto_field_name=True)
|
310
|
+
kwargs = self.process_response_keys(dict_response["runner"], "runner")
|
311
|
+
|
312
|
+
return dict(self.auth_helper, check_runner_exists=False, **kwargs)
|
313
|
+
|
314
|
+
def compute_cluster(self, compute_cluster_id: str) -> ComputeCluster:
|
315
|
+
"""Returns an Compute Cluster object for the specified compute cluster ID.
|
316
|
+
|
317
|
+
Args:
|
318
|
+
compute_cluster_id (str): The compute cluster ID for the compute cluster to interact with.
|
319
|
+
|
320
|
+
Returns:
|
321
|
+
ComputeCluster: A Compute Cluster object for the specified compute cluster ID.
|
322
|
+
|
323
|
+
Example:
|
324
|
+
>>> from clarifai.client.user import User
|
325
|
+
>>> compute_cluster = User("user_id").compute_cluster("compute_cluster_id")
|
326
|
+
"""
|
327
|
+
request = service_pb2.GetComputeClusterRequest(
|
328
|
+
user_app_id=self.user_app_id, compute_cluster_id=compute_cluster_id
|
329
|
+
)
|
330
|
+
response = self._grpc_request(self.STUB.GetComputeCluster, request)
|
331
|
+
if response.status.code != status_code_pb2.SUCCESS:
|
332
|
+
raise Exception(response.status)
|
333
|
+
|
334
|
+
dict_response = MessageToDict(response, preserving_proto_field_name=True)
|
335
|
+
kwargs = self.process_response_keys(dict_response["compute_cluster"], "compute_cluster")
|
336
|
+
|
337
|
+
return ComputeCluster.from_auth_helper(auth=self.auth_helper, **kwargs)
|
338
|
+
|
339
|
+
def patch_app(self, app_id: str, action: str = 'overwrite', **kwargs) -> App:
|
340
|
+
"""Patch an app for the user.
|
341
|
+
|
342
|
+
Args:
|
343
|
+
app_id (str): The app ID for the app to patch.
|
344
|
+
action (str): The action to perform on the app (overwrite/remove).
|
345
|
+
**kwargs: Additional keyword arguments to be passed to patch the App.
|
346
|
+
|
347
|
+
Returns:
|
348
|
+
App: Patched App object for the specified app ID.
|
349
|
+
"""
|
350
|
+
if "base_workflow" in kwargs:
|
351
|
+
kwargs["default_workflow"] = resources_pb2.Workflow(
|
352
|
+
id=kwargs.pop("base_workflow"), app_id="main", user_id="clarifai"
|
353
|
+
)
|
354
|
+
if "visibility" in kwargs:
|
355
|
+
kwargs["visibility"] = resources_pb2.Visibility(gettable=kwargs["visibility"])
|
356
|
+
if "image_url" in kwargs:
|
357
|
+
kwargs["image"] = resources_pb2.Image(url=kwargs.pop("image_url"))
|
358
|
+
if "is_template" in kwargs:
|
359
|
+
kwargs["is_template"] = BoolValue(value=kwargs["is_template"])
|
360
|
+
request = service_pb2.PatchAppRequest(
|
361
|
+
user_app_id=resources_pb2.UserAppIDSet(user_id=self.id, app_id=app_id),
|
362
|
+
app=resources_pb2.App(id=app_id, **kwargs),
|
363
|
+
action=action,
|
364
|
+
reindex=False,
|
365
|
+
)
|
366
|
+
response = self._grpc_request(self.STUB.PatchApp, request)
|
367
|
+
if response.status.code != status_code_pb2.SUCCESS:
|
368
|
+
raise Exception(response.status)
|
369
|
+
self.logger.info("\nApp patched\n%s", response.status)
|
370
|
+
|
371
|
+
return App.from_auth_helper(auth=self.auth_helper, app_id=app_id)
|
372
|
+
|
373
|
+
def delete_app(self, app_id: str) -> None:
|
374
|
+
"""Deletes an app for the user.
|
375
|
+
|
376
|
+
Args:
|
377
|
+
app_id (str): The app ID for the app to delete.
|
378
|
+
|
379
|
+
Example:
|
380
|
+
>>> from clarifai.client.user import User
|
381
|
+
>>> user = User("user_id").delete_app("app_id")
|
382
|
+
"""
|
383
|
+
request = service_pb2.DeleteAppRequest(
|
384
|
+
user_app_id=resources_pb2.UserAppIDSet(user_id=self.id, app_id=app_id)
|
385
|
+
)
|
386
|
+
response = self._grpc_request(self.STUB.DeleteApp, request)
|
387
|
+
if response.status.code != status_code_pb2.SUCCESS:
|
388
|
+
raise Exception(response.status)
|
389
|
+
self.logger.info("\nApp Deleted\n%s", response.status)
|
390
|
+
|
391
|
+
def delete_runner(self, runner_id: str) -> None:
|
392
|
+
"""Deletes all spectified runner ids
|
393
|
+
|
394
|
+
Args:
|
395
|
+
runner_ids (str): List of runners to delete
|
396
|
+
|
397
|
+
Example:
|
398
|
+
>>> from clarifai.client.user import User
|
399
|
+
>>> client = User(user_id="user_id")
|
400
|
+
>>> client.delete_runner(runner_id="runner_id")
|
401
|
+
"""
|
402
|
+
request = service_pb2.DeleteRunnersRequest(user_app_id=self.user_app_id, ids=[runner_id])
|
403
|
+
response = self._grpc_request(self.STUB.DeleteRunners, request)
|
404
|
+
|
405
|
+
if response.status.code != status_code_pb2.SUCCESS:
|
406
|
+
raise Exception(response.status)
|
407
|
+
self.logger.info("\nRunner Deleted\n%s", response.status)
|
408
|
+
|
409
|
+
def delete_compute_clusters(self, compute_cluster_ids: List[str]) -> None:
|
410
|
+
"""Deletes a list of compute clusters for the user.
|
411
|
+
|
412
|
+
Args:
|
413
|
+
compute_cluster_ids (List[str]): The compute cluster IDs of the user to delete.
|
414
|
+
|
415
|
+
Example:
|
416
|
+
>>> from clarifai.client.user import User
|
417
|
+
>>> user = User("user_id").delete_compute_clusters(compute_cluster_ids=["compute_cluster_id1", "compute_cluster_id2"])
|
418
|
+
"""
|
419
|
+
assert isinstance(compute_cluster_ids, list), "compute_cluster_ids param should be a list"
|
420
|
+
|
421
|
+
request = service_pb2.DeleteComputeClustersRequest(
|
422
|
+
user_app_id=self.user_app_id, ids=compute_cluster_ids
|
423
|
+
)
|
424
|
+
response = self._grpc_request(self.STUB.DeleteComputeClusters, request)
|
425
|
+
if response.status.code != status_code_pb2.SUCCESS:
|
426
|
+
raise Exception(response.status)
|
427
|
+
self.logger.info("\nCompute Cluster Deleted\n%s", response.status)
|
428
|
+
|
429
|
+
def __getattr__(self, name):
|
430
|
+
return getattr(self.user_info, name)
|
431
|
+
|
432
|
+
def __str__(self):
|
433
|
+
init_params = [param for param in self.kwargs.keys()]
|
434
|
+
attribute_strings = [
|
435
|
+
f"{param}={getattr(self.user_info, param)}"
|
436
|
+
for param in init_params
|
437
|
+
if hasattr(self.user_info, param)
|
438
|
+
]
|
439
|
+
return f"Clarifai User Details: \n{', '.join(attribute_strings)}\n"
|