From ae8226907ff03100cafd45ba5d648d2a62f77fef Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Mon, 14 Aug 2023 21:36:29 +0800 Subject: [PATCH] feat: close #2621 use better default api url --- app/client/platforms/openai.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/client/platforms/openai.ts b/app/client/platforms/openai.ts index 9dc92e9a..fd4eb59c 100644 --- a/app/client/platforms/openai.ts +++ b/app/client/platforms/openai.ts @@ -13,6 +13,7 @@ import { fetchEventSource, } from "@fortaine/fetch-event-source"; import { prettyObject } from "@/app/utils/format"; +import { getClientConfig } from "@/app/config/client"; export interface OpenAIListModelResponse { object: string; @@ -28,13 +29,16 @@ export class ChatGPTApi implements LLMApi { path(path: string): string { let openaiUrl = useAccessStore.getState().openaiUrl; + const apiPath = "/api/openai"; + if (openaiUrl.length === 0) { - openaiUrl = DEFAULT_API_HOST; + const isApp = !!getClientConfig()?.isApp; + openaiUrl = isApp ? DEFAULT_API_HOST : apiPath; } if (openaiUrl.endsWith("/")) { openaiUrl = openaiUrl.slice(0, openaiUrl.length - 1); } - if (!openaiUrl.startsWith("http") && !openaiUrl.startsWith("/api/openai")) { + if (!openaiUrl.startsWith("http") && !openaiUrl.startsWith(apiPath)) { openaiUrl = "https://" + openaiUrl; } return [openaiUrl, path].join("/");