From 9b97dca601b5f159bf44d09720f82cc865cc77b7 Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Fri, 12 Jul 2024 21:27:30 +0800 Subject: [PATCH 1/3] hotfix: custom comfig for Gemini api. #4944 --- app/client/platforms/google.ts | 15 ++++++--------- app/constant.ts | 1 + app/store/access.ts | 10 +++++----- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/app/client/platforms/google.ts b/app/client/platforms/google.ts index 828b28a0d4d..6054c7a476e 100644 --- a/app/client/platforms/google.ts +++ b/app/client/platforms/google.ts @@ -122,16 +122,13 @@ export class GeminiProApi implements LLMApi { const controller = new AbortController(); options.onController?.(controller); try { - // let baseUrl = accessStore.googleUrl; - - if (!baseUrl) { - baseUrl = isApp - ? DEFAULT_API_HOST + - "/api/proxy/google/" + - Google.ChatPath(modelConfig.model) - : this.path(Google.ChatPath(modelConfig.model)); + if (!baseUrl && isApp) { + baseUrl = DEFAULT_API_HOST + "/api/proxy/google/"; } - + baseUrl = `${baseUrl}/${Google.ChatPath(modelConfig.model)}`.replaceAll( + "//", + "/", + ); if (isApp) { baseUrl += `?key=${accessStore.googleApiKey}`; } diff --git a/app/constant.ts b/app/constant.ts index c07adad25be..a146200d63b 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -35,6 +35,7 @@ export enum ApiPath { Azure = "/api/azure", OpenAI = "/api/openai", Anthropic = "/api/anthropic", + Google = "/api/google", Baidu = "/api/baidu", ByteDance = "/api/bytedance", Alibaba = "/api/alibaba", diff --git a/app/store/access.ts b/app/store/access.ts index c0fea9fea2a..5b07ff1281c 100644 --- a/app/store/access.ts +++ b/app/store/access.ts @@ -17,10 +17,10 @@ const DEFAULT_OPENAI_URL = ? DEFAULT_API_HOST + "/api/proxy/openai" : ApiPath.OpenAI; -const DEFAULT_AZURE_URL = +const DEFAULT_GOOGLE_URL = getClientConfig()?.buildMode === "export" - ? DEFAULT_API_HOST + "/api/proxy/azure/{resource_name}" - : ApiPath.Azure; + ? DEFAULT_API_HOST + "/api/proxy/google" + : ApiPath.Google; const DEFAULT_ACCESS_STATE = { accessCode: "", @@ -33,12 +33,12 @@ const DEFAULT_ACCESS_STATE = { openaiApiKey: "", // azure - azureUrl: DEFAULT_AZURE_URL, + azureUrl: "", azureApiKey: "", azureApiVersion: "2023-08-01-preview", // google ai studio - googleUrl: "", + googleUrl: DEFAULT_GOOGLE_URL, googleApiKey: "", googleApiVersion: "v1", From 831627268dac654439cc522303a952fd32fe0e91 Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Fri, 12 Jul 2024 21:41:12 +0800 Subject: [PATCH 2/3] update --- app/locales/cn.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/locales/cn.ts b/app/locales/cn.ts index 728bdbc5968..323f9ddad83 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -349,12 +349,12 @@ const cn = { }, Baidu: { ApiKey: { - Title: "接口密钥", + Title: "API Key", SubTitle: "使用自定义 Baidu API Key", Placeholder: "Baidu API Key", }, SecretKey: { - Title: "接口密钥", + Title: "Secret Key", SubTitle: "使用自定义 Baidu Secret Key", Placeholder: "Baidu Secret Key", }, From 476bdac7177de0ece66e619ead06d7cd2b652209 Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Fri, 12 Jul 2024 21:52:38 +0800 Subject: [PATCH 3/3] update --- app/store/access.ts | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/app/store/access.ts b/app/store/access.ts index 5b07ff1281c..26359e55c91 100644 --- a/app/store/access.ts +++ b/app/store/access.ts @@ -12,15 +12,33 @@ import { DEFAULT_CONFIG } from "./config"; let fetchState = 0; // 0 not fetch, 1 fetching, 2 done -const DEFAULT_OPENAI_URL = - getClientConfig()?.buildMode === "export" - ? DEFAULT_API_HOST + "/api/proxy/openai" - : ApiPath.OpenAI; +const isApp = getClientConfig()?.buildMode === "export"; -const DEFAULT_GOOGLE_URL = - getClientConfig()?.buildMode === "export" - ? DEFAULT_API_HOST + "/api/proxy/google" - : ApiPath.Google; +const DEFAULT_OPENAI_URL = isApp + ? DEFAULT_API_HOST + "/api/proxy/openai" + : ApiPath.OpenAI; + +const DEFAULT_GOOGLE_URL = isApp + ? DEFAULT_API_HOST + "/api/proxy/google" + : ApiPath.Google; + +const DEFAULT_ANTHROPIC_URL = isApp + ? DEFAULT_API_HOST + "/api/proxy/anthropic" + : ApiPath.Anthropic; + +const DEFAULT_BAIDU_URL = isApp + ? DEFAULT_API_HOST + "/api/proxy/baidu" + : ApiPath.Baidu; + +const DEFAULT_BYTEDANCE_URL = isApp + ? DEFAULT_API_HOST + "/api/proxy/bytedance" + : ApiPath.ByteDance; + +const DEFAULT_ALIBABA_URL = isApp + ? DEFAULT_API_HOST + "/api/proxy/alibaba" + : ApiPath.Alibaba; + +console.log("DEFAULT_ANTHROPIC_URL", DEFAULT_ANTHROPIC_URL); const DEFAULT_ACCESS_STATE = { accessCode: "", @@ -43,21 +61,21 @@ const DEFAULT_ACCESS_STATE = { googleApiVersion: "v1", // anthropic + anthropicUrl: DEFAULT_ANTHROPIC_URL, anthropicApiKey: "", anthropicApiVersion: "2023-06-01", - anthropicUrl: "", // baidu - baiduUrl: "", + baiduUrl: DEFAULT_BAIDU_URL, baiduApiKey: "", baiduSecretKey: "", // bytedance + bytedanceUrl: DEFAULT_BYTEDANCE_URL, bytedanceApiKey: "", - bytedanceUrl: "", // alibaba - alibabaUrl: "", + alibabaUrl: DEFAULT_ALIBABA_URL, alibabaApiKey: "", // server config