Skip to content

Commit

Permalink
[repo] fix: removed HTTPS client requirement (#1718)
Browse files Browse the repository at this point in the history
## Linked issues

closes: #1698

## Details

- removed client check HTTPS error throwing

## 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
  • Loading branch information
lilyydu authored Jun 11, 2024
1 parent 46ff7e5 commit a9fb94f
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,6 @@ public void Test_Constructor_OpenAI()
new OpenAIModel(options);
}

[Fact]
public void Test_Constructor_AzureOpenAI_InvalidAzureEndpoint()
{
// Arrange
var options = new AzureOpenAIModelOptions("test-key", "test-deployment", "https://test.openai.azure.com/");
options.AzureEndpoint = "test-endpoint";

// Act
Exception exception = Assert.Throws<ArgumentException>(() => new OpenAIModel(options));

// Assert
Assert.Equal("Model created with an invalid endpoint of `test-endpoint`. The endpoint must be a valid HTTPS url.", exception.Message);
}

[Fact]
public void Test_Constructor_AzureOpenAI_InvalidAzureApiVersion()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ public OpenAIEmbeddings(AzureOpenAIEmbeddingsOptions options, ILoggerFactory? lo
Verify.ParamNotNull(options.AzureApiKey, "AzureOpenAIEmbeddingsOptions.AzureApiKey");
Verify.ParamNotNull(options.AzureDeployment, "AzureOpenAIEmbeddingsOptions.AzureDeployment");
Verify.ParamNotNull(options.AzureEndpoint, "AzureOpenAIEmbeddingsOptions.AzureEndpoint");
if (!options.AzureEndpoint.StartsWith("https://"))
{
throw new ArgumentException($"Model created with an invalid endpoint of `{options.AzureEndpoint}`. The endpoint must be a valid HTTPS url.");
}

string apiVersion = options.AzureApiVersion ?? "2023-05-15";
ServiceVersion? serviceVersion = ConvertStringToServiceVersion(apiVersion);
if (serviceVersion == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ public AzureOpenAIModelOptions(
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.AzureDefaultDeployment = azureDefaultDeployment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ public OpenAIModel(AzureOpenAIModelOptions options, ILoggerFactory? loggerFactor
Verify.ParamNotNull(options.AzureApiKey, "AzureOpenAIModelOptions.AzureApiKey");
Verify.ParamNotNull(options.AzureDefaultDeployment, "AzureOpenAIModelOptions.AzureDefaultDeployment");
Verify.ParamNotNull(options.AzureEndpoint, "AzureOpenAIModelOptions.AzureEndpoint");
if (!options.AzureEndpoint.StartsWith("https://"))
{
throw new ArgumentException($"Model created with an invalid endpoint of `{options.AzureEndpoint}`. The endpoint must be a valid HTTPS url.");
}
string apiVersion = options.AzureApiVersion ?? "2024-02-15-preview";
ServiceVersion? serviceVersion = ConvertStringToServiceVersion(apiVersion);
if (serviceVersion == null)
Expand Down
13 changes: 0 additions & 13 deletions js/packages/teams-ai/src/internals/OpenAIClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ describe('OpenAIClient', () => {
const options: OpenAIClientOptions = {
apiKey: 'mock-key'
};
const optionsWithInvalidEndpoint: OpenAIClientOptions = {
apiKey: 'mock-key',
endpoint: 'www.'
};
const optionsWithEmptyAPIKey: OpenAIClientOptions = {
apiKey: ''
};
Expand Down Expand Up @@ -106,15 +102,6 @@ describe('OpenAIClient', () => {
assert.equal(openAIClient.options.apiKey, options.apiKey);
});

it('should throw error due to invalid endpoint', () => {
assert.throws(
() => new OpenAIClient(optionsWithInvalidEndpoint),
new Error(
`OpenAIClient initialized with an invalid endpoint of '${optionsWithInvalidEndpoint.endpoint}'. The endpoint must be a valid HTTPS url.`
)
);
});

it('should throw error due to invalid api key', () => {
assert.throws(
() => new OpenAIClient(optionsWithEmptyAPIKey),
Expand Down
6 changes: 0 additions & 6 deletions js/packages/teams-ai/src/internals/OpenAIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ export class OpenAIClient {
if (options.endpoint.endsWith('/')) {
options.endpoint = options.endpoint.substring(0, options.endpoint.length - 1);
}

if (!options.endpoint.toLowerCase().startsWith('https://')) {
throw new Error(
`OpenAIClient initialized with an invalid endpoint of '${options.endpoint}'. The endpoint must be a valid HTTPS url.`
);
}
}

// Validate API key
Expand Down
6 changes: 0 additions & 6 deletions js/packages/teams-ai/src/models/OpenAIModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,6 @@ export class OpenAIModel implements PromptCompletionModel {
endpoint = endpoint.substring(0, endpoint.length - 1);
}

if (!endpoint.toLowerCase().startsWith('https://')) {
throw new Error(
`Model created with an invalid endpoint of '${endpoint}'. The endpoint must be a valid HTTPS url.`
);
}

this.options.azureEndpoint = endpoint;
} else {
this._useAzure = false;
Expand Down

0 comments on commit a9fb94f

Please sign in to comment.