about summary refs log tree commit diff
path: root/.venv/lib/python3.12/site-packages/azure/ai/ml/entities/_monitoring/target.py
blob: 73a11895395102fdb431d7eac6749a8f7da990c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------

from typing import Optional, Union

from azure.ai.ml._restclient.v2023_06_01_preview.models import MonitoringTarget as RestMonitoringTarget
from azure.ai.ml.constants._monitoring import MonitorTargetTasks


class MonitoringTarget:
    """Monitoring target.

    :keyword ml_task: Type of task. Allowed values: Classification, Regression, and QuestionAnswering
    :paramtype ml_task: Optional[Union[str, MonitorTargetTasks]]
    :keyword endpoint_deployment_id: The ARM ID of the target deployment. Mutually exclusive with model_id.
    :paramtype endpoint_deployment_id: Optional[str]
    :keyword model_id: ARM ID of the target model ID. Mutually exclusive with endpoint_deployment_id.
    :paramtype model_id: Optional[str]

    .. admonition:: Example:

        .. literalinclude:: ../samples/ml_samples_spark_configurations.py
            :start-after: [START spark_monitor_definition]
            :end-before: [END spark_monitor_definition]
            :language: python
            :dedent: 8
            :caption: Setting a monitoring target using endpoint_deployment_id.
    """

    def __init__(
        self,
        *,
        ml_task: Optional[Union[str, MonitorTargetTasks]] = None,
        endpoint_deployment_id: Optional[str] = None,
        model_id: Optional[str] = None,
    ):
        self.endpoint_deployment_id = endpoint_deployment_id
        self.model_id = model_id
        self.ml_task = ml_task

    def _to_rest_object(self) -> RestMonitoringTarget:
        return RestMonitoringTarget(
            task_type=self.ml_task if self.ml_task else "classification",
            deployment_id=self.endpoint_deployment_id,
            model_id=self.model_id,
        )

    @classmethod
    def _from_rest_object(cls, obj: RestMonitoringTarget) -> "MonitoringTarget":
        return cls(
            ml_task=obj.task_type,
            endpoint_deployment_id=obj.endpoint_deployment_id,
            model_id=obj.model_id,
        )