Consider porting the same endpoint and API key identification heuristic, recently added to the new OpenAI.ClientCore class, to the AzureOpenAI.ClientCore:
internal ClientCore(
string modelId,
string? apiKey = null,
string? organizationId = null,
Uri? endpoint = null,
HttpClient? httpClient = null,
ILogger? logger = null)
{
Verify.NotNullOrWhiteSpace(modelId);
this.Logger = logger ?? NullLogger.Instance;
this.ModelId = modelId;
this.AddAttribute(AIServiceExtensions.ModelIdKey, modelId);
// Accepts the endpoint if provided, otherwise uses the default OpenAI endpoint.
this.Endpoint = endpoint ?? httpClient?.BaseAddress;
if (this.Endpoint is null)
{
Verify.NotNullOrWhiteSpace(apiKey); // For Public OpenAI Endpoint a key must be provided.
this.Endpoint = new Uri(OpenAIV1Endpoint);
}
else if (string.IsNullOrEmpty(apiKey))
{
// Avoids an exception from OpenAI Client when a custom endpoint is provided without an API key.
apiKey = SingleSpace;
}
this.AddAttribute(AIServiceExtensions.EndpointKey, this.Endpoint.ToString());
var options = GetOpenAIClientOptions(httpClient, this.Endpoint);
if (!string.IsNullOrWhiteSpace(organizationId))
{
options.AddPolicy(CreateRequestHeaderPolicy("OpenAI-Organization", organizationId!), PipelinePosition.PerCall);
this.AddAttribute(ClientCore.OrganizationKey, organizationId);
}
this.Client = new OpenAIClient(apiKey!, options);
}
Related comment - #7060 (comment)
Consider porting the same endpoint and API key identification heuristic, recently added to the new OpenAI.ClientCore class, to the AzureOpenAI.ClientCore:
Related comment - #7060 (comment)