Skip to content

Commit 854299d

Browse files
authored
Merge pull request #1982 from kili-technology/feature/lab-4021-aau-i-can-activatedeactivate-the-consensus-on-an-asset
feat(lab-4021): add method to activate and deactivate consensus on asset
2 parents c63e9ca + f44d211 commit 854299d

File tree

15 files changed

+241
-3
lines changed

15 files changed

+241
-3
lines changed

src/kili/adapters/kili_api_gateway/asset/operations_mixin.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
)
2626
from kili.adapters.kili_api_gateway.label.common import get_annotation_fragment
2727
from kili.adapters.kili_api_gateway.project.common import get_project
28+
from kili.core.graphql.operations.asset.mutations import GQL_SET_ASSET_CONSENSUS
2829
from kili.domain.asset import AssetFilters
2930
from kili.domain.types import ListOrTuple
3031

@@ -166,3 +167,26 @@ def count_assets_annotations(self, filters: AssetFilters) -> int:
166167
count_result = self.graphql_client.execute(GQL_COUNT_ASSET_ANNOTATIONS, payload)
167168
count: int = count_result["data"]
168169
return count
170+
171+
def update_asset_consensus(
172+
self,
173+
project_id: str,
174+
is_consensus: bool,
175+
asset_id: str | None = None,
176+
external_id: str | None = None,
177+
) -> bool:
178+
"""Update consensus on an asset."""
179+
if asset_id is None and external_id is None:
180+
raise ValueError("At least one of asset_id or external_id must be provided")
181+
182+
payload = {
183+
"projectId": project_id,
184+
"isConsensus": is_consensus,
185+
}
186+
if asset_id is not None:
187+
payload["assetId"] = asset_id
188+
if external_id is not None:
189+
payload["externalId"] = external_id
190+
191+
result = self.graphql_client.execute(GQL_SET_ASSET_CONSENSUS, payload)
192+
return result["data"]

src/kili/core/graphql/operations/asset/mutations.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,19 @@
2727
}
2828
}
2929
"""
30+
31+
GQL_SET_ASSET_CONSENSUS = """
32+
mutation setAssetConsensus(
33+
$assetId: ID,
34+
$externalId: String,
35+
$projectId: ID!,
36+
$isConsensus: Boolean!
37+
) {
38+
data: setAssetConsensus(
39+
assetId: $assetId,
40+
externalId: $externalId,
41+
projectId: $projectId,
42+
isConsensus: $isConsensus
43+
)
44+
}
45+
"""

src/kili/domain_api/assets.py

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Assets domain namespace for the Kili Python SDK."""
2-
# pylint: disable=too-many-lines
2+
# pylint: disable=too-many-lines,too-many-public-methods
33

44
import warnings
55
from collections.abc import Generator
@@ -266,6 +266,7 @@ class AssetsNamespace(DomainNamespace): # pylint: disable=too-many-public-metho
266266
- update_priority(): Update asset priorities
267267
- skip(): Skip an asset
268268
- unskip(): Unskip an asset
269+
- add_consensus(): Activate or deactivate consensus on an asset
269270
270271
Examples:
271272
>>> kili = Kili()
@@ -2233,3 +2234,78 @@ def update_priority(
22332234
priorities=priorities if priorities is not None else [],
22342235
**kwargs,
22352236
)
2237+
2238+
@overload
2239+
def update_consensus(
2240+
self,
2241+
*,
2242+
asset_id: str,
2243+
project_id: str,
2244+
is_consensus: bool,
2245+
) -> bool:
2246+
...
2247+
2248+
@overload
2249+
def update_consensus(
2250+
self,
2251+
*,
2252+
external_id: str,
2253+
project_id: str,
2254+
is_consensus: bool,
2255+
) -> bool:
2256+
...
2257+
2258+
@typechecked
2259+
def update_consensus(
2260+
self,
2261+
*,
2262+
project_id: str,
2263+
is_consensus: bool,
2264+
asset_id: Optional[str] = None,
2265+
external_id: Optional[str] = None,
2266+
) -> bool:
2267+
"""Activate or deactivate consensus on an asset.
2268+
2269+
Args:
2270+
project_id: The project ID.
2271+
is_consensus: Whether to activate (True) or deactivate (False) consensus on the asset.
2272+
asset_id: The internal asset ID to modify. Either asset_id or external_id must be provided.
2273+
external_id: The external ID of the asset to modify. Either asset_id or external_id must be provided.
2274+
2275+
Returns:
2276+
The consensus value that was set (True if consensus was activated, False if deactivated).
2277+
2278+
Raises:
2279+
ValueError: If neither asset_id nor external_id is provided.
2280+
2281+
Examples:
2282+
>>> # Activate consensus on an asset using asset_id
2283+
>>> result = kili.assets.update_consensus(
2284+
... project_id="my_project",
2285+
... is_consensus=True,
2286+
... asset_id="ckg22d81r0jrg0885unmuswj8"
2287+
... )
2288+
>>> # result is True
2289+
2290+
>>> # Activate consensus on an asset using external_id
2291+
>>> result = kili.assets.update_consensus(
2292+
... project_id="my_project",
2293+
... is_consensus=True,
2294+
... external_id="my_asset_001"
2295+
... )
2296+
>>> # result is True
2297+
2298+
>>> # Deactivate consensus on an asset
2299+
>>> result = kili.assets.update_consensus(
2300+
... project_id="my_project",
2301+
... is_consensus=False,
2302+
... asset_id="ckg22d81r0jrg0885unmuswj8"
2303+
... )
2304+
>>> # result is False
2305+
"""
2306+
return self._client.update_asset_consensus(
2307+
project_id=project_id,
2308+
is_consensus=is_consensus,
2309+
asset_id=asset_id,
2310+
external_id=external_id,
2311+
)

src/kili/domain_api/exports.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Tags domain namespace for the Kili Python SDK."""
2+
# pylint: disable=too-many-public-methods
23

34
from typing import TYPE_CHECKING, Any, Optional, TypedDict, Union
45

src/kili/domain_api/issues.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
This module provides a comprehensive interface for issue-related operations
44
including creation, querying, status management, and lifecycle operations.
55
"""
6+
# pylint: disable=too-many-public-methods
67

78
from collections.abc import Generator
89
from itertools import repeat

src/kili/domain_api/labels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# pylint: disable=too-many-lines
1+
# pylint: disable=too-many-lines,too-many-public-methods
22
"""Labels domain namespace for the Kili Python SDK.
33
44
This module provides a comprehensive interface for label-related operations

src/kili/domain_api/organizations.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Organizations domain namespace for the Kili Python SDK."""
2+
# pylint: disable=too-many-public-methods
23

34
from collections.abc import Generator
45
from datetime import datetime

src/kili/domain_api/plugins.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Plugins domain namespace for the Kili Python SDK."""
2+
# pylint: disable=too-many-public-methods
23

34
from datetime import datetime
45
from typing import List, Optional

src/kili/domain_api/projects.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
This module provides a comprehensive interface for project-related operations
44
including lifecycle management, user management, workflow configuration, and versioning.
55
"""
6+
# pylint: disable=too-many-public-methods
67

78
from collections.abc import Generator, Iterable, Sequence
89
from functools import cached_property

src/kili/domain_api/questions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
This module provides a comprehensive interface for question-related operations
44
including creation, querying, status management, and lifecycle operations.
55
"""
6+
# pylint: disable=too-many-public-methods
67

78
from collections.abc import Generator
89
from itertools import repeat

0 commit comments

Comments
 (0)