Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Some pyright fixes
  • Loading branch information
dargilco committed Apr 28, 2025
commit 1c4b405cf8d1ff8afb585739abf217b28a141bfc
12 changes: 8 additions & 4 deletions sdk/ai/azure-ai-projects/azure/ai/projects/_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
"""
import os
from typing import List, Any, Optional
from typing import List, Any, Optional, TYPE_CHECKING
from typing_extensions import Self
from azure.core.credentials import TokenCredential
from ._client import AIProjectClient as AIProjectClientGenerated
from .operations import TelemetryOperations, InferenceOperations
from ._patch_prompts import PromptTemplate
from ._patch_telemetry import enable_telemetry

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from azure.ai.agents import AgentsClient

_console_logging_enabled: bool = os.environ.get("ENABLE_AZURE_AI_PROJECTS_CONSOLE_LOGGING", "False").lower() in (
"true",
"1",
Expand Down Expand Up @@ -91,12 +95,12 @@ def __init__(self, endpoint: str, credential: TokenCredential, **kwargs: Any) ->

super().__init__(endpoint=endpoint, credential=credential, **kwargs)

self.telemetry = TelemetryOperations(self)
self.inference = InferenceOperations(self)
self.telemetry = TelemetryOperations(self) # type: ignore
self.inference = InferenceOperations(self) # type: ignore
self._agents = None

@property
def agents(self) -> "AgentsClient":
def agents(self) -> "AgentsClient": # type: ignore[name-defined]
"""Get the AgentsClient associated with this AIProjectClient.
The package azure.ai.agents must be installed to use this property.

Expand Down
6 changes: 4 additions & 2 deletions sdk/ai/azure-ai-projects/azure/ai/projects/_patch_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
import traceback
import sys
from pathlib import Path
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List, Optional, TYPE_CHECKING
from typing_extensions import Self

if TYPE_CHECKING:
from prompty import Prompty # type: ignore[import]

class PromptTemplate:
"""A helper class which takes variant of inputs, e.g. Prompty format or string, and returns the parsed prompt in an array.
Expand Down Expand Up @@ -155,7 +157,7 @@ def __init__(
else:
raise ValueError("Please pass valid arguments for PromptTemplate")

def create_messages(self, data: Optional[Dict[str, Any]] = None, **kwargs) -> List[Dict[str, Any]]:
def create_messages(self, data: Optional[Dict[str, Any]] = None, **kwargs: Any) -> List[Dict[str, Any]]:
"""Render the prompt template with the given data.

:param data: The data to render the prompt template with.
Expand Down
11 changes: 7 additions & 4 deletions sdk/ai/azure-ai-projects/azure/ai/projects/aio/_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@

Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
"""
from typing import List, Any, Optional
from typing import List, Any, TYPE_CHECKING
from typing_extensions import Self
from azure.core.credentials_async import AsyncTokenCredential
from ._client import AIProjectClient as AIProjectClientGenerated
from .._patch import _patch_user_agent
from .operations import InferenceOperations, TelemetryOperations

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from azure.ai.agents.aio import AgentsClient

class AIProjectClient(AIProjectClientGenerated): # pylint: disable=too-many-instance-attributes
"""AIProjectClient.
Expand Down Expand Up @@ -56,12 +59,12 @@ def __init__(self, endpoint: str, credential: AsyncTokenCredential, **kwargs: An

super().__init__(endpoint=endpoint, credential=credential, **kwargs)

self.telemetry = TelemetryOperations(self)
self.inference = InferenceOperations(self)
self.telemetry = TelemetryOperations(self) # type: ignore
self.inference = InferenceOperations(self) # type: ignore
self._agents = None

@property
def agents(self) -> "AgentsClient":
def agents(self) -> "AgentsClient": # type: ignore[name-defined]
"""Get the asynchronous AgentsClient associated with this AIProjectClient.
The package azure.ai.agents must be installed to use this property.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
"""
import logging
from typing import Optional, AsyncIterable
from typing import Optional, AsyncIterable, TYPE_CHECKING
from urllib.parse import urlparse
from azure.core.exceptions import ResourceNotFoundError
from azure.core.tracing.decorator_async import distributed_trace_async
Expand All @@ -21,6 +21,11 @@
)
from ...models._enums import CredentialType, ConnectionType

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from openai import AsyncAzureOpenAI
from azure.ai.inference.aio import ChatCompletionsClient, EmbeddingsClient, ImageEmbeddingsClient

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -59,7 +64,7 @@ def _get_inference_url(cls, input_url: str) -> str:
return new_url

@distributed_trace
def get_chat_completions_client(self, **kwargs) -> "ChatCompletionsClient": # type: ignore[name-defined]
def get_chat_completions_client(self, **kwargs: Any) -> "ChatCompletionsClient": # type: ignore[name-defined]
"""Get an authenticated asynchronous ChatCompletionsClient (from the package azure-ai-inference) to use with
AI models deployed to your AI Foundry Project. Keyword arguments are passed to the constructor of
ChatCompletionsClient.
Expand Down Expand Up @@ -101,7 +106,7 @@ def get_chat_completions_client(self, **kwargs) -> "ChatCompletionsClient": # t
return client

@distributed_trace
def get_embeddings_client(self, **kwargs) -> "EmbeddingsClient": # type: ignore[name-defined]
def get_embeddings_client(self, **kwargs: Any) -> "EmbeddingsClient": # type: ignore[name-defined]
"""Get an authenticated asynchronous EmbeddingsClient (from the package azure-ai-inference) to use with
AI models deployed to your AI Foundry Project. Keyword arguments are passed to the constructor of
ChatCompletionsClient.
Expand Down Expand Up @@ -143,7 +148,7 @@ def get_embeddings_client(self, **kwargs) -> "EmbeddingsClient": # type: ignore
return client

@distributed_trace
def get_image_embeddings_client(self, **kwargs) -> "ImageEmbeddingsClient": # type: ignore[name-defined]
def get_image_embeddings_client(self, **kwargs: Any) -> "ImageEmbeddingsClient": # type: ignore[name-defined]
"""Get an authenticated asynchronous ImageEmbeddingsClient (from the package azure-ai-inference) to use with
AI models deployed to your AI Foundry Project. Keyword arguments are passed to the constructor of
ChatCompletionsClient.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2062,7 +2062,7 @@ def pending_upload(

@distributed_trace
def get_credentials(self, name: str, version: str, body: Any, **kwargs: Any) -> _models.AssetCredentialResponse:
"""Get download sas for dataset version.
"""Get the SAS credential to access the storage account associated with a Dataset version.

:param name: The name of the resource. Required.
:type name: str
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
"""
import logging
from typing import Optional, Iterable
from typing import Optional, Iterable, TYPE_CHECKING
from urllib.parse import urlparse
from azure.core.exceptions import ResourceNotFoundError
from azure.core.tracing.decorator import distributed_trace
from ..models._models import Connection, ApiKeyCredentials, EntraIDCredentials
from ..models._enums import CredentialType, ConnectionType

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from openai import AzureOpenAI
from azure.ai.inference import ChatCompletionsClient, EmbeddingsClient, ImageEmbeddingsClient

logger = logging.getLogger(__name__)


Expand All @@ -24,8 +29,8 @@ class InferenceOperations:
**DO NOT** instantiate this class directly.

Instead, you should access the following operations through
:class:`~azure.ai.projects.AIProjectClient`'s
:attr:`inference` attribute.
def __init__(self, outer_instance: "AIProjectClient") -> None:
self._outer_instance = outer_instance
"""

def __init__(self, outer_instance: "azure.ai.projects.AIProjectClient") -> None: # type: ignore[name-defined]
Expand All @@ -52,7 +57,7 @@ def _get_inference_url(cls, input_url: str) -> str:
return new_url

@distributed_trace
def get_chat_completions_client(self, **kwargs) -> "ChatCompletionsClient": # type: ignore[name-defined]
def get_chat_completions_client(self, **kwargs: Any) -> "ChatCompletionsClient": # type: ignore[name-defined]
"""Get an authenticated ChatCompletionsClient (from the package azure-ai-inference) to use with
AI models deployed to your AI Foundry Project. Keyword arguments are passed to the constructor of
ChatCompletionsClient.
Expand Down Expand Up @@ -95,7 +100,7 @@ def get_chat_completions_client(self, **kwargs) -> "ChatCompletionsClient": # t
return client

@distributed_trace
def get_embeddings_client(self, **kwargs) -> "EmbeddingsClient": # type: ignore[name-defined]
def get_embeddings_client(self, **kwargs: Any) -> "EmbeddingsClient": # type: ignore[name-defined]
"""Get an authenticated EmbeddingsClient (from the package azure-ai-inference) to use with
AI models deployed to your AI Foundry Project. Keyword arguments are passed to the constructor of
ChatCompletionsClient.
Expand Down Expand Up @@ -137,7 +142,7 @@ def get_embeddings_client(self, **kwargs) -> "EmbeddingsClient": # type: ignore
return client

@distributed_trace
def get_image_embeddings_client(self, **kwargs) -> "ImageEmbeddingsClient": # type: ignore[name-defined]
def get_image_embeddings_client(self, **kwargs: Any) -> "ImageEmbeddingsClient": # type: ignore[name-defined]
"""Get an authenticated ImageEmbeddingsClient (from the package azure-ai-inference) to use with
AI models deployed to your AI Foundry Project. Keyword arguments are passed to the constructor of
ChatCompletionsClient.
Expand Down
6 changes: 2 additions & 4 deletions sdk/ai/azure-ai-projects/pyrightconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
"reportMissingImports": false,
"pythonVersion": "3.11",
"exclude": [
"azure/ai/projects/_client.py",
"azure/ai/projects/aio/_client.py",
"azure/ai/projects/operations/_operations.py",
"azure/ai/projects/aio/operations/_operations.py",
"**/_client.py",
"**/_operations.py",
],
"extraPaths": [
"./../../core/azure-core",
Expand Down
Loading