diff --git a/README.md b/README.md index c72c791b264..be5e91d65c7 100644 --- a/README.md +++ b/README.md @@ -175,7 +175,7 @@ We recommend that you follow the steps below to re-deploy: ### Enable Automatic Updates -> If you encounter a failure of Upstream Sync execution, please manually sync fork once. +> If you encounter a failure of Upstream Sync execution, please [manually update code](./README.md#manually-updating-code). After forking the project, due to the limitations imposed by GitHub, you need to manually enable Workflows and Upstream Sync Action on the Actions page of the forked project. Once enabled, automatic updates will be scheduled every hour: diff --git a/README_CN.md b/README_CN.md index c5d02477c2c..640fe39331c 100644 --- a/README_CN.md +++ b/README_CN.md @@ -54,7 +54,7 @@ ### 打开自动更新 -> 如果你遇到了 Upstream Sync 执行错误,请手动 Sync Fork 一次! +> 如果你遇到了 Upstream Sync 执行错误,请[手动 Sync Fork 一次](./README_CN.md#手动更新代码)! 当你 fork 项目之后,由于 Github 的限制,需要手动去你 fork 后的项目的 Actions 页面启用 Workflows,并启用 Upstream Sync Action,启用之后即可开启每小时定时自动更新: diff --git a/README_JA.md b/README_JA.md index 2b0a3ab782c..ba3c514dcd7 100644 --- a/README_JA.md +++ b/README_JA.md @@ -54,7 +54,7 @@ ### 自動更新を開く -> Upstream Sync の実行エラーが発生した場合は、手動で Sync Fork してください! +> Upstream Sync の実行エラーが発生した場合は、[手動で Sync Fork](./README_JA.md#手動でコードを更新する) してください! プロジェクトを fork した後、GitHub の制限により、fork 後のプロジェクトの Actions ページで Workflows を手動で有効にし、Upstream Sync Action を有効にする必要があります。有効化後、毎時の定期自動更新が可能になります: diff --git a/app/api/google.ts b/app/api/google.ts index e6ab472568b..7d3f08be4d9 100644 --- a/app/api/google.ts +++ b/app/api/google.ts @@ -91,7 +91,7 @@ async function request(req: NextRequest, apiKey: string) { }, 10 * 60 * 1000, ); - const fetchUrl = `${baseUrl}${path}?key=${apiKey}${ + const fetchUrl = `${baseUrl}${path}${ req?.nextUrl?.searchParams?.get("alt") === "sse" ? "&alt=sse" : "" }`; @@ -100,6 +100,9 @@ async function request(req: NextRequest, apiKey: string) { headers: { "Content-Type": "application/json", "Cache-Control": "no-store", + "x-google-api-key": + req.headers.get("x-google-api-key") || + (req.headers.get("Authorization") ?? "").replace("Bearer ", ""), }, method: req.method, body: req.body, diff --git a/app/client/api.ts b/app/client/api.ts index 8285b4d9f94..48bbde6bc81 100644 --- a/app/client/api.ts +++ b/app/client/api.ts @@ -272,7 +272,13 @@ export function getHeaders(ignoreHeaders: boolean = false) { } function getAuthHeader(): string { - return isAzure ? "api-key" : isAnthropic ? "x-api-key" : "Authorization"; + return isAzure + ? "api-key" + : isAnthropic + ? "x-api-key" + : isGoogle + ? "x-goog-api-key" + : "Authorization"; } const { @@ -283,14 +289,15 @@ export function getHeaders(ignoreHeaders: boolean = false) { apiKey, isEnabledAccessControl, } = getConfig(); - // when using google api in app, not set auth header - if (isGoogle && clientConfig?.isApp) return headers; // when using baidu api in app, not set auth header if (isBaidu && clientConfig?.isApp) return headers; const authHeader = getAuthHeader(); - const bearerToken = getBearerToken(apiKey, isAzure || isAnthropic); + const bearerToken = getBearerToken( + apiKey, + isAzure || isAnthropic || isGoogle, + ); if (bearerToken) { headers[authHeader] = bearerToken; diff --git a/app/client/platforms/google.ts b/app/client/platforms/google.ts index ecb5ce44b57..3c2607271bf 100644 --- a/app/client/platforms/google.ts +++ b/app/client/platforms/google.ts @@ -48,10 +48,6 @@ export class GeminiProApi implements LLMApi { let chatPath = [baseUrl, path].join("/"); chatPath += chatPath.includes("?") ? "&alt=sse" : "?alt=sse"; - // if chatPath.startsWith('http') then add key in query string - if (chatPath.startsWith("http") && accessStore.googleApiKey) { - chatPath += `&key=${accessStore.googleApiKey}`; - } return chatPath; } extractMessage(res: any) { diff --git a/app/store/access.ts b/app/store/access.ts index d74cb9d0249..9fcd227e7c0 100644 --- a/app/store/access.ts +++ b/app/store/access.ts @@ -211,10 +211,13 @@ export const useAccessStore = createPersistStore( }) .then((res) => res.json()) .then((res) => { - // Set default model from env request - let defaultModel = res.defaultModel ?? ""; - if (defaultModel !== "") - DEFAULT_CONFIG.modelConfig.model = defaultModel; + const defaultModel = res.defaultModel ?? ""; + if (defaultModel !== "") { + const [model, providerName] = defaultModel.split("@"); + DEFAULT_CONFIG.modelConfig.model = model; + DEFAULT_CONFIG.modelConfig.providerName = providerName; + } + return res; }) .then((res: DangerConfig) => {