clarifai 11.8.1__py3-none-any.whl → 11.8.3__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/model.py +105 -38
- clarifai/cli/pipeline.py +84 -6
- clarifai/cli/templates/model_templates.py +1 -1
- clarifai/client/base.py +54 -16
- clarifai/client/dataset.py +18 -6
- clarifai/client/model.py +23 -13
- clarifai/client/model_client.py +2 -0
- clarifai/client/module.py +14 -13
- clarifai/client/nodepool.py +3 -1
- clarifai/client/pipeline.py +23 -23
- clarifai/client/pipeline_step.py +20 -18
- clarifai/client/search.py +35 -11
- clarifai/client/user.py +180 -5
- clarifai/client/workflow.py +18 -17
- clarifai/runners/models/model_builder.py +149 -17
- clarifai/runners/pipeline_steps/pipeline_step_builder.py +97 -1
- clarifai/runners/pipelines/pipeline_builder.py +196 -34
- clarifai/runners/server.py +1 -0
- clarifai/runners/utils/code_script.py +12 -1
- clarifai/utils/cli.py +62 -0
- clarifai/utils/constants.py +5 -3
- clarifai/utils/hashing.py +117 -0
- clarifai/utils/secrets.py +7 -2
- {clarifai-11.8.1.dist-info → clarifai-11.8.3.dist-info}/METADATA +4 -3
- {clarifai-11.8.1.dist-info → clarifai-11.8.3.dist-info}/RECORD +30 -29
- {clarifai-11.8.1.dist-info → clarifai-11.8.3.dist-info}/WHEEL +0 -0
- {clarifai-11.8.1.dist-info → clarifai-11.8.3.dist-info}/entry_points.txt +0 -0
- {clarifai-11.8.1.dist-info → clarifai-11.8.3.dist-info}/licenses/LICENSE +0 -0
- {clarifai-11.8.1.dist-info → clarifai-11.8.3.dist-info}/top_level.txt +0 -0
clarifai/client/module.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import Dict, Generator
|
1
|
+
from typing import Dict, Generator, Optional
|
2
2
|
|
3
3
|
from clarifai_grpc.grpc.api import resources_pb2, service_pb2
|
4
4
|
|
@@ -15,25 +15,26 @@ class Module(Lister, BaseClient):
|
|
15
15
|
|
16
16
|
def __init__(
|
17
17
|
self,
|
18
|
-
url: str = None,
|
19
|
-
module_id: str = None,
|
20
|
-
module_version: Dict = {'id': ""},
|
18
|
+
url: Optional[str] = None,
|
19
|
+
module_id: Optional[str] = None,
|
20
|
+
module_version: Dict[str, str] = {'id': ""},
|
21
21
|
base_url: str = DEFAULT_BASE,
|
22
|
-
pat: str = None,
|
23
|
-
token: str = None,
|
24
|
-
root_certificates_path: str = None,
|
22
|
+
pat: Optional[str] = None,
|
23
|
+
token: Optional[str] = None,
|
24
|
+
root_certificates_path: Optional[str] = None,
|
25
25
|
**kwargs,
|
26
26
|
):
|
27
27
|
"""Initializes a Module object.
|
28
28
|
|
29
29
|
Args:
|
30
|
-
url (str): The URL to initialize the module object.
|
31
|
-
module_id (str): The Module ID to interact with.
|
32
|
-
module_version (
|
30
|
+
url (Optional[str]): The URL to initialize the module object.
|
31
|
+
module_id (Optional[str]): The Module ID to interact with.
|
32
|
+
module_version (Dict[str, str]): The Module Version to interact with.
|
33
|
+
Defaults to {'id': ""} for latest version.
|
33
34
|
base_url (str): Base API url. Default "https://api.clarifai.com"
|
34
|
-
pat (str): A personal access token for authentication. Can be set as env var CLARIFAI_PAT.
|
35
|
-
token (str): A session token for authentication. Accepts either a session token or a pat. Can be set as env var CLARIFAI_SESSION_TOKEN.
|
36
|
-
root_certificates_path (str): Path to the SSL root certificates file, used to establish secure gRPC connections.
|
35
|
+
pat (Optional[str]): A personal access token for authentication. Can be set as env var CLARIFAI_PAT.
|
36
|
+
token (Optional[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 (Optional[str]): Path to the SSL root certificates file, used to establish secure gRPC connections.
|
37
38
|
**kwargs: Additional keyword arguments to be passed to the Module.
|
38
39
|
"""
|
39
40
|
if url and module_id:
|
clarifai/client/nodepool.py
CHANGED
@@ -334,7 +334,9 @@ class Nodepool(Lister, BaseClient):
|
|
334
334
|
f"Runner with ID '{response.runners[0].id}' is created:\n{response.status}"
|
335
335
|
)
|
336
336
|
|
337
|
-
dict_response = MessageToDict(
|
337
|
+
dict_response = MessageToDict(
|
338
|
+
response.runners[0], preserving_proto_field_name=True, use_integers_for_enums=True
|
339
|
+
)
|
338
340
|
kwargs = self.process_response_keys(dict_response, 'runner')
|
339
341
|
return Runner.from_auth_helper(auth=self.auth_helper, **kwargs)
|
340
342
|
|
clarifai/client/pipeline.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import time
|
2
2
|
import uuid
|
3
|
-
from typing import Dict, List
|
3
|
+
from typing import Dict, List, Optional
|
4
4
|
|
5
5
|
from clarifai_grpc.grpc.api import resources_pb2, service_pb2
|
6
6
|
from clarifai_grpc.grpc.api.status import status_code_pb2
|
@@ -19,35 +19,35 @@ class Pipeline(Lister, BaseClient):
|
|
19
19
|
|
20
20
|
def __init__(
|
21
21
|
self,
|
22
|
-
url: str = None,
|
23
|
-
pipeline_id: str = None,
|
24
|
-
pipeline_version_id: str = None,
|
25
|
-
pipeline_version_run_id: str = None,
|
26
|
-
user_id: str = None,
|
27
|
-
app_id: str = None,
|
28
|
-
nodepool_id: str = None,
|
29
|
-
compute_cluster_id: str = None,
|
30
|
-
log_file: str = None,
|
22
|
+
url: Optional[str] = None,
|
23
|
+
pipeline_id: Optional[str] = None,
|
24
|
+
pipeline_version_id: Optional[str] = None,
|
25
|
+
pipeline_version_run_id: Optional[str] = None,
|
26
|
+
user_id: Optional[str] = None,
|
27
|
+
app_id: Optional[str] = None,
|
28
|
+
nodepool_id: Optional[str] = None,
|
29
|
+
compute_cluster_id: Optional[str] = None,
|
30
|
+
log_file: Optional[str] = None,
|
31
31
|
base_url: str = DEFAULT_BASE,
|
32
|
-
pat: str = None,
|
33
|
-
token: str = None,
|
34
|
-
root_certificates_path: str = None,
|
32
|
+
pat: Optional[str] = None,
|
33
|
+
token: Optional[str] = None,
|
34
|
+
root_certificates_path: Optional[str] = None,
|
35
35
|
**kwargs,
|
36
36
|
):
|
37
37
|
"""Initializes a Pipeline object.
|
38
38
|
|
39
39
|
Args:
|
40
|
-
url (str): The URL to initialize the pipeline object.
|
41
|
-
pipeline_id (str): The Pipeline ID to interact with.
|
42
|
-
pipeline_version_id (str): The Pipeline Version ID to interact with.
|
43
|
-
pipeline_version_run_id (str): The Pipeline Version Run ID. If not provided, a UUID will be generated.
|
44
|
-
user_id (str): The User ID that owns the pipeline.
|
45
|
-
app_id (str): The App ID that contains the pipeline.
|
46
|
-
nodepool_id (str): The Nodepool ID to run the pipeline on.
|
47
|
-
compute_cluster_id (str): The Compute Cluster ID to run the pipeline on.
|
48
|
-
log_file (str): Path to file where logs should be written. If not provided, logs are displayed on console.
|
40
|
+
url (Optional[str]): The URL to initialize the pipeline object.
|
41
|
+
pipeline_id (Optional[str]): The Pipeline ID to interact with.
|
42
|
+
pipeline_version_id (Optional[str]): The Pipeline Version ID to interact with.
|
43
|
+
pipeline_version_run_id (Optional[str]): The Pipeline Version Run ID. If not provided, a UUID will be generated.
|
44
|
+
user_id (Optional[str]): The User ID that owns the pipeline.
|
45
|
+
app_id (Optional[str]): The App ID that contains the pipeline.
|
46
|
+
nodepool_id (Optional[str]): The Nodepool ID to run the pipeline on.
|
47
|
+
compute_cluster_id (Optional[str]): The Compute Cluster ID to run the pipeline on.
|
48
|
+
log_file (Optional[str]): Path to file where logs should be written. If not provided, logs are displayed on console.
|
49
49
|
base_url (str): Base API url. Default "https://api.clarifai.com"
|
50
|
-
pat (str): A personal access token for authentication. Can be set as env var CLARIFAI_PAT
|
50
|
+
pat (Optional[str]): A personal access token for authentication. Can be set as env var CLARIFAI_PAT
|
51
51
|
token (str): A session token for authentication. Accepts either a session token or a pat. Can be set as env var CLARIFAI_SESSION_TOKEN
|
52
52
|
root_certificates_path (str): Path to the SSL root certificates file, used to establish secure gRPC connections.
|
53
53
|
**kwargs: Additional keyword arguments to be passed to the Pipeline.
|
clarifai/client/pipeline_step.py
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
from typing import Optional
|
2
|
+
|
1
3
|
from clarifai.client.base import BaseClient
|
2
4
|
from clarifai.client.lister import Lister
|
3
5
|
from clarifai.urls.helper import ClarifaiUrlHelper
|
@@ -9,31 +11,31 @@ class PipelineStep(Lister, BaseClient):
|
|
9
11
|
|
10
12
|
def __init__(
|
11
13
|
self,
|
12
|
-
url: str = None,
|
13
|
-
pipeline_step_id: str = None,
|
14
|
-
pipeline_step_version_id: str = None,
|
15
|
-
user_id: str = None,
|
16
|
-
app_id: str = None,
|
17
|
-
pipeline_id: str = None,
|
14
|
+
url: Optional[str] = None,
|
15
|
+
pipeline_step_id: Optional[str] = None,
|
16
|
+
pipeline_step_version_id: Optional[str] = None,
|
17
|
+
user_id: Optional[str] = None,
|
18
|
+
app_id: Optional[str] = None,
|
19
|
+
pipeline_id: Optional[str] = None,
|
18
20
|
base_url: str = DEFAULT_BASE,
|
19
|
-
pat: str = None,
|
20
|
-
token: str = None,
|
21
|
-
root_certificates_path: str = None,
|
21
|
+
pat: Optional[str] = None,
|
22
|
+
token: Optional[str] = None,
|
23
|
+
root_certificates_path: Optional[str] = None,
|
22
24
|
**kwargs,
|
23
25
|
):
|
24
26
|
"""Initializes a PipelineStep object.
|
25
27
|
|
26
28
|
Args:
|
27
|
-
url (str): The URL to initialize the pipeline step object.
|
28
|
-
pipeline_step_id (str): The PipelineStep ID for the PipelineStep to interact with.
|
29
|
-
pipeline_step_version_id (str): The PipelineStep version ID for the PipelineStep to interact with.
|
30
|
-
user_id (str): The User ID for the PipelineStep to interact with.
|
31
|
-
app_id (str): The App ID for the PipelineStep to interact with.
|
32
|
-
pipeline_id (str): The Pipeline ID for the PipelineStep to interact with.
|
29
|
+
url (Optional[str]): The URL to initialize the pipeline step object.
|
30
|
+
pipeline_step_id (Optional[str]): The PipelineStep ID for the PipelineStep to interact with.
|
31
|
+
pipeline_step_version_id (Optional[str]): The PipelineStep version ID for the PipelineStep to interact with.
|
32
|
+
user_id (Optional[str]): The User ID for the PipelineStep to interact with.
|
33
|
+
app_id (Optional[str]): The App ID for the PipelineStep to interact with.
|
34
|
+
pipeline_id (Optional[str]): The Pipeline ID for the PipelineStep to interact with.
|
33
35
|
base_url (str): Base API url. Default "https://api.clarifai.com"
|
34
|
-
pat (str): A personal access token for authentication.
|
35
|
-
token (str): A session token for authentication.
|
36
|
-
root_certificates_path (str): Path to the SSL root certificates file.
|
36
|
+
pat (Optional[str]): A personal access token for authentication.
|
37
|
+
token (Optional[str]): A session token for authentication.
|
38
|
+
root_certificates_path (Optional[str]): Path to the SSL root certificates file.
|
37
39
|
**kwargs: Additional keyword arguments to be passed to the BaseClient.
|
38
40
|
"""
|
39
41
|
if url:
|
clarifai/client/search.py
CHANGED
@@ -91,14 +91,21 @@ class Search(Lister, BaseClient):
|
|
91
91
|
)
|
92
92
|
Lister.__init__(self, page_size=1000)
|
93
93
|
|
94
|
-
def _get_annot_proto(self, **kwargs):
|
94
|
+
def _get_annot_proto(self, **kwargs) -> resources_pb2.Annotation:
|
95
95
|
"""Get an Annotation proto message based on keyword arguments.
|
96
96
|
|
97
97
|
Args:
|
98
|
-
**kwargs: Keyword arguments specifying the
|
98
|
+
**kwargs: Keyword arguments specifying the annotation data.
|
99
|
+
Supported keys:
|
100
|
+
- image_bytes (bytes): Raw image bytes
|
101
|
+
- image_url (str): URL to an image
|
102
|
+
- concepts (List[Dict]): List of concept dictionaries
|
103
|
+
- metadata (Dict): Metadata dictionary
|
104
|
+
- geo_longitude (float): Geographic longitude
|
105
|
+
- geo_latitude (float): Geographic latitude
|
99
106
|
|
100
107
|
Returns:
|
101
|
-
resources_pb2.Annotation: An Annotation proto message.
|
108
|
+
resources_pb2.Annotation: An Annotation proto message with the specified data.
|
102
109
|
"""
|
103
110
|
if not kwargs:
|
104
111
|
return resources_pb2.Annotation()
|
@@ -139,14 +146,24 @@ class Search(Lister, BaseClient):
|
|
139
146
|
raise UserError(f"kwargs contain key that is not supported: {key}")
|
140
147
|
return resources_pb2.Annotation(data=self.data_proto)
|
141
148
|
|
142
|
-
def _get_input_proto(self, **kwargs):
|
149
|
+
def _get_input_proto(self, **kwargs) -> resources_pb2.Input:
|
143
150
|
"""Get an Input proto message based on keyword arguments.
|
144
151
|
|
145
152
|
Args:
|
146
|
-
**kwargs: Keyword arguments specifying the
|
153
|
+
**kwargs: Keyword arguments specifying the input data.
|
154
|
+
Supported keys:
|
155
|
+
- input_types (List[str]): List of input types ('image', 'text', 'audio', 'video')
|
156
|
+
- dataset_ids (List[str]): List of dataset IDs to filter by
|
157
|
+
- image_bytes (bytes): Raw image bytes
|
158
|
+
- image_url (str): URL to an image
|
159
|
+
- text_raw (str): Raw text content
|
160
|
+
- concepts (List[Dict]): List of concept dictionaries
|
161
|
+
- metadata (Dict): Metadata dictionary
|
162
|
+
- geo_longitude (float): Geographic longitude
|
163
|
+
- geo_latitude (float): Geographic latitude
|
147
164
|
|
148
165
|
Returns:
|
149
|
-
resources_pb2.Input: An Input proto message.
|
166
|
+
resources_pb2.Input: An Input proto message with the specified data.
|
150
167
|
"""
|
151
168
|
if not kwargs:
|
152
169
|
return resources_pb2.Input()
|
@@ -194,15 +211,22 @@ class Search(Lister, BaseClient):
|
|
194
211
|
def _list_topk_generator(
|
195
212
|
self, endpoint: Callable[..., Any], proto_message: Any, request_data: Dict[str, Any]
|
196
213
|
) -> Generator[Dict[str, Any], None, None]:
|
197
|
-
"""Lists
|
214
|
+
"""Lists top-k results with pagination support.
|
215
|
+
|
216
|
+
This method handles pagination for search results when top_k is specified,
|
217
|
+
automatically calculating the required number of pages and per-page limits.
|
198
218
|
|
199
219
|
Args:
|
200
|
-
endpoint (Callable): The endpoint to call.
|
201
|
-
proto_message (Any): The
|
202
|
-
request_data (
|
220
|
+
endpoint (Callable[..., Any]): The gRPC endpoint method to call for search.
|
221
|
+
proto_message (Any): The protobuf message class for the request.
|
222
|
+
request_data (Dict[str, Any]): The base request data dictionary.
|
203
223
|
|
204
224
|
Yields:
|
205
|
-
|
225
|
+
Dict[str, Any]: Individual search result items from the API response.
|
226
|
+
|
227
|
+
Raises:
|
228
|
+
UserError: If pagination limits are exceeded or top_k is too large.
|
229
|
+
Exception: If the API request fails.
|
206
230
|
"""
|
207
231
|
max_pages = ceil(self.top_k / self.default_page_size)
|
208
232
|
total_hits = 0
|
clarifai/client/user.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import os
|
2
|
-
from typing import Any, Dict, Generator, List
|
2
|
+
from typing import Any, Dict, Generator, List, Optional
|
3
3
|
|
4
4
|
import yaml
|
5
5
|
from clarifai_grpc.grpc.api import resources_pb2, service_pb2
|
@@ -53,14 +53,17 @@ class User(Lister, BaseClient):
|
|
53
53
|
Lister.__init__(self)
|
54
54
|
|
55
55
|
def list_apps(
|
56
|
-
self,
|
56
|
+
self,
|
57
|
+
filter_by: Dict[str, Any] = {},
|
58
|
+
page_no: Optional[int] = None,
|
59
|
+
per_page: Optional[int] = None,
|
57
60
|
) -> Generator[App, None, None]:
|
58
61
|
"""Lists all the apps for the user.
|
59
62
|
|
60
63
|
Args:
|
61
|
-
filter_by (
|
62
|
-
page_no (int): The page number to list.
|
63
|
-
per_page (int): The number of items per page.
|
64
|
+
filter_by (Dict[str, Any]): A dictionary of filters to be applied to the list of apps.
|
65
|
+
page_no (Optional[int]): The page number to list. If None, lists all pages.
|
66
|
+
per_page (Optional[int]): The number of items per page. If None, uses default.
|
64
67
|
|
65
68
|
Yields:
|
66
69
|
App: App objects for the user.
|
@@ -533,6 +536,178 @@ class User(Lister, BaseClient):
|
|
533
536
|
]
|
534
537
|
return f"Clarifai User Details: \n{', '.join(attribute_strings)}\n"
|
535
538
|
|
539
|
+
def get_secret(self, secret_id: str) -> dict:
|
540
|
+
"""Returns a secret object if exists.
|
541
|
+
|
542
|
+
Args:
|
543
|
+
secret_id (str): The secret ID to interact with
|
544
|
+
|
545
|
+
Returns:
|
546
|
+
Dict: A dictionary containing information about the existing secret ID.
|
547
|
+
|
548
|
+
Example:
|
549
|
+
>>> from clarifai.client.user import User
|
550
|
+
>>> client = User(user_id="user_id")
|
551
|
+
>>> secret_info = client.get_secret(secret_id="secret_id")
|
552
|
+
"""
|
553
|
+
request = service_pb2.GetSecretRequest(user_app_id=self.user_app_id, id=secret_id)
|
554
|
+
response = self._grpc_request(self.STUB.GetSecret, request)
|
555
|
+
if response.status.code != status_code_pb2.SUCCESS:
|
556
|
+
raise Exception(
|
557
|
+
f"""Error getting secret, are you sure this is a valid secret id {secret_id} at the user_id
|
558
|
+
{self.user_app_id.user_id}.
|
559
|
+
Error: {response.status.description}"""
|
560
|
+
)
|
561
|
+
|
562
|
+
dict_response = MessageToDict(response, preserving_proto_field_name=True)
|
563
|
+
kwargs = self.process_response_keys(dict_response["secret"], "secret")
|
564
|
+
|
565
|
+
return dict(auth=self.auth_helper, **kwargs)
|
566
|
+
|
567
|
+
def list_secrets(
|
568
|
+
self, page_no: int = None, per_page: int = None
|
569
|
+
) -> Generator[dict, None, None]:
|
570
|
+
"""List all secrets for the user
|
571
|
+
|
572
|
+
Args:
|
573
|
+
page_no (int): The page number to list.
|
574
|
+
per_page (int): The number of items per page.
|
575
|
+
|
576
|
+
Yields:
|
577
|
+
Dict: Dictionaries containing information about the secrets.
|
578
|
+
|
579
|
+
Example:
|
580
|
+
>>> from clarifai.client.user import User
|
581
|
+
>>> client = User(user_id="user_id")
|
582
|
+
>>> all_secrets = list(client.list_secrets())
|
583
|
+
|
584
|
+
Note:
|
585
|
+
Defaults to 16 per page if page_no is specified and per_page is not specified.
|
586
|
+
If both page_no and per_page are None, then lists all the resources.
|
587
|
+
"""
|
588
|
+
request_data = dict(user_app_id=self.user_app_id)
|
589
|
+
all_secrets_info = self.list_pages_generator(
|
590
|
+
self.STUB.ListSecrets,
|
591
|
+
service_pb2.ListSecretsRequest,
|
592
|
+
request_data,
|
593
|
+
per_page=per_page,
|
594
|
+
page_no=page_no,
|
595
|
+
)
|
596
|
+
for secret_info in all_secrets_info:
|
597
|
+
yield dict(auth=self.auth_helper, **secret_info)
|
598
|
+
|
599
|
+
def create_secrets(self, secrets: List[Dict[str, Any]]) -> List[dict]:
|
600
|
+
"""Creates secrets for the user.
|
601
|
+
|
602
|
+
Args:
|
603
|
+
secrets (List[Dict[str, Any]]): List of secret configurations to create.
|
604
|
+
Each secret dict can contain:
|
605
|
+
- id (str): The name/ID of the secret (required)
|
606
|
+
- value (str): The secret value (required)
|
607
|
+
- description (str): Optional description of the secret
|
608
|
+
- expires_at (str): Optional expiration timestamp
|
609
|
+
|
610
|
+
Returns:
|
611
|
+
List[Dict]: List of dictionaries containing information about the created secrets.
|
612
|
+
|
613
|
+
Example:
|
614
|
+
>>> from clarifai.client.user import User
|
615
|
+
>>> client = User(user_id="user_id")
|
616
|
+
>>> secrets = [{"id": "secret1", "value": "secret_value", "description": "My Secret"}]
|
617
|
+
>>> created_secrets = client.create_secrets(secrets)
|
618
|
+
"""
|
619
|
+
assert isinstance(secrets, list), "secrets param should be a list"
|
620
|
+
|
621
|
+
# Convert dict secrets to protobuf Secret objects
|
622
|
+
secret_objects = []
|
623
|
+
for secret_config in secrets:
|
624
|
+
secret_objects.append(resources_pb2.Secret(**secret_config))
|
625
|
+
|
626
|
+
request = service_pb2.PostSecretsRequest(
|
627
|
+
user_app_id=self.user_app_id, secrets=secret_objects
|
628
|
+
)
|
629
|
+
response = self._grpc_request(self.STUB.PostSecrets, request)
|
630
|
+
if response.status.code != status_code_pb2.SUCCESS:
|
631
|
+
raise Exception(response.status)
|
632
|
+
|
633
|
+
self.logger.info(f"Secrets created successfully:\n{response.status}")
|
634
|
+
|
635
|
+
# Convert response to list of dictionaries
|
636
|
+
dict_response = MessageToDict(response, preserving_proto_field_name=True)
|
637
|
+
created_secrets = []
|
638
|
+
for secret in dict_response.get("secrets", []):
|
639
|
+
kwargs = self.process_response_keys(secret, "secret")
|
640
|
+
created_secrets.append(dict(auth=self.auth_helper, **kwargs))
|
641
|
+
|
642
|
+
return created_secrets
|
643
|
+
|
644
|
+
def patch_secrets(
|
645
|
+
self, secrets: List[Dict[str, Any]], action: str = 'overwrite'
|
646
|
+
) -> List[dict]:
|
647
|
+
"""Patches secrets for the user.
|
648
|
+
|
649
|
+
Args:
|
650
|
+
secrets (List[Dict[str, Any]]): List of secret configurations to patch.
|
651
|
+
Each secret dict should contain:
|
652
|
+
- id (str): The name/ID of the secret to patch (required)
|
653
|
+
- value (str): Optional new secret value
|
654
|
+
- description (str): Optional new description
|
655
|
+
- expires_at (str): Optional new expiration timestamp
|
656
|
+
action (str): The action to perform on the secrets (overwrite/remove).
|
657
|
+
|
658
|
+
Returns:
|
659
|
+
List[Dict]: List of dictionaries containing information about the patched secrets.
|
660
|
+
|
661
|
+
Example:
|
662
|
+
>>> from clarifai.client.user import User
|
663
|
+
>>> client = User(user_id="user_id")
|
664
|
+
>>> secrets = [{"id": "secret1", "description": "Updated Secret Description"}]
|
665
|
+
>>> patched_secrets = client.patch_secrets(secrets, action="overwrite")
|
666
|
+
"""
|
667
|
+
assert isinstance(secrets, list), "secrets param should be a list"
|
668
|
+
|
669
|
+
# Convert dict secrets to protobuf Secret objects
|
670
|
+
secret_objects = []
|
671
|
+
for secret_config in secrets:
|
672
|
+
secret_objects.append(resources_pb2.Secret(**secret_config))
|
673
|
+
|
674
|
+
request = service_pb2.PatchSecretsRequest(
|
675
|
+
user_app_id=self.user_app_id, secret=secret_objects, action=action
|
676
|
+
)
|
677
|
+
response = self._grpc_request(self.STUB.PatchSecrets, request)
|
678
|
+
if response.status.code != status_code_pb2.SUCCESS:
|
679
|
+
raise Exception(response.status)
|
680
|
+
|
681
|
+
self.logger.info(f"Secrets patched successfully:\n{response.status}")
|
682
|
+
|
683
|
+
# Convert response to list of dictionaries
|
684
|
+
dict_response = MessageToDict(response, preserving_proto_field_name=True)
|
685
|
+
patched_secrets = []
|
686
|
+
for secret in dict_response.get("secrets", []):
|
687
|
+
kwargs = self.process_response_keys(secret, "secret")
|
688
|
+
patched_secrets.append(dict(auth=self.auth_helper, **kwargs))
|
689
|
+
|
690
|
+
return patched_secrets
|
691
|
+
|
692
|
+
def delete_secrets(self, secret_ids: List[str]) -> None:
|
693
|
+
"""Deletes a list of secrets for the user.
|
694
|
+
|
695
|
+
Args:
|
696
|
+
secret_ids (List[str]): The secret IDs of the user to delete.
|
697
|
+
|
698
|
+
Example:
|
699
|
+
>>> from clarifai.client.user import User
|
700
|
+
>>> client = User(user_id="user_id")
|
701
|
+
>>> client.delete_secrets(secret_ids=["secret_id1", "secret_id2"])
|
702
|
+
"""
|
703
|
+
assert isinstance(secret_ids, list), "secret_ids param should be a list"
|
704
|
+
|
705
|
+
request = service_pb2.DeleteSecretsRequest(user_app_id=self.user_app_id, ids=secret_ids)
|
706
|
+
response = self._grpc_request(self.STUB.DeleteSecrets, request)
|
707
|
+
if response.status.code != status_code_pb2.SUCCESS:
|
708
|
+
raise Exception(response.status)
|
709
|
+
self.logger.info("\nSecrets Deleted\n%s", response.status)
|
710
|
+
|
536
711
|
def list_models(
|
537
712
|
self,
|
538
713
|
user_id: str = None,
|
clarifai/client/workflow.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import os
|
2
2
|
import time
|
3
|
-
from typing import Dict, Generator, List
|
3
|
+
from typing import Any, Dict, Generator, List, Optional
|
4
4
|
|
5
5
|
from clarifai_grpc.grpc.api import resources_pb2, service_pb2
|
6
6
|
from clarifai_grpc.grpc.api.resources_pb2 import Input
|
@@ -25,29 +25,30 @@ class Workflow(Lister, BaseClient):
|
|
25
25
|
|
26
26
|
def __init__(
|
27
27
|
self,
|
28
|
-
url: str = None,
|
29
|
-
workflow_id: str = None,
|
30
|
-
workflow_version: Dict = {'id': ""},
|
31
|
-
output_config: Dict = {'min_value': 0},
|
28
|
+
url: Optional[str] = None,
|
29
|
+
workflow_id: Optional[str] = None,
|
30
|
+
workflow_version: Dict[str, str] = {'id': ""},
|
31
|
+
output_config: Dict[str, Any] = {'min_value': 0},
|
32
32
|
base_url: str = DEFAULT_BASE,
|
33
|
-
pat: str = None,
|
34
|
-
token: str = None,
|
35
|
-
root_certificates_path: str = None,
|
33
|
+
pat: Optional[str] = None,
|
34
|
+
token: Optional[str] = None,
|
35
|
+
root_certificates_path: Optional[str] = None,
|
36
36
|
**kwargs,
|
37
37
|
):
|
38
38
|
"""Initializes a Workflow object.
|
39
39
|
|
40
40
|
Args:
|
41
|
-
url (str): The URL to initialize the workflow object.
|
42
|
-
workflow_id (str): The Workflow ID to interact with.
|
43
|
-
workflow_version (
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
41
|
+
url (Optional[str]): The URL to initialize the workflow object.
|
42
|
+
workflow_id (Optional[str]): The Workflow ID to interact with.
|
43
|
+
workflow_version (Dict[str, str]): The Workflow Version to interact with.
|
44
|
+
Defaults to {'id': ""} for latest version.
|
45
|
+
output_config (Dict[str, Any]): The output config to interact with.
|
46
|
+
- min_value (float): The minimum value of the prediction confidence to filter.
|
47
|
+
- max_concepts (int): The maximum number of concepts to return.
|
48
|
+
- select_concepts (List[Concept]): The concepts to select.
|
49
|
+
- sample_ms (int): The number of milliseconds to sample.
|
49
50
|
base_url (str): Base API url. Default "https://api.clarifai.com"
|
50
|
-
pat (str): A personal access token for authentication. Can be set as env var CLARIFAI_PAT
|
51
|
+
pat (Optional[str]): A personal access token for authentication. Can be set as env var CLARIFAI_PAT
|
51
52
|
token (str): A session token for authentication. Accepts either a session token or a pat. Can be set as env var CLARIFAI_SESSION_TOKEN
|
52
53
|
root_certificates_path (str): Path to the SSL root certificates file, used to establish secure gRPC connections.
|
53
54
|
**kwargs: Additional keyword arguments to be passed to the Workflow.
|