@@ -223,7 +223,11 @@ def _fixup_image_query(iq: ImageQuery) -> ImageQuery:
223
223
iq .result .label = convert_internal_label_to_display (iq , iq .result .label )
224
224
return iq
225
225
226
- def whoami (self ) -> str :
226
+ def _get_request_timeout (self , ** kwargs ):
227
+ """Extract request_timeout from kwargs or use default."""
228
+ return kwargs .get ("request_timeout" , DEFAULT_REQUEST_TIMEOUT )
229
+
230
+ def whoami (self , ** kwargs ) -> str :
227
231
"""
228
232
Return the username (email address) associated with the current API token.
229
233
@@ -240,7 +244,7 @@ def whoami(self) -> str:
240
244
:raises ApiTokenError: If the API token is invalid
241
245
:raises GroundlightClientError: If there are connectivity issues with the Groundlight service
242
246
"""
243
- obj = self .user_api .who_am_i (_request_timeout = DEFAULT_REQUEST_TIMEOUT )
247
+ obj = self .user_api .who_am_i (_request_timeout = self . _get_request_timeout ( ** kwargs ) )
244
248
return obj ["email" ]
245
249
246
250
def _user_is_privileged (self ) -> bool :
@@ -251,7 +255,7 @@ def _user_is_privileged(self) -> bool:
251
255
obj = self .user_api .who_am_i ()
252
256
return obj ["is_superuser" ]
253
257
254
- def get_detector (self , id : Union [str , Detector ]) -> Detector : # pylint: disable=redefined-builtin
258
+ def get_detector (self , id : Union [str , Detector ], ** kwargs ) -> Detector : # pylint: disable=redefined-builtin
255
259
"""
256
260
Get a Detector by id.
257
261
@@ -270,7 +274,7 @@ def get_detector(self, id: Union[str, Detector]) -> Detector: # pylint: disable
270
274
# Short-circuit
271
275
return id
272
276
try :
273
- obj = self .detectors_api .get_detector (id = id , _request_timeout = DEFAULT_REQUEST_TIMEOUT )
277
+ obj = self .detectors_api .get_detector (id = id , _request_timeout = self . _get_request_timeout ( ** kwargs ) )
274
278
except NotFoundException as e :
275
279
raise NotFoundError (f"Detector with id '{ id } ' not found" ) from e
276
280
return Detector .parse_obj (obj .to_dict ())
@@ -291,7 +295,7 @@ def get_detector_by_name(self, name: str) -> Detector:
291
295
"""
292
296
return self .api_client ._get_detector_by_name (name ) # pylint: disable=protected-access
293
297
294
- def list_detectors (self , page : int = 1 , page_size : int = 10 ) -> PaginatedDetectorList :
298
+ def list_detectors (self , page : int = 1 , page_size : int = 10 , ** kwargs ) -> PaginatedDetectorList :
295
299
"""
296
300
Retrieve a paginated list of detectors associated with your account.
297
301
@@ -312,7 +316,7 @@ def list_detectors(self, page: int = 1, page_size: int = 10) -> PaginatedDetecto
312
316
:return: PaginatedDetectorList containing the requested page of detectors and pagination metadata
313
317
"""
314
318
obj = self .detectors_api .list_detectors (
315
- page = page , page_size = page_size , _request_timeout = DEFAULT_REQUEST_TIMEOUT
319
+ page = page , page_size = page_size , _request_timeout = self . _get_request_timeout ( ** kwargs )
316
320
)
317
321
return PaginatedDetectorList .parse_obj (obj .to_dict ())
318
322
@@ -358,6 +362,7 @@ def create_detector( # noqa: PLR0913
358
362
patience_time : Optional [float ] = None ,
359
363
pipeline_config : Optional [str ] = None ,
360
364
metadata : Union [dict , str , None ] = None ,
365
+ ** kwargs ,
361
366
) -> Detector :
362
367
"""
363
368
Create a new Detector with a given name and query.
@@ -423,7 +428,9 @@ def create_detector( # noqa: PLR0913
423
428
pipeline_config = pipeline_config ,
424
429
metadata = metadata ,
425
430
)
426
- obj = self .detectors_api .create_detector (detector_creation_input , _request_timeout = DEFAULT_REQUEST_TIMEOUT )
431
+ obj = self .detectors_api .create_detector (
432
+ detector_creation_input , _request_timeout = self ._get_request_timeout (** kwargs )
433
+ )
427
434
return Detector .parse_obj (obj .to_dict ())
428
435
429
436
def get_or_create_detector ( # noqa: PLR0913
@@ -435,6 +442,7 @@ def get_or_create_detector( # noqa: PLR0913
435
442
confidence_threshold : Optional [float ] = None ,
436
443
pipeline_config : Optional [str ] = None ,
437
444
metadata : Union [dict , str , None ] = None ,
445
+ ** kwargs ,
438
446
) -> Detector :
439
447
"""
440
448
Tries to look up the Detector by name. If a Detector with that name, query, and
@@ -491,6 +499,7 @@ def get_or_create_detector( # noqa: PLR0913
491
499
confidence_threshold = confidence_threshold ,
492
500
pipeline_config = pipeline_config ,
493
501
metadata = metadata ,
502
+ ** kwargs ,
494
503
)
495
504
496
505
# TODO: We may soon allow users to update the retrieved detector's fields.
@@ -512,7 +521,7 @@ def get_or_create_detector( # noqa: PLR0913
512
521
)
513
522
return existing_detector
514
523
515
- def get_image_query (self , id : str ) -> ImageQuery : # pylint: disable=redefined-builtin
524
+ def get_image_query (self , id : str , ** kwargs ) -> ImageQuery : # pylint: disable=redefined-builtin
516
525
"""
517
526
Get an ImageQuery by its ID. This is useful for retrieving the status and results of a
518
527
previously submitted query.
@@ -534,15 +543,15 @@ def get_image_query(self, id: str) -> ImageQuery: # pylint: disable=redefined-b
534
543
535
544
:return: ImageQuery object containing the query details and results
536
545
"""
537
- obj = self .image_queries_api .get_image_query (id = id , _request_timeout = DEFAULT_REQUEST_TIMEOUT )
546
+ obj = self .image_queries_api .get_image_query (id = id , _request_timeout = self . _get_request_timeout ( ** kwargs ) )
538
547
if obj .result_type == "counting" and getattr (obj .result , "label" , None ):
539
548
obj .result .pop ("label" )
540
549
obj .result ["count" ] = None
541
550
iq = ImageQuery .parse_obj (obj .to_dict ())
542
551
return self ._fixup_image_query (iq )
543
552
544
553
def list_image_queries (
545
- self , page : int = 1 , page_size : int = 10 , detector_id : Union [str , None ] = None
554
+ self , page : int = 1 , page_size : int = 10 , detector_id : Union [str , None ] = None , ** kwargs
546
555
) -> PaginatedImageQueryList :
547
556
"""
548
557
List all image queries associated with your account, with pagination support.
@@ -565,7 +574,11 @@ def list_image_queries(
565
574
:return: PaginatedImageQueryList containing the requested page of image queries and pagination metadata
566
575
like total count and links to next/previous pages.
567
576
"""
568
- params : dict [str , Any ] = {"page" : page , "page_size" : page_size , "_request_timeout" : DEFAULT_REQUEST_TIMEOUT }
577
+ params : dict [str , Any ] = {
578
+ "page" : page ,
579
+ "page_size" : page_size ,
580
+ "_request_timeout" : self ._get_request_timeout (** kwargs ),
581
+ }
569
582
if detector_id :
570
583
params ["detector_id" ] = detector_id
571
584
obj = self .image_queries_api .list_image_queries (** params )
@@ -586,6 +599,7 @@ def submit_image_query( # noqa: PLR0913 # pylint: disable=too-many-arguments, t
586
599
inspection_id : Optional [str ] = None ,
587
600
metadata : Union [dict , str , None ] = None ,
588
601
image_query_id : Optional [str ] = None ,
602
+ ** kwargs ,
589
603
) -> ImageQuery :
590
604
"""
591
605
Evaluates an image with Groundlight. This is the core method for getting predictions about images.
@@ -680,7 +694,11 @@ def submit_image_query( # noqa: PLR0913 # pylint: disable=too-many-arguments, t
680
694
681
695
image_bytesio : ByteStreamWrapper = parse_supported_image_types (image )
682
696
683
- params = {"detector_id" : detector_id , "body" : image_bytesio , "_request_timeout" : DEFAULT_REQUEST_TIMEOUT }
697
+ params = {
698
+ "detector_id" : detector_id ,
699
+ "body" : image_bytesio ,
700
+ "_request_timeout" : self ._get_request_timeout (** kwargs ),
701
+ }
684
702
685
703
if patience_time is not None :
686
704
params ["patience_time" ] = patience_time
@@ -732,6 +750,7 @@ def ask_confident( # noqa: PLR0913 # pylint: disable=too-many-arguments
732
750
wait : Optional [float ] = None ,
733
751
metadata : Union [dict , str , None ] = None ,
734
752
inspection_id : Optional [str ] = None ,
753
+ ** kwargs ,
735
754
) -> ImageQuery :
736
755
"""
737
756
Evaluates an image with Groundlight, waiting until an answer above the confidence threshold
@@ -788,6 +807,7 @@ def ask_confident( # noqa: PLR0913 # pylint: disable=too-many-arguments
788
807
human_review = None ,
789
808
metadata = metadata ,
790
809
inspection_id = inspection_id ,
810
+ ** kwargs ,
791
811
)
792
812
793
813
def ask_ml ( # noqa: PLR0913 # pylint: disable=too-many-arguments, too-many-locals
@@ -797,6 +817,7 @@ def ask_ml( # noqa: PLR0913 # pylint: disable=too-many-arguments, too-many-loca
797
817
wait : Optional [float ] = None ,
798
818
metadata : Union [dict , str , None ] = None ,
799
819
inspection_id : Optional [str ] = None ,
820
+ ** kwargs ,
800
821
) -> ImageQuery :
801
822
"""
802
823
Evaluates an image with Groundlight, getting the first ML prediction without waiting
@@ -856,6 +877,7 @@ def ask_ml( # noqa: PLR0913 # pylint: disable=too-many-arguments, too-many-loca
856
877
wait = 0 ,
857
878
metadata = metadata ,
858
879
inspection_id = inspection_id ,
880
+ ** kwargs ,
859
881
)
860
882
if iq_is_answered (iq ):
861
883
return iq
@@ -871,6 +893,7 @@ def ask_async( # noqa: PLR0913 # pylint: disable=too-many-arguments
871
893
human_review : Optional [str ] = None ,
872
894
metadata : Union [dict , str , None ] = None ,
873
895
inspection_id : Optional [str ] = None ,
896
+ ** kwargs ,
874
897
) -> ImageQuery :
875
898
"""
876
899
Submit an image query asynchronously. This is equivalent to calling `submit_image_query`
@@ -952,6 +975,7 @@ def ask_async( # noqa: PLR0913 # pylint: disable=too-many-arguments
952
975
want_async = True ,
953
976
metadata = metadata ,
954
977
inspection_id = inspection_id ,
978
+ ** kwargs ,
955
979
)
956
980
957
981
def wait_for_confident_result (
@@ -1092,6 +1116,7 @@ def add_label(
1092
1116
image_query : Union [ImageQuery , str ],
1093
1117
label : Union [Label , int , str ],
1094
1118
rois : Union [List [ROI ], str , None ] = None ,
1119
+ ** kwargs ,
1095
1120
):
1096
1121
"""
1097
1122
Provide a new label (annotation) for an image query. This is used to provide ground-truth labels
@@ -1151,7 +1176,7 @@ def add_label(
1151
1176
else None
1152
1177
)
1153
1178
request_params = LabelValueRequest (label = label , image_query_id = image_query_id , rois = roi_requests )
1154
- self .labels_api .create_label (request_params )
1179
+ self .labels_api .create_label (request_params , _request_timeout = self . _get_request_timeout ( ** kwargs ) )
1155
1180
1156
1181
def start_inspection (self ) -> str :
1157
1182
"""
@@ -1189,7 +1214,9 @@ def stop_inspection(self, inspection_id: str) -> str:
1189
1214
"""
1190
1215
return self .api_client .stop_inspection (inspection_id )
1191
1216
1192
- def update_detector_confidence_threshold (self , detector : Union [str , Detector ], confidence_threshold : float ) -> None :
1217
+ def update_detector_confidence_threshold (
1218
+ self , detector : Union [str , Detector ], confidence_threshold : float , ** kwargs
1219
+ ) -> None :
1193
1220
"""
1194
1221
Updates the confidence threshold for the given detector
1195
1222
@@ -1203,5 +1230,7 @@ def update_detector_confidence_threshold(self, detector: Union[str, Detector], c
1203
1230
if confidence_threshold < 0 or confidence_threshold > 1 :
1204
1231
raise ValueError ("confidence must be between 0 and 1" )
1205
1232
self .detectors_api .update_detector (
1206
- detector , patched_detector_request = PatchedDetectorRequest (confidence_threshold = confidence_threshold )
1233
+ detector ,
1234
+ patched_detector_request = PatchedDetectorRequest (confidence_threshold = confidence_threshold ),
1235
+ _request_timeout = self ._get_request_timeout (** kwargs ),
1207
1236
)
0 commit comments