Skip to content

Commit ad990bd

Browse files
Pylint Errors Fix for azure-ai-generative (#34180)
* fix line too long - 1 * fix line too long - 2 * fix line too long - 3 * fix line too long - 4 * fix import-error * fix unused-import * fix wrong-import-order error * fix import pylint errors * fix import pylint errors - 2 * fix whitespace errors * fix mypy error * fix too-many-locals errors * fix line-too-long errors - 5 * fix import errors - 2 * fix mypy error * fix mypy error - 2 * fix unused-variable errors * fix too-many-branches/too-many-statements errors * fix global-variable errors * fix no-else-return errors * fix mypy errors * fix protected-access errors * fix unspecified-encoding errors * fix unspecified-encoding errors - 2 * Merge branch 'main' into v-kevizhang/ai-generative-pylint-fix - 2 * fix name-too-long errors * fix attribute-defined-outside-init errors * fix file-needs-copyright-header errors * fix unused-argument errors - 1 * fix unused-argument errors - 2 * fix unused-argument errors - 3 * fix unnecessary-pass, no-member errors * fix logging-fstring-interpolation errors * fix inconsistent-return-statements errors * fix client related pylint errors * fix misc pylint errors * fix f-string-without-interpolation errors * fix misc errors - 2 * fix dangerous-default-value errors * fix misc errors - 3 * fix misc errors - 4 * fix misc errors - 5 * fix misc errors - 6 * fix broad-except errors - 1 * fix broad-except errors - 2 * fiix misc errors - 7 * fix docstring related errors - 1 * fix cracking.py docstring errors * fix docstring errors * fix mypy error * fix docstring errors - 2 * fix docstring format error * fix docstring related issues * fix misc pylint errors * fix docstring format error * fix misc pylint errors - 2 * fix misc pylint errors - 3 * fix error * fix misc pylint errors - 4 * enable pylint * fix pylint errors * fix pylint errors - 1 * fix pylint errors - 2 * fix pylint errors * fix comments issues
1 parent 39a6517 commit ad990bd

Some content is hidden

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

70 files changed

+4106
-2463
lines changed

sdk/ai/azure-ai-generative/azure/ai/generative/_telemetry/logging_handler.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ def get_appinsights_log_handler(
8585
if not in_jupyter_notebook() or enable_telemetry == "False":
8686
return logging.NullHandler()
8787

88-
if not user_agent or not any(name in user_agent.lower() for name in ["azure-ai-generative", "azure-ai-resources"]):
88+
if not user_agent or not any(
89+
name in user_agent.lower() for name in ["azure-ai-generative", "azure-ai-resources"]
90+
):
8991
return logging.NullHandler()
9092

9193
if "properties" in kwargs and "subscription_id" in kwargs.get("properties"):
@@ -221,6 +223,8 @@ def create_envelope(instrumentation_key, record):
221223
"traceId",
222224
"00000000000000000000000000000000",
223225
)
224-
envelope.tags["ai.generative.operation.parentId"] = f"|{envelope.tags.get('ai.generative.operation.id')}.{getattr(record, 'spanId', '0000000000000000')}"
226+
envelope.tags[
227+
"ai.generative.operation.parentId"
228+
] = f"|{envelope.tags.get('ai.generative.operation.id')}.{getattr(record, 'spanId', '0000000000000000')}"
225229

226230
return envelope

sdk/ai/azure-ai-generative/azure/ai/generative/evaluate/_base_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
class BaseHandler(metaclass=abc.ABCMeta):
9-
9+
# pylint: disable=unused-argument
1010
def __init__(self, asset, test_data, prediction_data=None, ground_truth=None, **kwargs):
1111
self._prediction_data = None
1212
self._input_output_data = None
@@ -47,4 +47,4 @@ def execute_target(self):
4747
"""
4848
Abstract method to generated prediction data and input output data.
4949
Should be implemented by all subclasses.
50-
"""
50+
"""

sdk/ai/azure-ai-generative/azure/ai/generative/evaluate/_client/openai_client.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,44 @@
33
# ---------------------------------------------------------
44
import asyncio
55
import logging
6+
from typing import Any, Dict, Optional
67

7-
from openai import AsyncAzureOpenAI, AzureOpenAI
8+
from openai import AzureOpenAI
89
from openai.types.chat.chat_completion import ChatCompletion
910

1011
from azure.ai.generative.evaluate._user_agent import USER_AGENT
1112
from azure.ai.generative.constants._common import USER_AGENT_HEADER_KEY
13+
from azure.core.credentials import TokenCredential
1214

1315
semaphore = asyncio.Semaphore(10)
1416

1517
LOGGER = logging.getLogger(__name__)
1618

1719

18-
class AzureOpenAIClient:
19-
20-
def __init__(self, openai_params):
21-
self._azure_endpoint = openai_params.get("azure_endpoint", None) if openai_params.get("azure_endpoint", None) \
20+
class AzureOpenAIClient: # pylint: disable=client-accepts-api-version-keyword
21+
# pylint: disable=unused-argument
22+
def __init__(self, openai_params: Dict, credential: Optional[TokenCredential] = None, **kwargs: Any) -> None:
23+
self._azure_endpoint = (
24+
openai_params.get("azure_endpoint", None)
25+
if openai_params.get("azure_endpoint", None)
2226
else openai_params.get("api_base", None)
27+
)
2328
self._api_key = openai_params.get("api_key", None)
2429
self._api_version = openai_params.get("api_version", None)
25-
self._azure_deployment = openai_params.get("azure_deployment", None)\
26-
if openai_params.get("azure_deployment", None) else openai_params.get("deployment_id", None)
30+
self._azure_deployment = (
31+
openai_params.get("azure_deployment", None)
32+
if openai_params.get("azure_deployment", None)
33+
else openai_params.get("deployment_id", None)
34+
)
2735

2836
self._client = AzureOpenAI(
2937
azure_endpoint=self._azure_endpoint.strip("/"),
3038
api_version=self._api_version,
3139
api_key=self._api_key,
32-
default_headers={
33-
USER_AGENT_HEADER_KEY: USER_AGENT,
34-
"client_operation_source": "evaluate"
35-
},
40+
default_headers={USER_AGENT_HEADER_KEY: USER_AGENT, "client_operation_source": "evaluate"},
3641
)
3742

38-
def bounded_chat_completion(self, messages):
43+
def bounded_chat_completion(self, messages: Any) -> Any:
3944
try:
4045
result = self._client.with_options(max_retries=5).chat.completions.create(
4146
model=self._azure_deployment,
@@ -44,12 +49,11 @@ def bounded_chat_completion(self, messages):
4449
seed=0,
4550
)
4651
return result
47-
except Exception as ex:
48-
LOGGER.debug(f"Failed to call llm with exception : {str(ex)}")
52+
except Exception as ex: # pylint: disable=broad-except
53+
LOGGER.debug("Failed to call llm with exception : %s", str(ex))
4954
return ex
5055

51-
@staticmethod
52-
def get_chat_completion_content_from_response(response):
56+
def get_chat_completion_content_from_response(self, response: Any) -> Any: # pylint: disable=name-too-long
5357
if isinstance(response, ChatCompletion):
5458
return response.choices[0].message.content
5559
return None

0 commit comments

Comments
 (0)