Browse Source

feat: close #2621 use better default api url

Yidadaa 1 year ago
parent
commit
ae8226907f
1 changed files with 6 additions and 2 deletions
  1. 6 2
      app/client/platforms/openai.ts

+ 6 - 2
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("/");