18
18
from groundlight_openapi_client .api .edge_api import EdgeApi
19
19
from groundlight_openapi_client .api .notes_api import NotesApi
20
20
from groundlight_openapi_client import Action
21
- from groundlight_openapi_client import ActionList
22
- from groundlight_openapi_client import ActionRequest
23
21
from groundlight_openapi_client import BoundingBoxModeConfiguration
24
22
from groundlight_openapi_client import ChannelEnum
25
23
from groundlight_openapi_client import Condition
41
39
from groundlight .internalapi import _generate_request_id
42
40
from groundlight .optional_imports import Image , np
43
41
from groundlight .splint import ModeEnumSplint
42
+ from groundlight_openapi_client .models .detector_creation_input_request_mode_configuration import DetectorCreationInputRequestModeConfiguration
44
43
45
44
from .client import DEFAULT_REQUEST_TIMEOUT , Groundlight , GroundlightClientError , logger
46
45
@@ -188,7 +187,7 @@ def create_alert( # pylint: disable=too-many-locals, too-many-arguments # noqa
188
187
detector : Union [str , Detector ],
189
188
name ,
190
189
condition : Condition ,
191
- actions : Optional [Union [Action , List [Action ], ActionList ]] = None ,
190
+ actions : Optional [Union [Action , List [Action ]]] = None ,
192
191
webhook_actions : Optional [Union [WebhookAction , List [WebhookAction ]]] = None ,
193
192
* ,
194
193
enabled : bool = True ,
@@ -248,16 +247,14 @@ def create_alert( # pylint: disable=too-many-locals, too-many-arguments # noqa
248
247
"""
249
248
if isinstance (actions , Action ):
250
249
actions = [actions ]
251
- elif isinstance (actions , ActionList ):
252
- actions = actions .root
253
250
if isinstance (detector , Detector ):
254
251
detector = detector .id
255
252
if isinstance (webhook_actions , WebhookAction ):
256
253
webhook_actions = [webhook_actions ]
257
254
# translate pydantic type to the openapi type
258
255
actions = (
259
256
[
260
- ActionRequest (
257
+ Action (
261
258
channel = ChannelEnum (action .channel ), recipient = action .recipient , include_image = action .include_image
262
259
)
263
260
for action in actions
@@ -296,7 +293,7 @@ def create_alert( # pylint: disable=too-many-locals, too-many-arguments # noqa
296
293
human_review_required = human_review_required ,
297
294
webhook_action = webhook_actions ,
298
295
)
299
- return Rule . model_validate ( self .actions_api .create_rule (detector , rule_input ). to_dict () )
296
+ return self .actions_api .create_rule (detector , rule_input )
300
297
301
298
def create_rule ( # pylint: disable=too-many-locals # noqa: PLR0913
302
299
self ,
@@ -384,7 +381,7 @@ def create_rule( # pylint: disable=too-many-locals # noqa: PLR0913
384
381
channel = ChannelEnum (channel .upper ())
385
382
if isinstance (condition_parameters , str ):
386
383
condition_parameters = json .loads (condition_parameters ) # type: ignore
387
- action = ActionRequest (
384
+ action = Action (
388
385
channel = channel , # type: ignore
389
386
recipient = recipient ,
390
387
include_image = include_image ,
@@ -402,7 +399,7 @@ def create_rule( # pylint: disable=too-many-locals # noqa: PLR0913
402
399
snooze_time_unit = snooze_time_unit ,
403
400
human_review_required = human_review_required ,
404
401
)
405
- return Rule . model_validate ( self .actions_api .create_rule (det_id , rule_input ). to_dict () )
402
+ return self .actions_api .create_rule (det_id , rule_input )
406
403
407
404
def get_rule (self , action_id : int ) -> Rule :
408
405
"""
@@ -696,7 +693,7 @@ def create_bounding_box_detector( # noqa: PLR0913 # pylint: disable=too-many-ar
696
693
else :
697
694
mode_config = BoundingBoxModeConfiguration (max_num_bboxes = max_num_bboxes , class_name = class_name )
698
695
699
- detector_creation_input .mode_configuration = mode_config
696
+ detector_creation_input .mode_configuration = DetectorCreationInputRequestModeConfiguration ( mode_config )
700
697
obj = self .detectors_api .create_detector (detector_creation_input , _request_timeout = DEFAULT_REQUEST_TIMEOUT )
701
698
return Detector .parse_obj (obj .to_dict ())
702
699
@@ -750,7 +747,7 @@ def create_text_recognition_detector( # noqa: PLR0913 # pylint: disable=too-man
750
747
detector_creation_input .mode = ModeEnumSplint .TEXT
751
748
mode_config = TextModeConfiguration ()
752
749
753
- detector_creation_input .mode_configuration = mode_config
750
+ detector_creation_input .mode_configuration = DetectorCreationInputRequestModeConfiguration ( mode_config )
754
751
obj = self .detectors_api .create_detector (detector_creation_input , _request_timeout = DEFAULT_REQUEST_TIMEOUT )
755
752
return Detector .parse_obj (obj .to_dict ())
756
753
0 commit comments