Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,24 @@ public void ItCanAddAudioToTextServiceWithOpenAIClient()
Assert.Equal("model", service.Attributes[AIServiceExtensions.ModelIdKey]);
}

[Fact]
public void ItCanAddEmbeddingGeneratorWithHttpClient()
{
// Arrange
var customEndpoint = new Uri("https://custom.proxy.url/openai/v1/");
using var httpClient = new System.Net.Http.HttpClient { BaseAddress = customEndpoint };
var sut = Kernel.CreateBuilder();

// Act
var kernel = sut.AddOpenAIEmbeddingGenerator("model", "key", httpClient: httpClient)
.Build();
var service = kernel.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>();

// Assert
Assert.NotNull(service);
Assert.Equal(customEndpoint, service.GetService<EmbeddingGeneratorMetadata>()!.ProviderUri);
}

[Fact]
[Obsolete(ObsoleteMessage)]
public void ItCanAddFileService()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,7 @@ internal static OpenAIClientOptions GetOpenAIClientOptions(HttpClient? httpClien
UserAgentApplicationId = HttpHeaderConstant.Values.UserAgent,
};

if (endpoint is not null)
{
options.Endpoint = endpoint;
}
options.Endpoint ??= endpoint ?? httpClient?.BaseAddress;

options.AddPolicy(CreateRequestHeaderPolicy(HttpHeaderConstant.Names.SemanticKernelVersion, HttpHeaderConstant.Values.GetAssemblyVersion(typeof(ClientCore))), PipelinePosition.PerCall);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Diagnostics.CodeAnalysis;
using System.Net.Http;
using Microsoft.Extensions.AI;
Expand Down Expand Up @@ -275,29 +274,4 @@ public static IServiceCollection AddOpenAIEmbeddingGenerator(this IServiceCollec
});
}
#endregion

private static OpenAIClientOptions GetClientOptions(
Uri? endpoint = null,
string? orgId = null,
HttpClient? httpClient = null)
{
OpenAIClientOptions options = new();

if (endpoint is not null)
{
options.Endpoint = endpoint;
}

if (orgId is not null)
{
options.OrganizationId = orgId;
}

if (httpClient is not null)
{
options.Transport = new HttpClientPipelineTransport(httpClient);
}

return options;
}
}
Loading