Skip to content

Commit afeb13c

Browse files
authored
[evaluation] chore: re-enable black in ci (#41668)
* chore: re-enable black in ci * style: reformat
1 parent 00fcd5c commit afeb13c

File tree

148 files changed

+4901
-4379
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+4901
-4379
lines changed

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@
5454
# in ai.projects. So we only import it if it's available and the user has ai.projects.
5555
try:
5656
from ._converters._ai_services import AIAgentConverter
57+
5758
_patch_all.append("AIAgentConverter")
5859
except ImportError:
59-
print("[INFO] Could not import AIAgentConverter. Please install the dependency with `pip install azure-ai-projects`.")
60+
print(
61+
"[INFO] Could not import AIAgentConverter. Please install the dependency with `pip install azure-ai-projects`."
62+
)
6063

6164

6265
__all__ = [
@@ -101,4 +104,4 @@
101104
"AzureOpenAITextSimilarityGrader",
102105
]
103106

104-
__all__.extend([p for p in _patch_all if p not in __all__])
107+
__all__.extend([p for p in _patch_all if p not in __all__])

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/_aoai/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
__all__ = [
99
"AzureOpenAIGrader",
10-
]
10+
]

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/_aoai/aoai_grader.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
@experimental
14-
class AzureOpenAIGrader():
14+
class AzureOpenAIGrader:
1515
"""
1616
Base class for Azure OpenAI grader wrappers, recommended only for use by experienced OpenAI API users.
1717
Combines a model configuration and any grader configuration
@@ -38,16 +38,20 @@ class AzureOpenAIGrader():
3838

3939
id = "aoai://general"
4040

41-
def __init__(self, *, model_config : Union[AzureOpenAIModelConfiguration, OpenAIModelConfiguration], grader_config: Dict[str, Any], **kwargs: Any):
41+
def __init__(
42+
self,
43+
*,
44+
model_config: Union[AzureOpenAIModelConfiguration, OpenAIModelConfiguration],
45+
grader_config: Dict[str, Any],
46+
**kwargs: Any,
47+
):
4248
self._model_config = model_config
4349
self._grader_config = grader_config
4450

4551
if kwargs.get("validate", True):
4652
self._validate_model_config()
4753
self._validate_grader_config()
4854

49-
50-
5155
def _validate_model_config(self) -> None:
5256
"""Validate the model configuration that this grader wrapper is using."""
5357
if "api_key" not in self._model_config or not self._model_config.get("api_key"):
@@ -58,7 +62,7 @@ def _validate_model_config(self) -> None:
5862
category=ErrorCategory.INVALID_VALUE,
5963
target=ErrorTarget.AOAI_GRADER,
6064
)
61-
65+
6266
def _validate_grader_config(self) -> None:
6367
"""Validate the grader configuration that this grader wrapper is using."""
6468

@@ -72,24 +76,24 @@ def get_client(self) -> Any:
7276
:return: The OpenAI client.
7377
:rtype: [~openai.OpenAI, ~openai.AzureOpenAI]
7478
"""
75-
default_headers = {
76-
"User-Agent": UserAgentSingleton().value
77-
}
79+
default_headers = {"User-Agent": UserAgentSingleton().value}
7880
if "azure_endpoint" in self._model_config:
79-
from openai import AzureOpenAI
80-
# TODO set default values?
81-
return AzureOpenAI(
81+
from openai import AzureOpenAI
82+
83+
# TODO set default values?
84+
return AzureOpenAI(
8285
azure_endpoint=self._model_config["azure_endpoint"],
83-
api_key=self._model_config.get("api_key", None), # Default-style access to appease linters.
84-
api_version=DEFAULT_AOAI_API_VERSION, # Force a known working version
86+
api_key=self._model_config.get("api_key", None), # Default-style access to appease linters.
87+
api_version=DEFAULT_AOAI_API_VERSION, # Force a known working version
8588
azure_deployment=self._model_config.get("azure_deployment", ""),
86-
default_headers=default_headers
89+
default_headers=default_headers,
8790
)
8891
from openai import OpenAI
92+
8993
# TODO add default values for base_url and organization?
9094
return OpenAI(
9195
api_key=self._model_config["api_key"],
9296
base_url=self._model_config.get("base_url", ""),
9397
organization=self._model_config.get("organization", ""),
94-
default_headers=default_headers
98+
default_headers=default_headers,
9599
)

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/_aoai/label_grader.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from .aoai_grader import AzureOpenAIGrader
1111

12+
1213
@experimental
1314
class AzureOpenAILabelGrader(AzureOpenAIGrader):
1415
"""
@@ -47,7 +48,7 @@ class AzureOpenAILabelGrader(AzureOpenAIGrader):
4748
def __init__(
4849
self,
4950
*,
50-
model_config : Union[AzureOpenAIModelConfiguration, OpenAIModelConfiguration],
51+
model_config: Union[AzureOpenAIModelConfiguration, OpenAIModelConfiguration],
5152
input: List[Dict[str, str]],
5253
labels: List[str],
5354
model: str,

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/_aoai/string_check_grader.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from .aoai_grader import AzureOpenAIGrader
1212

13+
1314
@experimental
1415
class AzureOpenAIStringCheckGrader(AzureOpenAIGrader):
1516
"""
@@ -43,7 +44,7 @@ class AzureOpenAIStringCheckGrader(AzureOpenAIGrader):
4344
def __init__(
4445
self,
4546
*,
46-
model_config : Union[AzureOpenAIModelConfiguration, OpenAIModelConfiguration],
47+
model_config: Union[AzureOpenAIModelConfiguration, OpenAIModelConfiguration],
4748
input: str,
4849
name: str,
4950
operation: Literal[

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/_aoai/text_similarity_grader.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from .aoai_grader import AzureOpenAIGrader
1212

13+
1314
@experimental
1415
class AzureOpenAITextSimilarityGrader(AzureOpenAIGrader):
1516
"""
@@ -57,7 +58,7 @@ class AzureOpenAITextSimilarityGrader(AzureOpenAIGrader):
5758
def __init__(
5859
self,
5960
*,
60-
model_config : Union[AzureOpenAIModelConfiguration, OpenAIModelConfiguration],
61+
model_config: Union[AzureOpenAIModelConfiguration, OpenAIModelConfiguration],
6162
evaluation_metric: Literal[
6263
"fuzzy_match",
6364
"bleu",

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/_azure/_envs.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
class AzureEnvironmentMetadata(TypedDict):
2121
"""Configuration for various Azure environments. All endpoints include a trailing slash."""
22+
2223
portal_endpoint: str
2324
"""The management portal for the Azure environment (e.g. https://portal.azure.com/)"""
2425
resource_manager_endpoint: str
@@ -107,15 +108,15 @@ async def get_cloud_async(self, name: str, *, update_cached: bool = True) -> Opt
107108

108109
def case_insensitive_match(d: Mapping[str, Any], key: str) -> Optional[Any]:
109110
key = key.strip().lower()
110-
return next((v for k,v in d.items() if k.strip().lower() == key), None)
111+
return next((v for k, v in d.items() if k.strip().lower() == key), None)
111112

112113
async with _ASYNC_LOCK:
113114
cloud = _KNOWN_AZURE_ENVIRONMENTS.get(name) or case_insensitive_match(_KNOWN_AZURE_ENVIRONMENTS, name)
114115
if cloud:
115116
return cloud
116-
default_endpoint = (_KNOWN_AZURE_ENVIRONMENTS
117-
.get(_DEFAULT_AZURE_ENV_NAME, {})
118-
.get("resource_manager_endpoint"))
117+
default_endpoint = _KNOWN_AZURE_ENVIRONMENTS.get(_DEFAULT_AZURE_ENV_NAME, {}).get(
118+
"resource_manager_endpoint"
119+
)
119120

120121
metadata_url = self.get_default_metadata_url(default_endpoint)
121122
clouds = await self.get_clouds_async(metadata_url=metadata_url, update_cached=update_cached)
@@ -124,10 +125,7 @@ def case_insensitive_match(d: Mapping[str, Any], key: str) -> Optional[Any]:
124125
return cloud_metadata
125126

126127
async def get_clouds_async(
127-
self,
128-
*,
129-
metadata_url: Optional[str] = None,
130-
update_cached: bool = True
128+
self, *, metadata_url: Optional[str] = None, update_cached: bool = True
131129
) -> Mapping[str, AzureEnvironmentMetadata]:
132130
metadata_url = metadata_url or self.get_default_metadata_url()
133131

@@ -149,7 +147,8 @@ def get_default_metadata_url(default_endpoint: Optional[str] = None) -> str:
149147
default_endpoint = default_endpoint or "https://management.azure.com/"
150148
metadata_url = os.getenv(
151149
_ENV_ARM_CLOUD_METADATA_URL,
152-
f"{default_endpoint}metadata/endpoints?api-version={AzureEnvironmentClient.DEFAULT_API_VERSION}")
150+
f"{default_endpoint}metadata/endpoints?api-version={AzureEnvironmentClient.DEFAULT_API_VERSION}",
151+
)
153152
return metadata_url
154153

155154
@staticmethod
@@ -197,7 +196,7 @@ def append_trailing_slash(url: str) -> str:
197196

198197
def recursive_update(d: Dict, u: Mapping) -> None:
199198
"""Recursively update a dictionary.
200-
199+
201200
:param Dict d: The dictionary to update.
202201
:param Mapping u: The mapping to update from.
203202
"""

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/_azure/_token_manager.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,13 @@ def get_aad_credential(self) -> Union[DefaultAzureCredential, ManagedIdentityCre
7373
return super().get_aad_credential()
7474

7575
def get_token(
76-
self, scopes = None, claims: Union[str, None] = None, tenant_id: Union[str, None] = None, enable_cae: bool = False, **kwargs: Any) -> AccessToken:
76+
self,
77+
scopes=None,
78+
claims: Union[str, None] = None,
79+
tenant_id: Union[str, None] = None,
80+
enable_cae: bool = False,
81+
**kwargs: Any
82+
) -> AccessToken:
7783
"""Get the API token. If the token is not available or has expired, refresh the token.
7884
7985
:return: API token

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/_common/constants.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@
55

66
from azure.core import CaseInsensitiveEnumMeta
77

8-
PROMPT_BASED_REASON_EVALUATORS = ["coherence", "relevance", "retrieval", "groundedness", "fluency", "intent_resolution",
9-
"tool_call_accurate", "response_completeness", "task_adherence"]
8+
PROMPT_BASED_REASON_EVALUATORS = [
9+
"coherence",
10+
"relevance",
11+
"retrieval",
12+
"groundedness",
13+
"fluency",
14+
"intent_resolution",
15+
"tool_call_accurate",
16+
"response_completeness",
17+
"task_adherence",
18+
]
1019

1120

1221
class CommonConstants:

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/_common/evaluation_onedp_client.py

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@
66
from typing import Union, Any, Dict
77
from azure.core.credentials import AzureKeyCredential, TokenCredential
88
from azure.ai.evaluation._common.onedp import AIProjectClient as RestEvaluationServiceClient
9-
from azure.ai.evaluation._common.onedp.models import (PendingUploadRequest, PendingUploadType, EvaluationResult,
10-
ResultType, AssetCredentialRequest, EvaluationUpload, InputDataset, RedTeamUpload)
9+
from azure.ai.evaluation._common.onedp.models import (
10+
PendingUploadRequest,
11+
PendingUploadType,
12+
EvaluationResult,
13+
ResultType,
14+
AssetCredentialRequest,
15+
EvaluationUpload,
16+
InputDataset,
17+
RedTeamUpload,
18+
)
1119
from azure.storage.blob import ContainerClient
1220
from .utils import upload
1321

1422
LOGGER = logging.getLogger(__name__)
1523

24+
1625
class EvaluationServiceOneDPClient:
1726

1827
def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None:
@@ -23,7 +32,15 @@ def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCr
2332
)
2433

2534
def create_evaluation_result(
26-
self, *, name: str, path: str, version=1, metrics: Dict[str, int]=None, result_type: ResultType=ResultType.EVALUATION, **kwargs) -> EvaluationResult:
35+
self,
36+
*,
37+
name: str,
38+
path: str,
39+
version=1,
40+
metrics: Dict[str, int] = None,
41+
result_type: ResultType = ResultType.EVALUATION,
42+
**kwargs,
43+
) -> EvaluationResult:
2744
"""Create and upload evaluation results to Azure evaluation service.
2845
2946
This method uploads evaluation results from a local path to Azure Blob Storage
@@ -49,17 +66,20 @@ def create_evaluation_result(
4966
:raises: Various exceptions from the underlying API calls or upload process
5067
"""
5168

52-
LOGGER.debug(f"Creating evaluation result for {name} with version {version} type {result_type} from path {path}")
69+
LOGGER.debug(
70+
f"Creating evaluation result for {name} with version {version} type {result_type} from path {path}"
71+
)
5372
start_pending_upload_response = self.rest_client.evaluation_results.start_pending_upload(
5473
name=name,
5574
version=version,
5675
body=PendingUploadRequest(pending_upload_type=PendingUploadType.TEMPORARY_BLOB_REFERENCE),
57-
**kwargs
76+
**kwargs,
5877
)
5978

6079
LOGGER.debug(f"Uploading {path} to {start_pending_upload_response.blob_reference_for_consumption.blob_uri}")
6180
with ContainerClient.from_container_url(
62-
start_pending_upload_response.blob_reference_for_consumption.credential.sas_uri) as container_client:
81+
start_pending_upload_response.blob_reference_for_consumption.credential.sas_uri
82+
) as container_client:
6383
upload(path=path, container_client=container_client, logger=LOGGER)
6484

6585
LOGGER.debug(f"Creating evaluation result version for {name} with version {version}")
@@ -73,7 +93,7 @@ def create_evaluation_result(
7393
),
7494
name=name,
7595
version=version,
76-
**kwargs
96+
**kwargs,
7797
)
7898

7999
return create_version_response
@@ -90,10 +110,7 @@ def start_evaluation_run(self, *, evaluation: EvaluationUpload, **kwargs) -> Eva
90110
:rtype: EvaluationUpload
91111
:raises: Various exceptions from the underlying API calls
92112
"""
93-
upload_run_response = self.rest_client.evaluations.upload_run(
94-
evaluation=evaluation,
95-
**kwargs
96-
)
113+
upload_run_response = self.rest_client.evaluations.upload_run(evaluation=evaluation, **kwargs)
97114

98115
return upload_run_response
99116

@@ -112,11 +129,7 @@ def update_evaluation_run(self, *, name: str, evaluation: EvaluationUpload, **kw
112129
:rtype: EvaluationUpload
113130
:raises: Various exceptions from the underlying API calls
114131
"""
115-
update_run_response = self.rest_client.evaluations.upload_update_run(
116-
name=name,
117-
evaluation=evaluation,
118-
**kwargs
119-
)
132+
update_run_response = self.rest_client.evaluations.upload_update_run(name=name, evaluation=evaluation, **kwargs)
120133

121134
return update_run_response
122135

@@ -132,10 +145,7 @@ def start_red_team_run(self, *, red_team: RedTeamUpload, **kwargs):
132145
:rtype: ~azure.ai.evaluation._common.onedp.models.RedTeamUpload
133146
:raises: Various exceptions from the underlying API calls
134147
"""
135-
upload_run_response = self.rest_client.red_teams.upload_run(
136-
redteam=red_team,
137-
**kwargs
138-
)
148+
upload_run_response = self.rest_client.red_teams.upload_run(redteam=red_team, **kwargs)
139149

140150
return upload_run_response
141151

@@ -154,10 +164,6 @@ def update_red_team_run(self, *, name: str, red_team: RedTeamUpload, **kwargs):
154164
:rtype: ~azure.ai.evaluation._common.onedp.models.RedTeamUpload
155165
:raises: Various exceptions from the underlying API calls
156166
"""
157-
update_run_response = self.rest_client.red_teams.upload_update_run(
158-
name=name,
159-
redteam=red_team,
160-
**kwargs
161-
)
167+
update_run_response = self.rest_client.red_teams.upload_update_run(name=name, redteam=red_team, **kwargs)
162168

163-
return update_run_response
169+
return update_run_response

0 commit comments

Comments
 (0)