Skip to content

Commit dc39f58

Browse files
fix bitwise OR for function typing in python 3.8
1 parent ff6a333 commit dc39f58

File tree

4 files changed

+73
-39
lines changed

4 files changed

+73
-39
lines changed
Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright (c) 2024 Oracle and/or its affiliates.
4+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
5+
16
import json
7+
from importlib import metadata
28
from typing import List, Union
39

410
from ads.aqua import ODSC_MODEL_COMPARTMENT_OCID, fetch_service_compartment
511
from ads.aqua.common.decorator import handle_exceptions
612
from ads.aqua.common.errors import AquaResourceAccessError
713
from ads.aqua.common.utils import known_realm
814
from ads.aqua.extension.aqua_ws_msg_handler import AquaWSMsgHandler
9-
from ads.aqua.extension.models.ws_models import RequestResponseType, AdsVersionResponse, AdsVersionRequest, \
10-
CompatibilityCheckResponse
11-
from importlib import metadata
15+
from ads.aqua.extension.models.ws_models import (
16+
AdsVersionResponse,
17+
CompatibilityCheckResponse,
18+
RequestResponseType,
19+
)
1220

1321

1422
class AquaCommonWsMsgHandler(AquaWSMsgHandler):
15-
1623
@staticmethod
1724
def get_message_types() -> List[RequestResponseType]:
1825
return [RequestResponseType.AdsVersion, RequestResponseType.CompatibilityCheck]
@@ -21,25 +28,30 @@ def __init__(self, message: Union[str, bytes]):
2128
super().__init__(message)
2229

2330
@handle_exceptions
24-
def process(self) -> AdsVersionResponse | CompatibilityCheckResponse:
31+
def process(self) -> Union[AdsVersionResponse, CompatibilityCheckResponse]:
2532
request = json.loads(self.message)
26-
if request.get('kind') == 'AdsVersion':
33+
if request.get("kind") == "AdsVersion":
2734
version = metadata.version("oracle_ads")
2835
response = AdsVersionResponse(
2936
message_id=request.get("message_id"),
3037
kind=RequestResponseType.AdsVersion,
31-
data=version)
38+
data=version,
39+
)
3240
return response
33-
if request.get('kind') == 'CompatibilityCheck':
41+
if request.get("kind") == "CompatibilityCheck":
3442
if ODSC_MODEL_COMPARTMENT_OCID or fetch_service_compartment():
35-
return CompatibilityCheckResponse(message_id=request.get("message_id"),
36-
kind=RequestResponseType.CompatibilityCheck,
37-
data={'status': 'ok'})
43+
return CompatibilityCheckResponse(
44+
message_id=request.get("message_id"),
45+
kind=RequestResponseType.CompatibilityCheck,
46+
data={"status": "ok"},
47+
)
3848
elif known_realm():
39-
return CompatibilityCheckResponse(message_id=request.get("message_id"),
40-
kind=RequestResponseType.CompatibilityCheck,
41-
data={'status': 'compatible'})
49+
return CompatibilityCheckResponse(
50+
message_id=request.get("message_id"),
51+
kind=RequestResponseType.CompatibilityCheck,
52+
data={"status": "compatible"},
53+
)
4254
else:
4355
raise AquaResourceAccessError(
44-
f"The AI Quick actions extension is not compatible in the given region."
56+
"The AI Quick actions extension is not compatible in the given region."
4557
)
Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright (c) 2024 Oracle and/or its affiliates.
4+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
5+
16
import json
27
from typing import List, Union
38

49
from ads.aqua.common.decorator import handle_exceptions
510
from ads.aqua.extension.aqua_ws_msg_handler import AquaWSMsgHandler
6-
from ads.aqua.extension.models.ws_models import RequestResponseType, ListDeploymentResponse, ListDeploymentRequest, \
7-
ModelDeploymentDetailsResponse
11+
from ads.aqua.extension.models.ws_models import (
12+
ListDeploymentResponse,
13+
ModelDeploymentDetailsResponse,
14+
RequestResponseType,
15+
)
816
from ads.aqua.modeldeployment import AquaDeploymentApp
917
from ads.config import COMPARTMENT_OCID
1018

1119

1220
class AquaDeploymentWSMsgHandler(AquaWSMsgHandler):
13-
1421
def __init__(self, message: Union[str, bytes]):
1522
super().__init__(message)
1623

1724
@staticmethod
1825
def get_message_types() -> List[RequestResponseType]:
19-
return [RequestResponseType.ListDeployments, RequestResponseType.DeploymentDetails]
26+
return [
27+
RequestResponseType.ListDeployments,
28+
RequestResponseType.DeploymentDetails,
29+
]
2030

2131
@handle_exceptions
22-
def process(self) -> ListDeploymentResponse | ModelDeploymentDetailsResponse:
32+
def process(self) -> Union[ListDeploymentResponse, ModelDeploymentDetailsResponse]:
2333
request = json.loads(self.message)
2434
if request.get("kind") == "ListDeployments":
2535
deployment_list = AquaDeploymentApp().list(
@@ -33,8 +43,12 @@ def process(self) -> ListDeploymentResponse | ModelDeploymentDetailsResponse:
3343
)
3444
return response
3545
elif request.get("kind") == "DeploymentDetails":
36-
deployment_details = AquaDeploymentApp().get(request.get("model_deployment_id"))
37-
response = ModelDeploymentDetailsResponse(message_id=request.get("message_id"),
38-
kind=RequestResponseType.DeploymentDetails,
39-
data=deployment_details)
46+
deployment_details = AquaDeploymentApp().get(
47+
request.get("model_deployment_id")
48+
)
49+
response = ModelDeploymentDetailsResponse(
50+
message_id=request.get("message_id"),
51+
kind=RequestResponseType.DeploymentDetails,
52+
data=deployment_details,
53+
)
4054
return response

ads/aqua/extension/evaluation_ws_msg_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(self, message: Union[str, bytes]):
2929
super().__init__(message)
3030

3131
@handle_exceptions
32-
def process(self) -> ListEvaluationsResponse | EvaluationDetailsResponse:
32+
def process(self) -> Union[ListEvaluationsResponse, EvaluationDetailsResponse]:
3333
request = json.loads(self.message)
3434
if request["kind"] == "ListEvaluations":
3535
return self.list_evaluations(request)
Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,49 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright (c) 2024 Oracle and/or its affiliates.
4+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
5+
16
import json
27
from typing import List, Union
38

49
from ads.aqua.common.decorator import handle_exceptions
510
from ads.aqua.extension.aqua_ws_msg_handler import AquaWSMsgHandler
6-
from ads.aqua.extension.models.ws_models import RequestResponseType, ListModelsResponse, ListModelsRequest, \
7-
ModelDetailsResponse
11+
from ads.aqua.extension.models.ws_models import (
12+
ListModelsResponse,
13+
ModelDetailsResponse,
14+
RequestResponseType,
15+
)
816
from ads.aqua.model import AquaModelApp
917

1018

1119
class AquaModelWSMsgHandler(AquaWSMsgHandler):
12-
1320
def __init__(self, message: Union[str, bytes]):
1421
super().__init__(message)
1522

1623
@staticmethod
1724
def get_message_types() -> List[RequestResponseType]:
18-
return [RequestResponseType.ListModels,RequestResponseType.ModelDetails]
25+
return [RequestResponseType.ListModels, RequestResponseType.ModelDetails]
1926

2027
@handle_exceptions
21-
def process(self) -> ListModelsResponse | ModelDetailsResponse:
28+
def process(self) -> Union[ListModelsResponse, ModelDetailsResponse]:
2229
request = json.loads(self.message)
23-
if request.get('kind') == 'ListModels':
30+
if request.get("kind") == "ListModels":
2431
models_list = AquaModelApp().list(
2532
compartment_id=request.get("compartment_id"),
2633
project_id=request.get("project_id"),
27-
model_type=request.get("model_type")
34+
model_type=request.get("model_type"),
2835
)
2936
response = ListModelsResponse(
3037
message_id=request.get("message_id"),
3138
kind=RequestResponseType.ListModels,
3239
data=models_list,
3340
)
3441
return response
35-
elif request.get('kind') == 'ModelDetails':
36-
model_id=request.get("model_id")
37-
response=AquaModelApp().get(model_id)
38-
return ModelDetailsResponse(message_id=request.get("message_id"),
39-
kind=RequestResponseType.ModelDetails,
40-
data=response)
41-
42+
elif request.get("kind") == "ModelDetails":
43+
model_id = request.get("model_id")
44+
response = AquaModelApp().get(model_id)
45+
return ModelDetailsResponse(
46+
message_id=request.get("message_id"),
47+
kind=RequestResponseType.ModelDetails,
48+
data=response,
49+
)

0 commit comments

Comments
 (0)