From beb28b7f1db6bd24cb65726e80b485f930361893 Mon Sep 17 00:00:00 2001 From: neon-sunset Date: Fri, 27 Sep 2024 20:13:52 +0300 Subject: [PATCH] refactor: improve UX of the constructor overload that accepts an HttpClient instance --- src/Constants.cs | 2 +- src/PineconeClient.cs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Constants.cs b/src/Constants.cs index 4dbb5dc..7540350 100644 --- a/src/Constants.cs +++ b/src/Constants.cs @@ -6,9 +6,9 @@ static class Constants { public const string RestApiKey = "Api-Key"; public const string GrpcApiKey = "api-key"; - public const string ApiVersion = "2024-07"; + public static readonly Uri BaseUrl = new("https://api.pinecone.io"); public static readonly string UserAgent = $"lang=C#; Pinecone.NET/{typeof(Constants).Assembly.GetName().Version?.ToString(3) ?? "0.0.0"}"; diff --git a/src/PineconeClient.cs b/src/PineconeClient.cs index 4bf5458..375b2be 100644 --- a/src/PineconeClient.cs +++ b/src/PineconeClient.cs @@ -26,7 +26,7 @@ public sealed class PineconeClient : IDisposable /// API key used to connect to Pinecone. /// The logger factory to be used. public PineconeClient(string apiKey, ILoggerFactory? loggerFactory = null) - : this(apiKey, new Uri("https://api.pinecone.io"), loggerFactory) + : this(apiKey, Constants.BaseUrl, loggerFactory) { } @@ -51,6 +51,12 @@ public PineconeClient(string apiKey, Uri baseUrl, ILoggerFactory? loggerFactory /// /// Creates a new instance of the class. /// + /// + /// If is not set, the default base address is used. + /// + /// The logger factory, if provided, will be used to instrument the objects + /// created by the client but will not apply to the specified instance. + /// /// API key used to connect to Pinecone. /// HTTP client used to connect to Pinecone. /// The logger factory to be used. @@ -58,9 +64,9 @@ public PineconeClient(string apiKey, HttpClient client, ILoggerFactory? loggerFa { ThrowHelpers.CheckNullOrWhiteSpace(apiKey); ThrowHelpers.CheckNull(client); - ThrowHelpers.CheckNull(client.BaseAddress); Http = client; + Http.BaseAddress ??= Constants.BaseUrl; Http.AddPineconeHeaders(apiKey); LoggerFactory = loggerFactory; }