From 9abe3f69165ca5d3dc5749f0f2cf0b1fa402a23c Mon Sep 17 00:00:00 2001 From: lloydchang Date: Wed, 11 Dec 2024 02:37:26 -0800 Subject: [PATCH] fix(openai.ts): default to an empty string if undefined Change: const urlHost = new URL(this.options.openAiBaseUrl).host; To: const urlHost = new URL(this.options.openAiBaseUrl ?? "").host; because the nullish coalescing operator (??) to default to an empty string if this.options.openAiBaseUrl is undefined. It ensures that the URL constructor always receives a valid string. --- src/api/providers/openai.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/providers/openai.ts b/src/api/providers/openai.ts index 3912fa4..f1c576b 100644 --- a/src/api/providers/openai.ts +++ b/src/api/providers/openai.ts @@ -17,7 +17,7 @@ export class OpenAiHandler implements ApiHandler { constructor(options: ApiHandlerOptions) { this.options = options // Azure API shape slightly differs from the core API shape: https://github.com/openai/openai-node?tab=readme-ov-file#microsoft-azure-openai - const urlHost = new URL(this.options.openAiBaseUrl).host; + const urlHost = new URL(this.options.openAiBaseUrl ?? "").host; if (urlHost === "azure.com" || urlHost.endsWith(".azure.com")) { this.client = new AzureOpenAI({ baseURL: this.options.openAiBaseUrl,