Skip to content

Commit 8f410b7

Browse files
authored
Merge pull request #812 from RooVetGit/cte/catch-openai-handler-exception
Don't throw when `openAiBaseUrl` is not a valid URL
2 parents 6037140 + e0336b5 commit 8f410b7

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/api/providers/openai.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,20 @@ export class OpenAiHandler implements ApiHandler, SingleCompletionHandler {
1818

1919
constructor(options: ApiHandlerOptions) {
2020
this.options = options
21-
// Azure API shape slightly differs from the core API shape:
22-
// https://github.com/openai/openai-node?tab=readme-ov-file#microsoft-azure-openai
23-
const urlHost = new URL(this.options.openAiBaseUrl ?? "").host
21+
22+
let urlHost: string
23+
24+
try {
25+
urlHost = new URL(this.options.openAiBaseUrl ?? "").host
26+
} catch (error) {
27+
// Likely an invalid `openAiBaseUrl`; we're still working on
28+
// proper settings validation.
29+
urlHost = ""
30+
}
31+
2432
if (urlHost === "azure.com" || urlHost.endsWith(".azure.com") || options.openAiUseAzure) {
33+
// Azure API shape slightly differs from the core API shape:
34+
// https://github.com/openai/openai-node?tab=readme-ov-file#microsoft-azure-openai
2535
this.client = new AzureOpenAI({
2636
baseURL: this.options.openAiBaseUrl,
2737
apiKey: this.options.openAiApiKey,

0 commit comments

Comments
 (0)