Skip to content

Typing experiments#45831

Merged
dargilco merged 1 commit intoAzure:dargilco/typing-experimentsfrom
kashifkhan:typing-experiments
Mar 20, 2026
Merged

Typing experiments#45831
dargilco merged 1 commit intoAzure:dargilco/typing-experimentsfrom
kashifkhan:typing-experiments

Conversation

@dargilco
Copy link
Copy Markdown
Member

Description

Please add an informative description that covers that changes made by the pull request and link all relevant issues.

If an SDK is being regenerated based on a new API spec, a link to the pull request containing these API spec changes should be included above.

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Copilot AI review requested due to automatic review settings March 20, 2026 21:37
@dargilco dargilco changed the base branch from main to dargilco/typing-experiments March 20, 2026 21:38
@dargilco dargilco merged commit 39439b4 into Azure:dargilco/typing-experiments Mar 20, 2026
13 of 19 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a typing “patch” layer for azure-ai-projects so the OpenAI client returned by AIProjectClient.get_openai_client() can accept Azure-specific grader types for evals.create(), and updates a local typing experiment script to use the new type.

Changes:

  • Added a new _patch.pyi type stub to widen evals.create(testing_criteria=...) accepted types.
  • Updated get_openai_client return annotation in _patch.py to reference OpenAI directly.
  • Updated the typing experiment sample to use find_dotenv() and to reference AzureAIGraderCoherenceParam from _patch.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
sdk/ai/azure-ai-projects/typing-experiments/modified_sample_evaluations_graders.py Updates the experiment script to use the new grader TypedDict and tweaks dotenv loading; currently contains a runtime import issue and double-create resource leak.
sdk/ai/azure-ai-projects/azure/ai/projects/_patch.pyi Introduces the type stub that widens accepted grader types and re-types get_openai_client(); packaging/syntax compatibility concerns noted.
sdk/ai/azure-ai-projects/azure/ai/projects/_patch.py Minor signature typing change for get_openai_client(); one now-redundant type: ignore remains.

Comment on lines 182 to +194
testing_criteria=testing_criteria,
)
eval_object = client.evals.create(
name="OpenAI graders test",
data_source_config=data_source_config,
testing_criteria=[
AzureAIGraderCoherenceParam(
type="azure_ai_evaluator",
name="coherence",
evaluator_name="builtin.coherence",
initialization_parameters={"deployment_name": f"{model_deployment_name}"},
data_mapping={"query": "{{item.query}}", "response": "{{item.response}}"},
)],
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script creates an evaluation twice (client.evals.create(...) is called twice) but only deletes the second one (the first eval_object is overwritten). This will leave an evaluation resource behind and can create clutter/cost. Consider deleting both evaluations (track both ids) or remove the redundant first create call.

Suggested change
testing_criteria=testing_criteria,
)
eval_object = client.evals.create(
name="OpenAI graders test",
data_source_config=data_source_config,
testing_criteria=[
AzureAIGraderCoherenceParam(
type="azure_ai_evaluator",
name="coherence",
evaluator_name="builtin.coherence",
initialization_parameters={"deployment_name": f"{model_deployment_name}"},
data_mapping={"query": "{{item.query}}", "response": "{{item.response}}"},
)],
testing_criteria=[
AzureAIGraderCoherenceParam(
type="azure_ai_evaluator",
name="coherence",
evaluator_name="builtin.coherence",
initialization_parameters={"deployment_name": f"{model_deployment_name}"},
data_mapping={"query": "{{item.query}}", "response": "{{item.response}}"},
)
],

Copilot uses AI. Check for mistakes.
Comment on lines +47 to +52
metadata: Optional[Metadata] | Omit = ...,
name: str | Omit = ...,
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = ...,
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stub uses PEP 604 unions (e.g., Headers | None, str | Omit). Since this package supports Python 3.9, some type-checking setups targeting 3.9 will reject this syntax. Prefer Union[...] / Optional[...] forms in the .pyi to keep it compatible with Python 3.9 type checkers.

Suggested change
metadata: Optional[Metadata] | Omit = ...,
name: str | Omit = ...,
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = ...,
metadata: Union[Optional[Metadata], Omit] = ...,
name: Union[str, Omit] = ...,
extra_headers: Optional[Headers] = None,
extra_query: Optional[Query] = None,
extra_body: Optional[Body] = None,
timeout: Union[float, httpx.Timeout, None, NotGiven] = ...,

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +10
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
"""Type stub for _patch.py.

Overrides get_openai_client() return type so that evals.create() accepts
Azure-specific grader types in addition to the standard OpenAI graders.
"""

Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding _patch.pyi may not affect consumers unless it is included in the published sdist/wheel. In this package, MANIFEST.in only includes py.typed and pyproject.toml's [tool.setuptools.package-data] only lists py.typed, so the new .pyi is likely not shipped. Please update packaging config to include azure/ai/projects/_patch.pyi (or *.pyi) as package data.

Copilot uses AI. Check for mistakes.

@distributed_trace
def get_openai_client(self, **kwargs: Any) -> "OpenAI": # type: ignore[name-defined] # pylint: disable=too-many-statements
def get_openai_client(self, **kwargs: Any) -> OpenAI: # type: ignore[name-defined] # pylint: disable=too-many-statements
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenAI is imported in this module (from openai import OpenAI), so # type: ignore[name-defined] on the return annotation is no longer necessary and may hide real type issues. Consider removing the type: ignore[name-defined] here.

Suggested change
def get_openai_client(self, **kwargs: Any) -> OpenAI: # type: ignore[name-defined] # pylint: disable=too-many-statements
def get_openai_client(self, **kwargs: Any) -> OpenAI: # pylint: disable=too-many-statements

Copilot uses AI. Check for mistakes.
from openai.types.eval_create_params import DataSourceConfigCustom
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
from azure.ai.projects._patch import AzureAIGraderCoherenceParam
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AzureAIGraderCoherenceParam is imported from azure.ai.projects._patch, but it only exists in _patch.pyi (type stub) and is not defined in _patch.py, so this import will fail at runtime. Either define/export AzureAIGraderCoherenceParam in _patch.py (e.g., as a TypedDict) or keep the TypedDict definition local to this script (or gate the import behind TYPE_CHECKING and avoid using it at runtime).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants