-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AzureOpenai access from behind company proxies. (#1459)
- Loading branch information
1 parent
e7d2ab6
commit 448c672
Showing
8 changed files
with
173 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from unittest.mock import patch, Mock | ||
|
||
import httpx | ||
|
||
from embedchain.config import BaseEmbedderConfig | ||
from embedchain.embedder.azure_openai import AzureOpenAIEmbedder | ||
|
||
|
||
def test_azure_openai_embedder_with_http_client(monkeypatch): | ||
mock_http_client = Mock(spec=httpx.Client) | ||
mock_http_client_instance = Mock(spec=httpx.Client) | ||
mock_http_client.return_value = mock_http_client_instance | ||
|
||
with patch("embedchain.embedder.azure_openai.AzureOpenAIEmbeddings") as mock_embeddings, patch( | ||
"httpx.Client", new=mock_http_client | ||
) as mock_http_client: | ||
config = BaseEmbedderConfig( | ||
deployment_name="text-embedding-ada-002", | ||
http_client_proxies="http://testproxy.mem0.net:8000", | ||
) | ||
|
||
_ = AzureOpenAIEmbedder(config=config) | ||
|
||
mock_embeddings.assert_called_once_with( | ||
deployment="text-embedding-ada-002", | ||
http_client=mock_http_client_instance, | ||
http_async_client=None, | ||
) | ||
mock_http_client.assert_called_once_with(proxies="http://testproxy.mem0.net:8000") | ||
|
||
|
||
def test_azure_openai_embedder_with_http_async_client(monkeypatch): | ||
mock_http_async_client = Mock(spec=httpx.AsyncClient) | ||
mock_http_async_client_instance = Mock(spec=httpx.AsyncClient) | ||
mock_http_async_client.return_value = mock_http_async_client_instance | ||
|
||
with patch("embedchain.embedder.azure_openai.AzureOpenAIEmbeddings") as mock_embeddings, patch( | ||
"httpx.AsyncClient", new=mock_http_async_client | ||
) as mock_http_async_client: | ||
config = BaseEmbedderConfig( | ||
deployment_name="text-embedding-ada-002", | ||
http_async_client_proxies={"http://": "http://testproxy.mem0.net:8000"}, | ||
) | ||
|
||
_ = AzureOpenAIEmbedder(config=config) | ||
|
||
mock_embeddings.assert_called_once_with( | ||
deployment="text-embedding-ada-002", | ||
http_client=None, | ||
http_async_client=mock_http_async_client_instance, | ||
) | ||
mock_http_async_client.assert_called_once_with(proxies={"http://": "http://testproxy.mem0.net:8000"}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters