Skip to content

Commit

Permalink
fix!: Move azure auth provider to separate module (#4912)
Browse files Browse the repository at this point in the history
* Move azure auth provider to separate module

* Update lock

* fix component gen
  • Loading branch information
jackgerrits authored Jan 7, 2025
1 parent bdfdc6a commit 3105649
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion python/packages/autogen-ext/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ m1 = "autogen_ext.teams.magentic_one_cli:main"
langchain = ["langchain_core~= 0.3.3"]
azure = ["azure-core", "azure-identity"]
docker = ["docker~=7.0"]
openai = ["openai>=1.52.2", "aiofiles", "azure-core", "azure-identity"]
openai = ["openai>=1.52.2", "aiofiles"]
file-surfer = [
"autogen-agentchat==0.4.0.dev13",
"markitdown>=0.0.1a2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from typing import List

from autogen_core import Component
from azure.core.credentials import TokenProvider
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
from pydantic import BaseModel
from typing_extensions import Self

from azure.core.credentials import TokenProvider
from azure.identity import DefaultAzureCredential, get_bearer_token_provider


class TokenProviderConfig(BaseModel):
provider_kind: str
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from ._azure_token_provider import AzureTokenProvider
from ._openai_client import (
AzureOpenAIChatCompletionClient,
OpenAIChatCompletionClient,
Expand All @@ -10,5 +9,4 @@
"AzureOpenAIChatCompletionClient",
"OpenAIClientConfiguration",
"OpenAIChatCompletionClient",
"AzureTokenProvider",
]
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@
from pydantic import BaseModel
from typing_extensions import Self, Unpack

from autogen_ext.models.openai._azure_token_provider import AzureTokenProvider

from . import _model_info
from .config import (
AzureOpenAIClientConfiguration,
Expand Down Expand Up @@ -1076,8 +1074,9 @@ def __setstate__(self, state: Dict[str, Any]) -> None:
self._client = _azure_openai_client_from_config(state["_raw_config"])

def _to_config(self) -> AzureOpenAIClientConfigurationConfigModel:
copied_config = self._raw_config.copy()
from ...auth.azure import AzureTokenProvider

copied_config = self._raw_config.copy()
if "azure_ad_token_provider" in copied_config:
if not isinstance(copied_config["azure_ad_token_provider"], AzureTokenProvider):
raise ValueError("azure_ad_token_provider must be a AzureTokenProvider to be component serialized")
Expand All @@ -1090,6 +1089,8 @@ def _to_config(self) -> AzureOpenAIClientConfigurationConfigModel:

@classmethod
def _from_config(cls, config: AzureOpenAIClientConfigurationConfigModel) -> Self:
from ...auth.azure import AzureTokenProvider

copied_config = config.model_copy().model_dump(exclude_none=True)
if "azure_ad_token_provider" in copied_config:
copied_config["azure_ad_token_provider"] = AzureTokenProvider.load_component(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from pydantic import BaseModel
from typing_extensions import Required, TypedDict

from .._azure_token_provider import AzureTokenProvider


class ResponseFormat(TypedDict):
type: Literal["text", "json_object"]
Expand Down Expand Up @@ -51,7 +49,7 @@ class AzureOpenAIClientConfiguration(BaseOpenAIClientConfiguration, total=False)
azure_deployment: str
api_version: Required[str]
azure_ad_token: str
azure_ad_token_provider: AsyncAzureADTokenProvider | AzureTokenProvider
azure_ad_token_provider: AsyncAzureADTokenProvider # Or AzureTokenProvider


__all__ = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
ComponentConfigImpl,
_type_to_provider_str, # type: ignore
)
from autogen_ext.models.openai import AzureOpenAIChatCompletionClient, AzureTokenProvider, OpenAIChatCompletionClient
from autogen_ext.auth.azure import AzureTokenProvider
from autogen_ext.models.openai import AzureOpenAIChatCompletionClient, OpenAIChatCompletionClient
from pydantic import BaseModel

all_defs: Dict[str, Any] = {}
Expand Down
4 changes: 0 additions & 4 deletions python/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3105649

Please sign in to comment.