Skip to content

Commit 6981ed3

Browse files
authored
[ml][ai] Turn on docstring validation (#33248)
* Turn on docstring validation * Remove whitespace * Resolve ai packages sphinx errors * Resolve ml packages sphinx errors * Resolve some ml sphinx errors * Fix remaining sphinx errors * Fix generative error * Make pylint mandatory * Fix some ml sphinx errors * Enable pylint check for docstring errors * Enable pylint check for docstring errors * Update ml and generative pyproject.toml files * Update syntax for enable/disable in pylint pyproject.toml sections * Try using disable config only * Disable pylint - will address in another PR * Revert init changes * Update sweep_job and _feature_set_operations * Turn off strict_sphinx check for azure-ai-ml * Fix sphinx issue in _custom_metric.py * Update name of job operations begin cancel sample * Reformat service_client param in model_operations method
1 parent 1f08994 commit 6981ed3

Some content is hidden

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

56 files changed

+398
-424
lines changed

sdk/ai/azure-ai-generative/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ For a more complete set of Azure libraries, see https://aka.ms/azsdk/python/all.
2323
### Install the package
2424
Install the Azure AI generative package for Python with pip:
2525

26-
```dotnetcli
26+
```
2727
pip install azure-ai-generative[index,evaluate,promptflow]
2828
pip install azure-identity
2929
```
@@ -131,7 +131,6 @@ If you encounter any bugs or have suggestions, please file an issue in the [Issu
131131
[azure_core_ref_docs]: https://aka.ms/azsdk-python-core-policies
132132
[azure_core]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/core/azure-core/README.md
133133
[azure_identity]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity
134-
[python_logging]: https://docs.python.org/3/library/logging.html
135134
[cla]: https://cla.microsoft.com
136135
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
137136
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/

sdk/ai/azure-ai-generative/azure/ai/generative/evaluate/metrics/_custom_metric.py

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,43 @@ def __init__(self, name):
2020
class CodeMetric(Metric):
2121
"""Evaluation code metric
2222
23-
:keyword name: Name of the metric.
24-
:paramtype name: str
25-
:keyword calculate: Function to compute row level metrics. It should have the following signature:
26-
27-
.. code-block:: python
28-
29-
def my_code_metric(
30-
*,
31-
data: Dict,
32-
response: Union[Dict, str],
33-
**kwargs,
34-
):
35-
'''
36-
:keyword data: Row data.This method will be called for each row.
37-
:paramtype data: Dict
38-
:keyword response: Response from target function passed to evaluate API otherwise None.
39-
:paramtype response: Dict
40-
:keyword kwargs: Includes params like data_mapping for this metric passed to evaluate API.
41-
:paramtype kwargs: Dict
42-
'''
43-
...
44-
:paramtype calculate: Callable
45-
:keyword aggregator: Function to aggregate row level metrics. It should have the following signature:
46-
.. code-block:: python
47-
48-
def my_aggregator(
49-
*,
50-
values,
51-
**kwargs,
52-
):
53-
'''
54-
:keyword values: Row level metric value calculated by calculate method of the metric.
55-
:paramtype values: Union[int, Dict[str, int]]
56-
:keyword kwargs: Includes params like data_mapping for this metric passed to evaluate API.
57-
:paramtype kwargs: Dict
58-
'''
59-
...
60-
:paramtype aggregator: Callable
61-
23+
:keyword name: Name of the metric.
24+
:paramtype name: str
25+
:keyword calculate: Function to compute row level metrics. It should have the following signature:
26+
27+
.. code:: python
28+
29+
def my_code_metric(
30+
data: Dict,
31+
response: Union[Dict, str],
32+
**kwargs,
33+
):
34+
'''
35+
:keyword data: Row data. This method will be called for each row.
36+
:paramtype data: Dict
37+
:keyword response: Response from target function passed to evaluate API otherwise None.
38+
:paramtype response: Dict
39+
:keyword kwargs: Includes params like data_mapping for this metric passed to evaluate API.
40+
:paramtype kwargs: Dict
41+
'''
42+
43+
:paramtype calculate: Callable
44+
:keyword aggregator: Function to aggregate row level metrics. It should have the following signature:
45+
46+
.. code:: python
47+
48+
def my_aggregator(
49+
values: Union[int, Dict[str, int]],
50+
**kwargs,
51+
):
52+
'''
53+
:keyword values: Row level metric value calculated by calculate method of the metric.
54+
:paramtype values: Union[int, Dict[str, int]]
55+
:keyword kwargs: Includes params like data_mapping for this metric passed to evaluate API.
56+
:paramtype kwargs: Dict
57+
'''
58+
59+
:paramtype aggregator: Callable
6260
"""
6361

6462
def __init__(self, *, name, calculate, aggregator=None, **kwargs):

sdk/ai/azure-ai-generative/azure/ai/generative/synthetic/qa.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,9 @@ def _modify_conversation_questions(self, questions) -> Tuple[List[str], Dict]:
260260
@distributed_trace
261261
@monitor_with_activity(logger, "QADataGenerator.Export", ActivityType.INTERNALCALL)
262262
def export_to_file(self, output_path: str, qa_type: QAType, results: Union[List, List[List]], output_format: OutputStructure = OutputStructure.PROMPTFLOW, field_mapping: Dict[str,str] = {"chat_history_key": "chat_history", "question_key": "question"}):
263-
"""
264-
Writes results from QA gen to a jsonl file for Promptflow batch run
265-
results is either a list of questions and answers or list of list of questions and answers grouped by their chunk
266-
e.g. [("How are you?", "I am good.")] or [ [("How are you?", "I am good.")], [("What can I do?", "Tell me a joke.")]
263+
"""Writes results from QA gen to a jsonl file for Promptflow batch run results is either a list of questions
264+
and answers or list of list of questions and answers grouped by their chunk e.g. [("How are you?",
265+
"I am good.")] or [ [("How are you?", "I am good.")], [("What can I do?", "Tell me a joke.")]
267266
"""
268267
data_dict = defaultdict(list)
269268

sdk/ai/azure-ai-generative/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ bandit = false
99
sphinx=true
1010
breaking = false
1111
whl_no_aio = false
12+
strict_sphinx = true
1213

1314
[tool.mypy]
1415
python_version = "3.10"

sdk/ai/azure-ai-resources/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ For a more complete set of Azure libraries, see https://aka.ms/azsdk/python/all.
2424
### Install the package
2525
Install the Azure AI generative package for Python with pip:
2626

27-
```dotnetcli
27+
```
2828
pip install azure-ai-resources
2929
pip install azure-identity
3030
```
@@ -97,7 +97,6 @@ If you encounter any bugs or have suggestions, please file an issue in the [Issu
9797
[azure_core_ref_docs]: https://aka.ms/azsdk-python-core-policies
9898
[azure_core]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/core/azure-core/README.md
9999
[azure_identity]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity
100-
[python_logging]: https://docs.python.org/3/library/logging.html
101100
[cla]: https://cla.microsoft.com
102101
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
103102
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ class IndexType(object):
3131
FAISS = "faiss"
3232

3333
class OperationScope:
34-
"""
35-
Some AI Client Operations can be applied to either the client's AI resource,
34+
"""Some AI Client Operations can be applied to either the client's AI resource
3635
or its project. For such operations, this is used to determine that scope.
3736
"""
3837
AI_RESOURCE = "ai_resource"

sdk/ai/azure-ai-resources/azure/ai/resources/entities/base_connection.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ class BaseConnection:
3232
:param id: The connection's resource id.
3333
:type id: str
3434
:param is_shared: For connections created for a project, this determines if the connection
35-
is shared amongst other connections with that project's parent AI resource.
36-
Defaults to true.
35+
is shared amongst other connections with that project's parent AI resource. Defaults to True.
3736
:type is_shared: bool
3837
"""
3938

@@ -79,10 +78,10 @@ def _from_v2_workspace_connection(cls, workspace_connection: WorkspaceConnection
7978

8079
@classmethod
8180
def _get_ai_connection_class_from_type(cls, conn_type: str):
82-
''' Given a connection type string, get the corresponding AI SDK object via class
81+
"""Given a connection type string, get the corresponding AI SDK object via class
8382
comparisons. Accounts for any potential camel/snake/capitalization issues. Returns
8483
the BaseConnection class if no match is found.
85-
'''
84+
"""
8685
#import here to avoid circular import
8786
from .connection_subtypes import (
8887
AzureOpenAIConnection,
@@ -194,7 +193,7 @@ def credentials(self, value: ApiKeyConfiguration): # Eventual TODO: re-add Mana
194193

195194
@property
196195
def tags(self) -> Dict[str, Any]:
197-
"""tags for the connection.
196+
"""Tags for the connection.
198197
199198
:return: This connection's tags.
200199
:rtype: Dict[str, Any]
@@ -236,26 +235,26 @@ def metadata(self, value: Dict[str, Any]):
236235

237236
@property
238237
def is_shared(self) -> bool:
239-
"""Get the Boolean describing if this connection is shared
240-
amongst its cohort within a workspace hub. Only applicable for connections
241-
that are project-scoped on creation.
238+
"""Get the Boolean describing if this connection is shared amongst its cohort within a workspace hub.
239+
Only applicable for connections that are project-scoped on creation.
240+
242241
:rtype: bool
243242
"""
244243
return self._workspace_connection.is_shared
245244

246245
@is_shared.setter
247246
def is_shared(self, value: bool):
248-
"""The is_shared determines if this connection is shared amongst other
249-
lean workspaces within its parent workspace hub. Only applicable for connections
250-
that are project-scoped on creation.
247+
"""The is_shared determines if this connection is shared amongst other lean workspaces within its parent
248+
workspace hub. Only applicable for connections that are project-scoped on creation.
249+
251250
:type value: bool
252251
"""
253252
if not value:
254253
return
255254
self._workspace_connection.is_shared = value
256255

257256
def set_current_environment(self, credential: Optional[TokenCredential] = None):
258-
"""Sets the current environment to use the connection. To use AAD auth for AzureOpenAI connetion, pass in a credential object.
257+
"""Sets the current environment to use the connection. To use AAD auth for AzureOpenAI connection, pass in a credential object.
259258
Only certain types of connections make use of this function. Those that don't will raise an error if this is called.
260259
261260
:param credential: Optional credential to use for the connection. If not provided, the connection's credentials will be used.

sdk/ai/azure-ai-resources/azure/ai/resources/entities/connection_subtypes.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ class AzureOpenAIConnection(BaseConnection):
3434
:param api_type: The api type that this connection was created for. Defaults to "Azure" and currently rarely changes.
3535
:type api_type: str
3636
:param is_shared: For connections created for a project, this determines if the connection
37-
is shared amongst other connections with that project's parent AI resource.
38-
Defaults to true.
37+
is shared amongst other connections with that project's parent AI resource. Defaults to True.
3938
:type is_shared: bool
4039
"""
4140

@@ -162,8 +161,7 @@ class AzureAISearchConnection(BaseConnection):
162161
:param api_version: The api version that this connection was created for. Only applies to certain connection types.
163162
:type api_version: Optional[str]
164163
:param is_shared: For connections created for a project, this determines if the connection
165-
is shared amongst other connections with that project's parent AI resource.
166-
Defaults to true.
164+
is shared amongst other connections with that project's parent AI resource. Defaults to True.
167165
:type is_shared: bool
168166
"""
169167

@@ -233,11 +231,10 @@ class AzureAIServiceConnection(BaseConnection):
233231
:param api_version: The api version that this connection was created for.
234232
:type api_version: Optional[str]
235233
:param kind: The kind of ai service that this connection points to. Valid inputs include:
236-
"AzureOpenAI", "ContentSafety", and "Speech"
234+
"AzureOpenAI", "ContentSafety", and "Speech".
237235
:type kind: str
238236
:param is_shared: For connections created for a project, this determines if the connection
239-
is shared amongst other connections with that project's parent AI resource.
240-
Defaults to true.
237+
is shared amongst other connections with that project's parent AI resource. Defaults to True.
241238
:type is_shared: bool
242239
"""
243240

@@ -305,8 +302,7 @@ class GitHubConnection(BaseConnection):
305302
:param credentials: The credentials for authenticating the external resource.
306303
:type credentials: ~azure.ai.ml.entities.ApiKeyConfiguration
307304
:param is_shared: For connections created for a project, this determines if the connection
308-
is shared amongst other connections with that project's parent AI resource.
309-
Defaults to true.
305+
is shared amongst other connections with that project's parent AI resource. Defaults to True.
310306
:type is_shared: bool
311307
"""
312308

@@ -332,8 +328,7 @@ class CustomConnection(BaseConnection):
332328
:param credentials: The credentials for authenticating the external resource.
333329
:type credentials: ~azure.ai.ml.entities.ApiKeyConfiguration
334330
:param is_shared: For connections created for a project, this determines if the connection
335-
is shared amongst other connections with that project's parent AI resource.
336-
Defaults to true.
331+
is shared amongst other connections with that project's parent AI resource. Defaults to True.
337332
:type is_shared: bool
338333
"""
339334
def __init__(

sdk/ai/azure-ai-resources/azure/ai/resources/operations/_ai_resource_operations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def get(self, *, name: str, **kwargs) -> AIResource:
4040
:paramtype name: str
4141
4242
:return: The AI resource with the provided name.
43-
:rtype: AIResource
43+
:rtype: ~azure.ai.resources.entities.AIResource
4444
"""
4545
workspace_hub = self._ml_client._workspace_hubs.get(name=name, **kwargs)
4646
resource = AIResource._from_v2_workspace_hub(workspace_hub)
@@ -55,7 +55,7 @@ def list(self, *, scope: str = Scope.RESOURCE_GROUP) -> Iterable[AIResource]:
5555
:paramtype scope: str
5656
5757
:return: An iterator like instance of AI resource objects
58-
:rtype: Iterable[AIResource]
58+
:rtype: Iterable[~azure.ai.resources.entities.AIResource]
5959
"""
6060
return [AIResource._from_v2_workspace_hub(wh) for wh in self._ml_client._workspace_hubs.list(scope=scope)]
6161

sdk/ai/azure-ai-resources/azure/ai/resources/operations/_project_operations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def get(self, *, name: Optional[str] = None, **kwargs: Dict) -> Project:
4747
:keyword name: Name of the project.
4848
:paramtype name: str
4949
:return: The project with the provided name.
50-
:rtype: Project
50+
:rtype: ~azure.ai.resource.entities.Project
5151
"""
5252

5353
workspace = self._ml_client._workspaces.get(name=name, **kwargs)
@@ -62,7 +62,7 @@ def list(self, *, scope: str = Scope.RESOURCE_GROUP) -> Iterable[Project]:
6262
:keyword scope: The scope of the listing. Can be either "resource_group" or "subscription", and defaults to "resource_group".
6363
:paramtype scope: str
6464
:return: An iterator like instance of Project objects
65-
:rtype: Iterable[Project]
65+
:rtype: Iterable[~azure.ai.resource.entities.Project]
6666
"""
6767

6868
workspaces = []

0 commit comments

Comments
 (0)