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/auth/register.py
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
import abc
|
2
|
-
import grpc
|
3
2
|
|
3
|
+
import grpc
|
4
4
|
from clarifai_grpc.grpc.api import service_pb2_grpc
|
5
5
|
|
6
6
|
|
7
7
|
class V2Stub(abc.ABC):
|
8
|
-
|
8
|
+
"""Abstract base class of clarifai api rpc client stubs"""
|
9
9
|
|
10
10
|
|
11
11
|
class RpcCallable(abc.ABC):
|
12
|
-
|
12
|
+
"""Abstract base class of clarifai api rpc callables"""
|
13
13
|
|
14
14
|
|
15
15
|
# add grpc classes as subclasses of the abcs, so they also succeed in isinstance calls
|
16
16
|
def _register_classes():
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
V2Stub.register(service_pb2_grpc.V2Stub)
|
18
|
+
for name in dir(grpc):
|
19
|
+
if name.endswith('Callable'):
|
20
|
+
RpcCallable.register(getattr(grpc, name))
|
21
21
|
|
22
22
|
|
23
23
|
_register_classes()
|
clarifai/client/auth/stub.py
CHANGED
@@ -8,6 +8,7 @@ from clarifai_grpc.grpc.api.status import status_code_pb2
|
|
8
8
|
from clarifai.client.auth.helper import ClarifaiAuthHelper
|
9
9
|
from clarifai.client.auth.register import RpcCallable, V2Stub
|
10
10
|
from clarifai.utils.logging import logger
|
11
|
+
|
11
12
|
throttle_status_codes = {
|
12
13
|
status_code_pb2.CONN_THROTTLED,
|
13
14
|
status_code_pb2.CONN_EXCEED_HOURLY_LIMIT,
|
@@ -21,134 +22,134 @@ _threadpool = ThreadPoolExecutor(100)
|
|
21
22
|
|
22
23
|
|
23
24
|
def validate_response(response, attempt, max_attempts):
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
25
|
+
# Helper function to handle simple response validation
|
26
|
+
def handle_simple_response(response):
|
27
|
+
if hasattr(response, 'status') and hasattr(response.status, 'code'):
|
28
|
+
if (response.status.code in throttle_status_codes) and attempt < max_attempts:
|
29
|
+
logger.debug('Retrying with status %s' % str(response.status))
|
30
|
+
return None # Indicates a retry is needed
|
31
|
+
else:
|
32
|
+
return response
|
33
|
+
|
34
|
+
# Check if the response is an instance of a gRPC streaming call
|
35
|
+
if isinstance(response, grpc._channel._MultiThreadedRendezvous):
|
36
|
+
try:
|
37
|
+
# Check just the first response in the stream for validation
|
38
|
+
first_res = next(response)
|
39
|
+
validated_response = handle_simple_response(first_res)
|
40
|
+
if validated_response is not None:
|
41
|
+
# Have to return that first response and the rest of the stream.
|
42
|
+
return itertools.chain([validated_response], response)
|
43
|
+
return None # Indicates a retry is needed
|
44
|
+
except grpc.RpcError as e:
|
45
|
+
logger.error('Error processing streaming response: %s' % str(e))
|
46
|
+
return None # Indicates an error
|
47
|
+
else:
|
48
|
+
# Handle simple response validation
|
49
|
+
return handle_simple_response(response)
|
49
50
|
|
50
51
|
|
51
52
|
def create_stub(auth_helper: ClarifaiAuthHelper = None, max_retry_attempts: int = 10) -> V2Stub:
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
"""
|
54
|
+
Create client stub that handles authorization and basic retries for
|
55
|
+
unavailable or throttled connections.
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
57
|
+
Args:
|
58
|
+
auth_helper: ClarifaiAuthHelper to use for auth metadata (default: from env)
|
59
|
+
max_retry_attempts: max attempts to retry rpcs with retryable failures
|
60
|
+
"""
|
61
|
+
stub = AuthorizedStub(auth_helper)
|
62
|
+
if max_retry_attempts > 0:
|
63
|
+
return RetryStub(stub, max_retry_attempts)
|
64
|
+
return stub
|
64
65
|
|
65
66
|
|
66
67
|
class AuthorizedStub(V2Stub):
|
67
|
-
|
68
|
+
"""V2Stub proxy that inserts metadata authorization in rpc calls."""
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
70
|
+
def __init__(self, auth_helper: ClarifaiAuthHelper = None):
|
71
|
+
if auth_helper is None:
|
72
|
+
auth_helper = ClarifaiAuthHelper.from_env()
|
73
|
+
self.stub = auth_helper.get_stub()
|
74
|
+
self.metadata = auth_helper.metadata
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
76
|
+
def __getattr__(self, name):
|
77
|
+
value = getattr(self.stub, name)
|
78
|
+
if isinstance(value, RpcCallable):
|
79
|
+
value = _AuthorizedRpcCallable(value, self.metadata)
|
80
|
+
return value
|
80
81
|
|
81
82
|
|
82
83
|
class _AuthorizedRpcCallable(RpcCallable):
|
83
|
-
|
84
|
+
"""Adds metadata(authorization header) to rpc calls"""
|
84
85
|
|
85
|
-
|
86
|
-
|
87
|
-
|
86
|
+
def __init__(self, func, metadata):
|
87
|
+
self.f = func
|
88
|
+
self.metadata = metadata
|
88
89
|
|
89
|
-
|
90
|
-
|
90
|
+
def __repr__(self):
|
91
|
+
return repr(self.f)
|
91
92
|
|
92
|
-
|
93
|
-
|
94
|
-
|
93
|
+
def __call__(self, *args, **kwargs):
|
94
|
+
metadata = kwargs.pop('metadata', self.metadata)
|
95
|
+
return self.f(*args, **kwargs, metadata=metadata)
|
95
96
|
|
96
|
-
|
97
|
-
|
98
|
-
|
97
|
+
def future(self, *args, **kwargs):
|
98
|
+
metadata = kwargs.pop('metadata', self.metadata)
|
99
|
+
return self.f.future(*args, **kwargs, metadata=metadata)
|
99
100
|
|
100
|
-
|
101
|
-
|
101
|
+
def __getattr__(self, name):
|
102
|
+
return getattr(self.f, name)
|
102
103
|
|
103
104
|
|
104
105
|
class RetryStub(V2Stub):
|
105
|
-
|
106
|
-
|
107
|
-
|
106
|
+
"""
|
107
|
+
V2Stub proxy that retries requests (currently on unavailable server or throttle codes)
|
108
|
+
"""
|
108
109
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
110
|
+
def __init__(self, stub, max_attempts=10, backoff_time=5):
|
111
|
+
self.stub = stub
|
112
|
+
self.max_attempts = max_attempts
|
113
|
+
self.backoff_time = backoff_time
|
113
114
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
115
|
+
def __getattr__(self, name):
|
116
|
+
value = getattr(self.stub, name)
|
117
|
+
if isinstance(value, RpcCallable):
|
118
|
+
value = _RetryRpcCallable(value, self.max_attempts, self.backoff_time)
|
119
|
+
return value
|
119
120
|
|
120
121
|
|
121
122
|
class _RetryRpcCallable(RpcCallable):
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
123
|
+
"""Retries rpc calls on unavailable server or throttle codes"""
|
124
|
+
|
125
|
+
def __init__(self, func, max_attempts, backoff_time):
|
126
|
+
self.f = func
|
127
|
+
self.max_attempts = max_attempts
|
128
|
+
self.backoff_time = backoff_time
|
129
|
+
|
130
|
+
def __repr__(self):
|
131
|
+
return repr(self.f)
|
132
|
+
|
133
|
+
def __call__(self, *args, **kwargs):
|
134
|
+
attempt = 0
|
135
|
+
while attempt < self.max_attempts:
|
136
|
+
attempt += 1
|
137
|
+
if attempt != 1:
|
138
|
+
time.sleep(self.backoff_time) # TODO better backoff between attempts
|
139
|
+
try:
|
140
|
+
response = self.f(*args, **kwargs)
|
141
|
+
v = validate_response(response, attempt, self.max_attempts)
|
142
|
+
if v is not None:
|
143
|
+
return v
|
144
|
+
except grpc.RpcError as e:
|
145
|
+
if (e.code() in retry_codes_grpc) and attempt < self.max_attempts:
|
146
|
+
logger.debug('Retrying with status %s' % e.code())
|
147
|
+
else:
|
148
|
+
raise
|
149
|
+
|
150
|
+
def future(self, *args, **kwargs):
|
151
|
+
# TODO use single result event loop thread with asyncio
|
152
|
+
return _threadpool.submit(self, *args, **kwargs)
|
153
|
+
|
154
|
+
def __getattr__(self, name):
|
155
|
+
return getattr(self.f, name)
|
clarifai/client/base.py
CHANGED
@@ -15,186 +15,193 @@ from clarifai.utils.misc import get_from_dict_or_env
|
|
15
15
|
|
16
16
|
|
17
17
|
class BaseClient:
|
18
|
-
|
19
|
-
|
20
|
-
Args:
|
21
|
-
**kwargs: Additional keyword arguments to be passed to the ClarifaiAuthHelper.
|
22
|
-
- user_id (str): A user ID for authentication.
|
23
|
-
- app_id (str): An app ID for the application to interact with.
|
24
|
-
- pat (str): A personal access token for authentication.
|
25
|
-
- token (str): A session token for authentication. Accepts either a session token or a pat.
|
26
|
-
- base (str): The base URL for the API endpoint. Defaults to 'https://api.clarifai.com'.
|
27
|
-
- ui (str): The URL for the UI. Defaults to 'https://clarifai.com'.
|
28
|
-
- root_certificates_path (str): Path to the SSL root certificates file, used to establish secure gRPC connections.
|
29
|
-
|
30
|
-
|
31
|
-
Attributes:
|
32
|
-
auth_helper (ClarifaiAuthHelper): An instance of ClarifaiAuthHelper for authentication.
|
33
|
-
STUB (Stub): The gRPC Stub object for API interaction.
|
34
|
-
metadata (tuple): The gRPC metadata containing the personal access token.
|
35
|
-
userDataObject (UserAppIDSet): The protobuf object representing user and app IDs.
|
36
|
-
base (str): The base URL for the API endpoint.
|
37
|
-
"""
|
38
|
-
|
39
|
-
def __init__(self, **kwargs):
|
40
|
-
token, pat = "", ""
|
41
|
-
try:
|
42
|
-
pat = get_from_dict_or_env(key="pat", env_key=CLARIFAI_PAT_ENV_VAR, **kwargs)
|
43
|
-
except UserError:
|
44
|
-
token = get_from_dict_or_env(key="token", env_key=CLARIFAI_SESSION_TOKEN_ENV_VAR, **kwargs)
|
45
|
-
finally:
|
46
|
-
assert token or pat, Exception(
|
47
|
-
"Need 'pat' or 'token' in args or use one of the CLARIFAI_PAT or CLARIFAI_SESSION_TOKEN env vars"
|
48
|
-
)
|
49
|
-
kwargs.update({'token': token, 'pat': pat})
|
50
|
-
|
51
|
-
self.auth_helper = ClarifaiAuthHelper(**kwargs, validate=False)
|
52
|
-
self.STUB = create_stub(self.auth_helper)
|
53
|
-
self.metadata = self.auth_helper.metadata
|
54
|
-
self.pat = self.auth_helper.pat
|
55
|
-
self.token = self.auth_helper._token
|
56
|
-
self.user_app_id = self.auth_helper.get_user_app_id_proto()
|
57
|
-
self.base = self.auth_helper.base
|
58
|
-
self.root_certificates_path = self.auth_helper._root_certificates_path
|
59
|
-
|
60
|
-
@classmethod
|
61
|
-
def from_env(cls, validate: bool = False):
|
62
|
-
auth = ClarifaiAuthHelper.from_env(validate=validate)
|
63
|
-
return cls.from_auth_helper(auth)
|
64
|
-
|
65
|
-
@classmethod
|
66
|
-
def from_auth_helper(cls, auth: ClarifaiAuthHelper, **kwargs):
|
67
|
-
default_kwargs = {
|
68
|
-
"user_id":
|
69
|
-
kwargs.get("user_id", None) or auth.user_id,
|
70
|
-
"app_id":
|
71
|
-
kwargs.get("app_id", None) or auth.app_id,
|
72
|
-
"pat":
|
73
|
-
kwargs.get("pat", None) or auth.pat,
|
74
|
-
"token":
|
75
|
-
kwargs.get("token", None) or auth._token,
|
76
|
-
"root_certificates_path":
|
77
|
-
kwargs.get("root_certificates_path", None) or auth._root_certificates_path
|
78
|
-
}
|
79
|
-
_base = kwargs.get("base", None) or auth.base
|
80
|
-
_clss = cls.__mro__[0]
|
81
|
-
if _clss == BaseClient:
|
82
|
-
kwargs = {
|
83
|
-
**default_kwargs,
|
84
|
-
"base": _base, # Baseclient uses `base`
|
85
|
-
"ui": kwargs.get("ui", None) or auth.ui
|
86
|
-
}
|
87
|
-
else:
|
88
|
-
# Remove user_id and app_id if a custom URL is provided
|
89
|
-
if kwargs.get("url"):
|
90
|
-
default_kwargs.pop("user_id", "")
|
91
|
-
default_kwargs.pop("app_id", "")
|
92
|
-
# Remove app_id if the class name is a compute orchestration resource
|
93
|
-
if any(co_resource in _clss.__name__ for co_resource in COMPUTE_ORCHESTRATION_RESOURCES):
|
94
|
-
default_kwargs.pop("app_id", "")
|
95
|
-
kwargs.update({**default_kwargs, "base_url": _base})
|
96
|
-
|
97
|
-
return cls(**kwargs)
|
98
|
-
|
99
|
-
def _grpc_request(self, method: Callable, argument: Any):
|
100
|
-
"""Makes a gRPC request to the API.
|
18
|
+
"""BaseClient is the base class for all the classes interacting with Clarifai endpoints.
|
101
19
|
|
102
20
|
Args:
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
Args:
|
121
|
-
date_str (str): The string to convert.
|
122
|
-
|
123
|
-
Returns:
|
124
|
-
Timestamp: The converted Timestamp object.
|
21
|
+
**kwargs: Additional keyword arguments to be passed to the ClarifaiAuthHelper.
|
22
|
+
- user_id (str): A user ID for authentication.
|
23
|
+
- app_id (str): An app ID for the application to interact with.
|
24
|
+
- pat (str): A personal access token for authentication.
|
25
|
+
- token (str): A session token for authentication. Accepts either a session token or a pat.
|
26
|
+
- base (str): The base URL for the API endpoint. Defaults to 'https://api.clarifai.com'.
|
27
|
+
- ui (str): The URL for the UI. Defaults to 'https://clarifai.com'.
|
28
|
+
- root_certificates_path (str): Path to the SSL root certificates file, used to establish secure gRPC connections.
|
29
|
+
|
30
|
+
|
31
|
+
Attributes:
|
32
|
+
auth_helper (ClarifaiAuthHelper): An instance of ClarifaiAuthHelper for authentication.
|
33
|
+
STUB (Stub): The gRPC Stub object for API interaction.
|
34
|
+
metadata (tuple): The gRPC metadata containing the personal access token.
|
35
|
+
userDataObject (UserAppIDSet): The protobuf object representing user and app IDs.
|
36
|
+
base (str): The base URL for the API endpoint.
|
125
37
|
"""
|
126
|
-
# Parse the string into a Python datetime object
|
127
|
-
try:
|
128
|
-
datetime_obj = datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S.%fZ')
|
129
|
-
except ValueError:
|
130
|
-
try:
|
131
|
-
datetime_obj = datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%SZ')
|
132
|
-
except ValueError:
|
133
|
-
return Timestamp()
|
134
38
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
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
|
-
if
|
187
|
-
|
188
|
-
|
189
|
-
|
39
|
+
def __init__(self, **kwargs):
|
40
|
+
token, pat = "", ""
|
41
|
+
try:
|
42
|
+
pat = get_from_dict_or_env(key="pat", env_key=CLARIFAI_PAT_ENV_VAR, **kwargs)
|
43
|
+
except UserError:
|
44
|
+
token = get_from_dict_or_env(
|
45
|
+
key="token", env_key=CLARIFAI_SESSION_TOKEN_ENV_VAR, **kwargs
|
46
|
+
)
|
47
|
+
finally:
|
48
|
+
assert token or pat, Exception(
|
49
|
+
"Need 'pat' or 'token' in args or use one of the CLARIFAI_PAT or CLARIFAI_SESSION_TOKEN env vars"
|
50
|
+
)
|
51
|
+
kwargs.update({'token': token, 'pat': pat})
|
52
|
+
|
53
|
+
self.auth_helper = ClarifaiAuthHelper(**kwargs, validate=False)
|
54
|
+
self.STUB = create_stub(self.auth_helper)
|
55
|
+
self.metadata = self.auth_helper.metadata
|
56
|
+
self.pat = self.auth_helper.pat
|
57
|
+
self.token = self.auth_helper._token
|
58
|
+
self.user_app_id = self.auth_helper.get_user_app_id_proto()
|
59
|
+
self.base = self.auth_helper.base
|
60
|
+
self.root_certificates_path = self.auth_helper._root_certificates_path
|
61
|
+
|
62
|
+
@classmethod
|
63
|
+
def from_env(cls, validate: bool = False):
|
64
|
+
auth = ClarifaiAuthHelper.from_env(validate=validate)
|
65
|
+
return cls.from_auth_helper(auth)
|
66
|
+
|
67
|
+
@classmethod
|
68
|
+
def from_auth_helper(cls, auth: ClarifaiAuthHelper, **kwargs):
|
69
|
+
default_kwargs = {
|
70
|
+
"user_id": kwargs.get("user_id", None) or auth.user_id,
|
71
|
+
"app_id": kwargs.get("app_id", None) or auth.app_id,
|
72
|
+
"pat": kwargs.get("pat", None) or auth.pat,
|
73
|
+
"token": kwargs.get("token", None) or auth._token,
|
74
|
+
"root_certificates_path": kwargs.get("root_certificates_path", None)
|
75
|
+
or auth._root_certificates_path,
|
76
|
+
}
|
77
|
+
_base = kwargs.get("base", None) or auth.base
|
78
|
+
_clss = cls.__mro__[0]
|
79
|
+
if _clss == BaseClient:
|
80
|
+
kwargs = {
|
81
|
+
**default_kwargs,
|
82
|
+
"base": _base, # Baseclient uses `base`
|
83
|
+
"ui": kwargs.get("ui", None) or auth.ui,
|
84
|
+
}
|
85
|
+
else:
|
86
|
+
# Remove user_id and app_id if a custom URL is provided
|
87
|
+
if kwargs.get("url"):
|
88
|
+
default_kwargs.pop("user_id", "")
|
89
|
+
default_kwargs.pop("app_id", "")
|
90
|
+
# Remove app_id if the class name is a compute orchestration resource
|
91
|
+
if any(
|
92
|
+
co_resource in _clss.__name__ for co_resource in COMPUTE_ORCHESTRATION_RESOURCES
|
93
|
+
):
|
94
|
+
default_kwargs.pop("app_id", "")
|
95
|
+
kwargs.update({**default_kwargs, "base_url": _base})
|
96
|
+
|
97
|
+
return cls(**kwargs)
|
98
|
+
|
99
|
+
def _grpc_request(self, method: Callable, argument: Any):
|
100
|
+
"""Makes a gRPC request to the API.
|
101
|
+
|
102
|
+
Args:
|
103
|
+
method (Callable): The gRPC method to call.
|
104
|
+
argument (Any): The argument to pass to the gRPC method.
|
105
|
+
|
106
|
+
Returns:
|
107
|
+
res (Any): The result of the gRPC method call.
|
108
|
+
"""
|
109
|
+
|
110
|
+
try:
|
111
|
+
res = method(argument, metadata=self.auth_helper.metadata)
|
112
|
+
# MessageToDict(res) TODO global debug logger
|
113
|
+
return res
|
114
|
+
except ApiError:
|
115
|
+
raise Exception("ApiError")
|
116
|
+
|
117
|
+
def convert_string_to_timestamp(self, date_str) -> Timestamp:
|
118
|
+
"""Converts a string to a Timestamp object.
|
119
|
+
|
120
|
+
Args:
|
121
|
+
date_str (str): The string to convert.
|
122
|
+
|
123
|
+
Returns:
|
124
|
+
Timestamp: The converted Timestamp object.
|
125
|
+
"""
|
126
|
+
# Parse the string into a Python datetime object
|
127
|
+
try:
|
128
|
+
datetime_obj = datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S.%fZ')
|
129
|
+
except ValueError:
|
130
|
+
try:
|
131
|
+
datetime_obj = datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%SZ')
|
132
|
+
except ValueError:
|
133
|
+
return Timestamp()
|
134
|
+
|
135
|
+
# Convert the datetime object to a Timestamp object
|
136
|
+
timestamp_obj = Timestamp()
|
137
|
+
timestamp_obj.FromDatetime(datetime_obj)
|
138
|
+
|
139
|
+
return timestamp_obj
|
140
|
+
|
141
|
+
def process_response_keys(self, old_dict, listing_resource=None):
|
142
|
+
"""Converts keys in a response dictionary to resource proto format.
|
143
|
+
|
144
|
+
Args:
|
145
|
+
old_dict (dict): The dictionary to convert.
|
146
|
+
listing_resource (str, optional): The resource type for which the keys are being processed.
|
147
|
+
|
148
|
+
Returns:
|
149
|
+
new_dict (dict): The dictionary with processed keys.
|
150
|
+
"""
|
151
|
+
if listing_resource:
|
152
|
+
old_dict[f'{listing_resource}_id'] = old_dict['id']
|
153
|
+
old_dict.pop('id')
|
154
|
+
|
155
|
+
def convert_recursive(item):
|
156
|
+
if isinstance(item, dict):
|
157
|
+
new_item = {}
|
158
|
+
for key, value in item.items():
|
159
|
+
if key == 'default_value':
|
160
|
+
# Map infer param value to proto value
|
161
|
+
value_map = dict(number_value=None, string_value=None, bool_value=None)
|
162
|
+
|
163
|
+
def map_fn(v):
|
164
|
+
return (
|
165
|
+
'number_value'
|
166
|
+
if isinstance(v, float) or isinstance(v, int)
|
167
|
+
else 'string_value'
|
168
|
+
if isinstance(v, str)
|
169
|
+
else 'bool_value'
|
170
|
+
if isinstance(v, bool)
|
171
|
+
else None
|
172
|
+
)
|
173
|
+
|
174
|
+
value_map[map_fn(value)] = value
|
175
|
+
value = struct_pb2.Value(**value_map)
|
176
|
+
if key in ['created_at', 'modified_at', 'completed_at']:
|
177
|
+
value = self.convert_string_to_timestamp(value)
|
178
|
+
elif key in ['workflow_recommended', 'is_template']:
|
179
|
+
value = BoolValue(value=True)
|
180
|
+
elif key in ['fields_map', 'params']:
|
181
|
+
value_s = struct_pb2.Struct()
|
182
|
+
value_s.update(value)
|
183
|
+
value = value_s
|
184
|
+
elif key == 'metrics':
|
185
|
+
continue
|
186
|
+
elif key == 'size':
|
187
|
+
value = int(value)
|
188
|
+
elif key == 'image_info':
|
189
|
+
value = resources_pb2.ImageInfo(**value)
|
190
|
+
elif key == 'hosted_image_info':
|
191
|
+
continue
|
192
|
+
elif key in ['metadata', 'presets']:
|
193
|
+
if isinstance(value, dict) and value != {}:
|
194
|
+
value_s = struct_pb2.Struct()
|
195
|
+
value_s.update(value)
|
196
|
+
value = value_s
|
197
|
+
else:
|
198
|
+
continue
|
199
|
+
new_item[key] = convert_recursive(value)
|
200
|
+
return new_item
|
201
|
+
elif isinstance(item, list):
|
202
|
+
return [convert_recursive(element) for element in item]
|
190
203
|
else:
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
return [convert_recursive(element) for element in item]
|
196
|
-
else:
|
197
|
-
return item
|
198
|
-
|
199
|
-
new_dict = convert_recursive(old_dict)
|
200
|
-
return new_dict
|
204
|
+
return item
|
205
|
+
|
206
|
+
new_dict = convert_recursive(old_dict)
|
207
|
+
return new_dict
|