From 1d8bd59210b6233c92362a7f7861779abb23b570 Mon Sep 17 00:00:00 2001 From: Brian Sunter <2816289+briansunter@users.noreply.github.com> Date: Tue, 8 Oct 2024 19:37:03 -1000 Subject: [PATCH] fix: migrate old url if in settings --- src/lib/openai.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib/openai.ts b/src/lib/openai.ts index 32d4cce..2fb499d 100644 --- a/src/lib/openai.ts +++ b/src/lib/openai.ts @@ -58,9 +58,16 @@ const retryOptions = { }, }; +function migrateOldUrl(url: string) { + if (url.startsWith("http://api.openai.com")) { + return url.replace("http://api.openai.com", "https://api.openai.com"); + } + return url; +} + export async function whisper(file: File,openAiOptions:OpenAIOptions): Promise { const apiKey = openAiOptions.apiKey; - const baseUrl = openAiOptions.completionEndpoint ? openAiOptions.completionEndpoint : "https://api.openai.com/v1"; + const baseUrl = openAiOptions.completionEndpoint ? migrateOldUrl(openAiOptions.completionEndpoint) : "https://api.openai.com/v1"; const model = 'whisper-1'; // Create a FormData object and append the file