From 6d2ebaa97244460b5d52a2e19fc4eef3417dda4c Mon Sep 17 00:00:00 2001 From: Zou Jian Date: Tue, 10 Dec 2024 11:14:18 +0800 Subject: [PATCH] fix: domain like https://domain not allow the following use case where ``` var client = new OpenAIClient(new OpenAIAuthentication(key), new OpenAIClientSettings("https://domain")); ``` does not work, while both 'domain' and 'http://domain' work fine. This does not reflect the consistency of the API. --- .../Authentication/OpenAIClientSettings.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/OpenAI-DotNet/Authentication/OpenAIClientSettings.cs b/OpenAI-DotNet/Authentication/OpenAIClientSettings.cs index b242e3f9..81d5f408 100644 --- a/OpenAI-DotNet/Authentication/OpenAIClientSettings.cs +++ b/OpenAI-DotNet/Authentication/OpenAIClientSettings.cs @@ -56,16 +56,20 @@ public OpenAIClientSettings(string domain, string apiVersion = DefaultOpenAIApiV apiVersion = DefaultOpenAIApiVersion; } - ResourceName = domain.Contains(Http) - ? domain - : $"{Https}{domain}"; - - if (domain.Contains(Http)) + var httpSchema = Https; + if (domain.StartsWith(Http)) { + httpSchema = Http; domain = domain.Replace(Http, string.Empty); + } + else if (domain.StartsWith(Https)) + { + httpSchema = Https; domain = domain.Replace(Https, string.Empty); } + ResourceName = $"{httpSchema}{domain}"; + ApiVersion = apiVersion; DeploymentId = string.Empty; BaseRequest = $"/{ApiVersion}/";