Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default value for _azure_ad_token attribute in AzureOpenAI class (#10245) #10377

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
2 changes: 1 addition & 1 deletion llama_index/llms/azure_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class AzureOpenAI(OpenAI):
description="Indicates if Microsoft Entra ID (former Azure AD) is used for token authentication"
)

_azure_ad_token: Any = PrivateAttr()
_azure_ad_token: Any = PrivateAttr(default=None)
_client: SyncAzureOpenAI = PrivateAttr()
_aclient: AsyncAzureOpenAI = PrivateAttr()

Expand Down
81 changes: 77 additions & 4 deletions poetry.lock

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

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ query_tools = [
]

[tool.poetry.group.dev.dependencies]
azure-identity = ">=1.15.0"
black = {extras = ["jupyter"], version = "<=23.9.1,>=23.7.0"}
boto3 = "1.33.6" # needed for tests
botocore = ">=1.33.13"
Expand Down
21 changes: 21 additions & 0 deletions tests/llms/test_azure_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,24 @@ def test_custom_http_client(sync_azure_openai_mock: MagicMock) -> None:
kwargs = sync_azure_openai_mock.call_args.kwargs
assert "http_client" in kwargs
assert kwargs["http_client"] == custom_http_client


@patch("llama_index.llms.azure_openai.SyncAzureOpenAI")
def test_azure_open_ai_with_azure_ad(sync_azure_openai_mock: MagicMock) -> None:
"""
Verify that a custom http_client set for AzureOpenAI.
Should get passed on to the implementation from OpenAI.
Use azure ad.
"""
custom_http_client = httpx.Client()
mock_instance = sync_azure_openai_mock.return_value
# Valid mocked result required to not run into another error
mock_instance.chat.completions.create.return_value = mock_chat_completion_v1()
azure_openai = AzureOpenAI(
engine="foo bar", http_client=custom_http_client, use_azure_ad=True
)
azure_openai.complete("test prompt")
sync_azure_openai_mock.assert_called()
kwargs = sync_azure_openai_mock.call_args.kwargs
assert "http_client" in kwargs
assert kwargs["http_client"] == custom_http_client
Loading