From df612464f08ce19292fd9e764a64eaf29a11b2cf Mon Sep 17 00:00:00 2001 From: Lily Du Date: Thu, 30 May 2024 10:24:16 -0700 Subject: [PATCH] [repo] fix: removed HTTPS requirement for AOAI Embeddings (#1694) ## Linked issues closes: #1688 ## Details Removed HTTPS url requirement from JS, C#, and Python. ## Attestation Checklist - [x] My code follows the style guidelines of this project - I have checked for/fixed spelling, linting, and other errors - I have commented my code for clarity - I have made corresponding changes to the documentation (updating the doc strings in the code is sufficient) - My changes generate no new warnings - I have added tests that validates my changes, and provides sufficient test coverage. I have tested with: - Local testing - E2E testing in Teams - New and existing unit tests pass locally with my changes --- .../AI/Embeddings/AzureOpenAIEmbeddingsOptions.cs | 4 ---- .../teams-ai/src/embeddings/OpenAIEmbeddings.ts | 6 ------ .../teams/ai/embeddings/azure_openai_embeddings.py | 6 ------ .../ai/embeddings/test_azure_openai_embeddings.py | 13 ------------- 4 files changed, 29 deletions(-) diff --git a/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Embeddings/AzureOpenAIEmbeddingsOptions.cs b/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Embeddings/AzureOpenAIEmbeddingsOptions.cs index 77211c39e..79de36b2b 100644 --- a/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Embeddings/AzureOpenAIEmbeddingsOptions.cs +++ b/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Embeddings/AzureOpenAIEmbeddingsOptions.cs @@ -43,10 +43,6 @@ public AzureOpenAIEmbeddingsOptions( Verify.ParamNotNull(azureEndpoint); azureEndpoint = azureEndpoint.Trim(); - if (!azureEndpoint.StartsWith("https://")) - { - throw new ArgumentException($"Model created with an invalid endpoint of `{azureEndpoint}`. The endpoint must be a valid HTTPS url."); - } this.AzureApiKey = azureApiKey; this.AzureDeployment = azureDeployment; diff --git a/js/packages/teams-ai/src/embeddings/OpenAIEmbeddings.ts b/js/packages/teams-ai/src/embeddings/OpenAIEmbeddings.ts index 19ef284bd..09800754b 100644 --- a/js/packages/teams-ai/src/embeddings/OpenAIEmbeddings.ts +++ b/js/packages/teams-ai/src/embeddings/OpenAIEmbeddings.ts @@ -157,12 +157,6 @@ export class OpenAIEmbeddings implements EmbeddingsModel { endpoint = endpoint.substring(0, endpoint.length - 1); } - if (!endpoint.toLowerCase().startsWith('https://')) { - throw new Error( - `Client created with an invalid endpoint of '${endpoint}'. The endpoint must be a valid HTTPS url.` - ); - } - this.options.azureEndpoint = endpoint; } else { this._useAzure = false; diff --git a/python/packages/ai/teams/ai/embeddings/azure_openai_embeddings.py b/python/packages/ai/teams/ai/embeddings/azure_openai_embeddings.py index 56204bbeb..d0197a189 100644 --- a/python/packages/ai/teams/ai/embeddings/azure_openai_embeddings.py +++ b/python/packages/ai/teams/ai/embeddings/azure_openai_embeddings.py @@ -51,12 +51,6 @@ def __init__(self, options: AzureOpenAIEmbeddingsOptions, log=Logger("teams.ai") if endpoint[-1] == "/": endpoint = endpoint[0 : (len(endpoint) - 1)] - if not endpoint.lower().startswith("https://"): - raise ValueError(f""" - Client created with an invalid endpoint of \"{endpoint}\". - The endpoint must be a valid HTTPS url. - """) - self.options.azure_endpoint = endpoint async def create_embeddings( diff --git a/python/packages/ai/tests/ai/embeddings/test_azure_openai_embeddings.py b/python/packages/ai/tests/ai/embeddings/test_azure_openai_embeddings.py index 5a53fec9b..f21e0480a 100644 --- a/python/packages/ai/tests/ai/embeddings/test_azure_openai_embeddings.py +++ b/python/packages/ai/tests/ai/embeddings/test_azure_openai_embeddings.py @@ -8,7 +8,6 @@ import httpx import openai -import pytest from teams.ai.embeddings.azure_openai_embeddings import AzureOpenAIEmbeddings from teams.ai.embeddings.azure_openai_embeddings_options import ( @@ -93,7 +92,6 @@ class TestOpenAIEmbeddings(IsolatedAsyncioTestCase): embeddings: AzureOpenAIEmbeddings options_with_array: AzureOpenAIEmbeddingsOptions embeddings_with_array: AzureOpenAIEmbeddings - options_error: AzureOpenAIEmbeddingsOptions def setUp(self): self.options = AzureOpenAIEmbeddingsOptions( @@ -103,13 +101,6 @@ def setUp(self): log_requests=True, retry_policy=[2, 4], ) - self.options_error = AzureOpenAIEmbeddingsOptions( - azure_api_key="empty", - azure_endpoint="www.mock.openai.azure.com/", - azure_deployment="text-embedding-ada-002", - log_requests=True, - retry_policy=[2, 4], - ) self.options_with_array = AzureOpenAIEmbeddingsOptions( azure_api_key="empty", azure_endpoint="https://mock.openai.azure.com", @@ -122,10 +113,6 @@ def setUp(self): }, ) - async def test_endpoint_error(self): - with pytest.raises(ValueError): - AzureOpenAIEmbeddings(self.options_error) - @mock.patch("openai.AsyncAzureOpenAI", return_value=MockAsyncAzureOpenAI) async def test_string_embedding(self, mock_async_azure_open_ai): self.embeddings = AzureOpenAIEmbeddings(self.options)