5
5
# Code generated by Microsoft (R) Python Code Generator.
6
6
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7
7
# --------------------------------------------------------------------------
8
- from collections .abc import MutableMapping
8
+ try :
9
+ from collections .abc import MutableMapping
10
+ except ImportError :
11
+ from collections import MutableMapping # pylint: disable=deprecated-class
9
12
from io import IOBase
10
13
import json
11
14
from typing import Any , Callable , Dict , IO , Iterator , List , Optional , TypeVar , Union , cast , overload
35
38
from .._utils .utils import ClientMixinABC
36
39
37
40
JSON = MutableMapping [str , Any ]
41
+ _Unset : Any = object ()
38
42
T = TypeVar ("T" )
39
43
ClsType = Optional [Callable [[PipelineResponse [HttpRequest , HttpResponse ], T , Dict [str , Any ]], Any ]]
40
44
@@ -73,7 +77,31 @@ def build_radiology_insights_infer_radiology_insights_request( # pylint: disabl
73
77
return HttpRequest (method = "PUT" , url = _url , params = _params , headers = _headers , ** kwargs )
74
78
75
79
76
- class RadiologyInsightsClientOperationsMixin (
80
+ def build_radiology_insights_infer_from_custom_model_id_request ( # pylint: disable=name-too-long
81
+ ** kwargs : Any ,
82
+ ) -> HttpRequest :
83
+ _headers = case_insensitive_dict (kwargs .pop ("headers" , {}) or {})
84
+ _params = case_insensitive_dict (kwargs .pop ("params" , {}) or {})
85
+
86
+ content_type : Optional [str ] = kwargs .pop ("content_type" , _headers .pop ("Content-Type" , None ))
87
+ api_version : str = kwargs .pop ("api_version" , _params .pop ("api-version" , "2024-10-01" ))
88
+ accept = _headers .pop ("Accept" , "application/json" )
89
+
90
+ # Construct URL
91
+ _url = "/radiology-insights/custom"
92
+
93
+ # Construct parameters
94
+ _params ["api-version" ] = _SERIALIZER .query ("api_version" , api_version , "str" )
95
+
96
+ # Construct headers
97
+ if content_type is not None :
98
+ _headers ["Content-Type" ] = _SERIALIZER .header ("content_type" , content_type , "str" )
99
+ _headers ["Accept" ] = _SERIALIZER .header ("accept" , accept , "str" )
100
+
101
+ return HttpRequest (method = "POST" , url = _url , params = _params , headers = _headers , ** kwargs )
102
+
103
+
104
+ class _RadiologyInsightsClientOperationsMixin (
77
105
ClientMixinABC [PipelineClient [HttpRequest , HttpResponse ], RadiologyInsightsClientConfiguration ]
78
106
):
79
107
@@ -83,7 +111,7 @@ def _infer_radiology_insights_initial(
83
111
resource : Union [_models .RadiologyInsightsJob , JSON , IO [bytes ]],
84
112
* ,
85
113
expand : Optional [List [str ]] = None ,
86
- ** kwargs : Any
114
+ ** kwargs : Any ,
87
115
) -> Iterator [bytes ]:
88
116
error_map : MutableMapping = {
89
117
401 : ClientAuthenticationError ,
@@ -155,7 +183,7 @@ def begin_infer_radiology_insights(
155
183
* ,
156
184
expand : Optional [List [str ]] = None ,
157
185
content_type : str = "application/json" ,
158
- ** kwargs : Any
186
+ ** kwargs : Any ,
159
187
) -> LROPoller [_models .RadiologyInsightsJob ]:
160
188
"""Create Radiology Insights job.
161
189
@@ -185,7 +213,7 @@ def begin_infer_radiology_insights(
185
213
* ,
186
214
expand : Optional [List [str ]] = None ,
187
215
content_type : str = "application/json" ,
188
- ** kwargs : Any
216
+ ** kwargs : Any ,
189
217
) -> LROPoller [_models .RadiologyInsightsJob ]:
190
218
"""Create Radiology Insights job.
191
219
@@ -215,7 +243,7 @@ def begin_infer_radiology_insights(
215
243
* ,
216
244
expand : Optional [List [str ]] = None ,
217
245
content_type : str = "application/json" ,
218
- ** kwargs : Any
246
+ ** kwargs : Any ,
219
247
) -> LROPoller [_models .RadiologyInsightsJob ]:
220
248
"""Create Radiology Insights job.
221
249
@@ -244,7 +272,7 @@ def begin_infer_radiology_insights(
244
272
resource : Union [_models .RadiologyInsightsJob , JSON , IO [bytes ]],
245
273
* ,
246
274
expand : Optional [List [str ]] = None ,
247
- ** kwargs : Any
275
+ ** kwargs : Any ,
248
276
) -> LROPoller [_models .RadiologyInsightsJob ]:
249
277
"""Create Radiology Insights job.
250
278
@@ -281,7 +309,7 @@ def begin_infer_radiology_insights(
281
309
cls = lambda x , y , z : x ,
282
310
headers = _headers ,
283
311
params = _params ,
284
- ** kwargs
312
+ ** kwargs ,
285
313
)
286
314
raw_result .http_response .read () # type: ignore
287
315
kwargs .pop ("error_map" , None )
@@ -321,3 +349,217 @@ def get_long_running_output(pipeline_response):
321
349
return LROPoller [_models .RadiologyInsightsJob ](
322
350
self ._client , raw_result , get_long_running_output , polling_method # type: ignore
323
351
)
352
+
353
+ def _infer_from_custom_model_id_initial (
354
+ self ,
355
+ body : Union [JSON , IO [bytes ]] = _Unset ,
356
+ * ,
357
+ inference_data : _models .RadiologyInsightsData = _Unset ,
358
+ id : Optional [List [str ]] = None ,
359
+ ** kwargs : Any ,
360
+ ) -> Iterator [bytes ]:
361
+ error_map : MutableMapping = {
362
+ 401 : ClientAuthenticationError ,
363
+ 404 : ResourceNotFoundError ,
364
+ 409 : ResourceExistsError ,
365
+ 304 : ResourceNotModifiedError ,
366
+ }
367
+ error_map .update (kwargs .pop ("error_map" , {}) or {})
368
+
369
+ _headers = case_insensitive_dict (kwargs .pop ("headers" , {}) or {})
370
+ _params = kwargs .pop ("params" , {}) or {}
371
+
372
+ content_type : Optional [str ] = kwargs .pop ("content_type" , _headers .pop ("Content-Type" , None ))
373
+ cls : ClsType [Iterator [bytes ]] = kwargs .pop ("cls" , None )
374
+
375
+ if body is _Unset :
376
+ if inference_data is _Unset :
377
+ raise TypeError ("missing required argument: inference_data" )
378
+ body = {"id" : id , "inferenceData" : inference_data }
379
+ body = {k : v for k , v in body .items () if v is not None }
380
+ content_type = content_type or "application/json"
381
+ _content = None
382
+ if isinstance (body , (IOBase , bytes )):
383
+ _content = body
384
+ else :
385
+ _content = json .dumps (body , cls = SdkJSONEncoder , exclude_readonly = True ) # type: ignore
386
+
387
+ _request = build_radiology_insights_infer_from_custom_model_id_request (
388
+ content_type = content_type ,
389
+ api_version = self ._config .api_version ,
390
+ content = _content ,
391
+ headers = _headers ,
392
+ params = _params ,
393
+ )
394
+ path_format_arguments = {
395
+ "endpoint" : self ._serialize .url ("self._config.endpoint" , self ._config .endpoint , "str" , skip_quote = True ),
396
+ }
397
+ _request .url = self ._client .format_url (_request .url , ** path_format_arguments )
398
+
399
+ _stream = True
400
+ pipeline_response : PipelineResponse = self ._client ._pipeline .run ( # pylint: disable=protected-access
401
+ _request , stream = _stream , ** kwargs
402
+ )
403
+
404
+ response = pipeline_response .http_response
405
+
406
+ if response .status_code not in [202 ]:
407
+ try :
408
+ response .read () # Load the body in memory and close the socket
409
+ except (StreamConsumedError , StreamClosedError ):
410
+ pass
411
+ map_error (status_code = response .status_code , response = response , error_map = error_map )
412
+ raise HttpResponseError (response = response )
413
+
414
+ response_headers = {}
415
+ response_headers ["Operation-Location" ] = self ._deserialize ("str" , response .headers .get ("Operation-Location" ))
416
+
417
+ deserialized = response .iter_bytes ()
418
+
419
+ if cls :
420
+ return cls (pipeline_response , deserialized , response_headers ) # type: ignore
421
+
422
+ return deserialized # type: ignore
423
+
424
+ @overload
425
+ def begin_infer_from_custom_model_id (
426
+ self ,
427
+ * ,
428
+ inference_data : _models .RadiologyInsightsData ,
429
+ content_type : str = "application/json" ,
430
+ id : Optional [List [str ]] = None ,
431
+ ** kwargs : Any ,
432
+ ) -> LROPoller [_models .RadiologyInsightsInferenceResult ]:
433
+ """Infer radiology insights using a custom model.
434
+
435
+ :keyword inference_data: Contains the list of patients, and configuration data. Required.
436
+ :paramtype inference_data: ~azure.healthinsights.radiologyinsights.models.RadiologyInsightsData
437
+ :keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
438
+ Default value is "application/json".
439
+ :paramtype content_type: str
440
+ :keyword id: Models to be used for inference. If this is not specified, the model will use the
441
+ default model for inference. Default value is None.
442
+ :paramtype id: list[str]
443
+ :return: An instance of LROPoller that returns RadiologyInsightsInferenceResult. The
444
+ RadiologyInsightsInferenceResult is compatible with MutableMapping
445
+ :rtype:
446
+ ~azure.core.polling.LROPoller[~azure.healthinsights.radiologyinsights.models.RadiologyInsightsInferenceResult]
447
+ :raises ~azure.core.exceptions.HttpResponseError:
448
+ """
449
+
450
+ @overload
451
+ def begin_infer_from_custom_model_id (
452
+ self , body : JSON , * , content_type : str = "application/json" , ** kwargs : Any
453
+ ) -> LROPoller [_models .RadiologyInsightsInferenceResult ]:
454
+ """Infer radiology insights using a custom model.
455
+
456
+ :param body: Required.
457
+ :type body: JSON
458
+ :keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
459
+ Default value is "application/json".
460
+ :paramtype content_type: str
461
+ :return: An instance of LROPoller that returns RadiologyInsightsInferenceResult. The
462
+ RadiologyInsightsInferenceResult is compatible with MutableMapping
463
+ :rtype:
464
+ ~azure.core.polling.LROPoller[~azure.healthinsights.radiologyinsights.models.RadiologyInsightsInferenceResult]
465
+ :raises ~azure.core.exceptions.HttpResponseError:
466
+ """
467
+
468
+ @overload
469
+ def begin_infer_from_custom_model_id (
470
+ self , body : IO [bytes ], * , content_type : str = "application/json" , ** kwargs : Any
471
+ ) -> LROPoller [_models .RadiologyInsightsInferenceResult ]:
472
+ """Infer radiology insights using a custom model.
473
+
474
+ :param body: Required.
475
+ :type body: IO[bytes]
476
+ :keyword content_type: Body Parameter content-type. Content type parameter for binary body.
477
+ Default value is "application/json".
478
+ :paramtype content_type: str
479
+ :return: An instance of LROPoller that returns RadiologyInsightsInferenceResult. The
480
+ RadiologyInsightsInferenceResult is compatible with MutableMapping
481
+ :rtype:
482
+ ~azure.core.polling.LROPoller[~azure.healthinsights.radiologyinsights.models.RadiologyInsightsInferenceResult]
483
+ :raises ~azure.core.exceptions.HttpResponseError:
484
+ """
485
+
486
+ @distributed_trace
487
+ def begin_infer_from_custom_model_id (
488
+ self ,
489
+ body : Union [JSON , IO [bytes ]] = _Unset ,
490
+ * ,
491
+ inference_data : _models .RadiologyInsightsData = _Unset ,
492
+ id : Optional [List [str ]] = None ,
493
+ ** kwargs : Any ,
494
+ ) -> LROPoller [_models .RadiologyInsightsInferenceResult ]:
495
+ """Infer radiology insights using a custom model.
496
+
497
+ :param body: Is either a JSON type or a IO[bytes] type. Required.
498
+ :type body: JSON or IO[bytes]
499
+ :keyword inference_data: Contains the list of patients, and configuration data. Required.
500
+ :paramtype inference_data: ~azure.healthinsights.radiologyinsights.models.RadiologyInsightsData
501
+ :keyword id: Models to be used for inference. If this is not specified, the model will use the
502
+ default model for inference. Default value is None.
503
+ :paramtype id: list[str]
504
+ :return: An instance of LROPoller that returns RadiologyInsightsInferenceResult. The
505
+ RadiologyInsightsInferenceResult is compatible with MutableMapping
506
+ :rtype:
507
+ ~azure.core.polling.LROPoller[~azure.healthinsights.radiologyinsights.models.RadiologyInsightsInferenceResult]
508
+ :raises ~azure.core.exceptions.HttpResponseError:
509
+ """
510
+ _headers = case_insensitive_dict (kwargs .pop ("headers" , {}) or {})
511
+ _params = kwargs .pop ("params" , {}) or {}
512
+
513
+ content_type : Optional [str ] = kwargs .pop ("content_type" , _headers .pop ("Content-Type" , None ))
514
+ cls : ClsType [_models .RadiologyInsightsInferenceResult ] = kwargs .pop ("cls" , None )
515
+ polling : Union [bool , PollingMethod ] = kwargs .pop ("polling" , True )
516
+ lro_delay = kwargs .pop ("polling_interval" , self ._config .polling_interval )
517
+ cont_token : Optional [str ] = kwargs .pop ("continuation_token" , None )
518
+ if cont_token is None :
519
+ raw_result = self ._infer_from_custom_model_id_initial (
520
+ body = body ,
521
+ inference_data = inference_data ,
522
+ id = id ,
523
+ content_type = content_type ,
524
+ cls = lambda x , y , z : x ,
525
+ headers = _headers ,
526
+ params = _params ,
527
+ ** kwargs ,
528
+ )
529
+ raw_result .http_response .read () # type: ignore
530
+ kwargs .pop ("error_map" , None )
531
+
532
+ def get_long_running_output (pipeline_response ):
533
+ response_headers = {}
534
+ response = pipeline_response .http_response
535
+ response_headers ["Operation-Location" ] = self ._deserialize (
536
+ "str" , response .headers .get ("Operation-Location" )
537
+ )
538
+
539
+ deserialized = _deserialize (_models .RadiologyInsightsInferenceResult , response .json ().get ("result" , {}))
540
+ if cls :
541
+ return cls (pipeline_response , deserialized , response_headers ) # type: ignore
542
+ return deserialized
543
+
544
+ path_format_arguments = {
545
+ "endpoint" : self ._serialize .url ("self._config.endpoint" , self ._config .endpoint , "str" , skip_quote = True ),
546
+ }
547
+
548
+ if polling is True :
549
+ polling_method : PollingMethod = cast (
550
+ PollingMethod , LROBasePolling (lro_delay , path_format_arguments = path_format_arguments , ** kwargs )
551
+ )
552
+ elif polling is False :
553
+ polling_method = cast (PollingMethod , NoPolling ())
554
+ else :
555
+ polling_method = polling
556
+ if cont_token :
557
+ return LROPoller [_models .RadiologyInsightsInferenceResult ].from_continuation_token (
558
+ polling_method = polling_method ,
559
+ continuation_token = cont_token ,
560
+ client = self ._client ,
561
+ deserialization_callback = get_long_running_output ,
562
+ )
563
+ return LROPoller [_models .RadiologyInsightsInferenceResult ](
564
+ self ._client , raw_result , get_long_running_output , polling_method # type: ignore
565
+ )
0 commit comments