From 19e41c8f22b734c7cd78f2468ce9ecfe4977eec0 Mon Sep 17 00:00:00 2001 From: Ancelin Serre Date: Wed, 31 Jan 2024 16:56:06 +0100 Subject: [PATCH 1/4] fix: add default value for _azure_ad_token (#10245) --- llama_index/llms/azure_openai.py | 2 +- tests/llms/test_azure_openai.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/llama_index/llms/azure_openai.py b/llama_index/llms/azure_openai.py index 51fabe0a43cc9..70dfc19c449f0 100644 --- a/llama_index/llms/azure_openai.py +++ b/llama_index/llms/azure_openai.py @@ -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() diff --git a/tests/llms/test_azure_openai.py b/tests/llms/test_azure_openai.py index bd0f9624ed0a9..e7e370c2ca181 100644 --- a/tests/llms/test_azure_openai.py +++ b/tests/llms/test_azure_openai.py @@ -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 From 0e3b6d540d4e077b6846af13130e6247748e34c2 Mon Sep 17 00:00:00 2001 From: Ancelin Serre Date: Thu, 1 Feb 2024 12:02:59 +0100 Subject: [PATCH 2/4] fix: add azure-identity dependency --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index d8e6a8ac14fed..803139f32d706 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" From c2007deb717f28ae43bccae5319099146fabc776 Mon Sep 17 00:00:00 2001 From: Haotian Zhang Date: Thu, 1 Feb 2024 16:40:12 -0800 Subject: [PATCH 3/4] cr --- poetry.lock | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 4 deletions(-) diff --git a/poetry.lock b/poetry.lock index d906ea9feca65..a17599c1ab31c 100644 --- a/poetry.lock +++ b/poetry.lock @@ -427,6 +427,42 @@ docs = ["sphinx-copybutton (>=0.4,<0.5)", "sphinx-rtd-theme (>=1.0,<2.0)", "sphi erdantic = ["erdantic (>=0.5,<0.6)"] test = ["coverage (>=7,<8)", "pytest (>=7,<8)"] +[[package]] +name = "azure-core" +version = "1.30.0" +description = "Microsoft Azure Core Library for Python" +optional = false +python-versions = ">=3.7" +files = [ + {file = "azure-core-1.30.0.tar.gz", hash = "sha256:6f3a7883ef184722f6bd997262eddaf80cfe7e5b3e0caaaf8db1695695893d35"}, + {file = "azure_core-1.30.0-py3-none-any.whl", hash = "sha256:3dae7962aad109610e68c9a7abb31d79720e1d982ddf61363038d175a5025e89"}, +] + +[package.dependencies] +requests = ">=2.21.0" +six = ">=1.11.0" +typing-extensions = ">=4.6.0" + +[package.extras] +aio = ["aiohttp (>=3.0)"] + +[[package]] +name = "azure-identity" +version = "1.15.0" +description = "Microsoft Azure Identity Library for Python" +optional = false +python-versions = ">=3.7" +files = [ + {file = "azure-identity-1.15.0.tar.gz", hash = "sha256:4c28fc246b7f9265610eb5261d65931183d019a23d4b0e99357facb2e6c227c8"}, + {file = "azure_identity-1.15.0-py3-none-any.whl", hash = "sha256:a14b1f01c7036f11f148f22cd8c16e05035293d714458d6b44ddf534d93eb912"}, +] + +[package.dependencies] +azure-core = ">=1.23.0,<2.0.0" +cryptography = ">=2.5" +msal = ">=1.24.0,<2.0.0" +msal-extensions = ">=0.3.0,<2.0.0" + [[package]] name = "babel" version = "2.14.0" @@ -3134,7 +3170,7 @@ tests = ["pytest (>=4.6)"] name = "msal" version = "1.26.0" description = "The Microsoft Authentication Library (MSAL) for Python library enables your app to access the Microsoft Cloud by supporting authentication of users with Microsoft Azure Active Directory accounts (AAD) and Microsoft Accounts (MSA) using industry standard OAuth2 and OpenID Connect." -optional = true +optional = false python-versions = ">=2.7" files = [ {file = "msal-1.26.0-py2.py3-none-any.whl", hash = "sha256:be77ba6a8f49c9ff598bbcdc5dfcf1c9842f3044300109af738e8c3e371065b5"}, @@ -3149,6 +3185,25 @@ requests = ">=2.0.0,<3" [package.extras] broker = ["pymsalruntime (>=0.13.2,<0.14)"] +[[package]] +name = "msal-extensions" +version = "1.1.0" +description = "Microsoft Authentication Library extensions (MSAL EX) provides a persistence API that can save your data on disk, encrypted on Windows, macOS and Linux. Concurrent data access will be coordinated by a file lock mechanism." +optional = false +python-versions = ">=3.7" +files = [ + {file = "msal-extensions-1.1.0.tar.gz", hash = "sha256:6ab357867062db7b253d0bd2df6d411c7891a0ee7308d54d1e4317c1d1c54252"}, + {file = "msal_extensions-1.1.0-py3-none-any.whl", hash = "sha256:01be9711b4c0b1a151450068eeb2c4f0997df3bba085ac299de3a66f585e382f"}, +] + +[package.dependencies] +msal = ">=0.4.1,<2.0.0" +packaging = "*" +portalocker = [ + {version = ">=1.0,<3", markers = "platform_system != \"Windows\""}, + {version = ">=1.6,<3", markers = "platform_system == \"Windows\""}, +] + [[package]] name = "multidict" version = "6.0.4" @@ -4155,6 +4210,25 @@ files = [ {file = "ply-3.11.tar.gz", hash = "sha256:00c7c1aaa88358b9c765b6d3000c6eec0ba42abca5351b095321aef446081da3"}, ] +[[package]] +name = "portalocker" +version = "2.8.2" +description = "Wraps the portalocker recipe for easy usage" +optional = false +python-versions = ">=3.8" +files = [ + {file = "portalocker-2.8.2-py3-none-any.whl", hash = "sha256:cfb86acc09b9aa7c3b43594e19be1345b9d16af3feb08bf92f23d4dce513a28e"}, + {file = "portalocker-2.8.2.tar.gz", hash = "sha256:2b035aa7828e46c58e9b31390ee1f169b98e1066ab10b9a6a861fe7e25ee4f33"}, +] + +[package.dependencies] +pywin32 = {version = ">=226", markers = "platform_system == \"Windows\""} + +[package.extras] +docs = ["sphinx (>=1.7.1)"] +redis = ["redis"] +tests = ["pytest (>=5.4.1)", "pytest-cov (>=2.8.1)", "pytest-mypy (>=0.8.0)", "pytest-timeout (>=2.1.0)", "redis", "sphinx (>=6.0.0)", "types-redis"] + [[package]] name = "pre-commit" version = "3.2.0" @@ -4584,7 +4658,7 @@ files = [ name = "pyjwt" version = "2.8.0" description = "JSON Web Token implementation in Python" -optional = true +optional = false python-versions = ">=3.7" files = [ {file = "PyJWT-2.8.0-py3-none-any.whl", hash = "sha256:59127c392cc44c2da5bb3192169a91f429924e17aff6534d70fdc02ab3e04320"}, @@ -4964,7 +5038,6 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, @@ -7823,4 +7896,4 @@ query-tools = ["guidance", "jsonpath-ng", "lm-format-enforcer", "rank-bm25", "sc [metadata] lock-version = "2.0" python-versions = ">=3.8.1,<4.0" -content-hash = "6f230242ed4fe799ae5b98f5b64e5f388ad54c304198c6de55bc056be873397c" +content-hash = "5be6faa467154b5ae979b90fa2dd6feb6799c26de2024d54ad53c12a38a627c3" From 57ac6dd1546cc1a4a10602c0fb71a1add03e12e7 Mon Sep 17 00:00:00 2001 From: Logan Markewich Date: Wed, 28 Feb 2024 10:09:56 -0600 Subject: [PATCH 4/4] revert some changes --- .../llama_index/llms/azure_openai/base.py | 2 +- .../llama_index/multi_modal_llms/azure_openai/base.py | 2 +- pyproject.toml | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/llama-index-integrations/llms/llama-index-llms-azure-openai/llama_index/llms/azure_openai/base.py b/llama-index-integrations/llms/llama-index-llms-azure-openai/llama_index/llms/azure_openai/base.py index 6297019c26127..236c7af700ff7 100644 --- a/llama-index-integrations/llms/llama-index-llms-azure-openai/llama_index/llms/azure_openai/base.py +++ b/llama-index-integrations/llms/llama-index-llms-azure-openai/llama_index/llms/azure_openai/base.py @@ -50,7 +50,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() diff --git a/llama-index-integrations/multi_modal_llms/llama-index-multi-modal-llms-azure-openai/llama_index/multi_modal_llms/azure_openai/base.py b/llama-index-integrations/multi_modal_llms/llama-index-multi-modal-llms-azure-openai/llama_index/multi_modal_llms/azure_openai/base.py index b5a9a89200666..b02c38b051c58 100644 --- a/llama-index-integrations/multi_modal_llms/llama-index-multi-modal-llms-azure-openai/llama_index/multi_modal_llms/azure_openai/base.py +++ b/llama-index-integrations/multi_modal_llms/llama-index-multi-modal-llms-azure-openai/llama_index/multi_modal_llms/azure_openai/base.py @@ -54,7 +54,7 @@ class AzureOpenAIMultiModal(OpenAIMultiModal): 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) def __init__( self, diff --git a/pyproject.toml b/pyproject.toml index b091fafa27531..d40690be39cd8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,7 +62,6 @@ llama-index-multi-modal-llms-openai = "^0.1.3" llama-index-cli = "^0.1.2" [tool.poetry.group.dev.dependencies] -azure-identity = ">=1.15.0" black = {extras = ["jupyter"], version = "<=23.9.1,>=23.7.0"} codespell = {extras = ["toml"], version = ">=v2.2.6"} mypy = "0.991"