From de7d1b2e222a0a84121add019444dce77ac7a168 Mon Sep 17 00:00:00 2001 From: sijinhui Date: Wed, 25 Sep 2024 19:01:48 +0800 Subject: [PATCH 1/3] enable start script --- start.sh | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/start.sh b/start.sh index ea7197eac..a3d18acda 100755 --- a/start.sh +++ b/start.sh @@ -1,18 +1,18 @@ #!/bin/bash set -e -## 加速 -#yarn config set registry 'https://registry.npmmirror.com/' -#yarn config set sharp_binary_host "https://npm.taobao.org/mirrors/sharp" -#yarn config set sharp_libvips_binary_host "https://npm.taobao.org/mirrors/sharp-libvips" +# 加速 +yarn config set registry 'https://registry.npmmirror.com/' +yarn config set sharp_binary_host "https://npm.taobao.org/mirrors/sharp" +yarn config set sharp_libvips_binary_host "https://npm.taobao.org/mirrors/sharp-libvips" ## 官方 ##yarn config delete registry ##yarn config delete sharp_binary_host ##yarn config delete sharp_libvips_binary_host # #yarn cache clean -#yarn install +yarn install # -#yarn run build +yarn run build # #mkdir -p "./node_modules/tiktoken" #export OUT_DIR="out" @@ -27,12 +27,11 @@ set -e #docker network ls | grep -qw chatgpt-ns || docker network create chatgpt-ns -# 检查构建器是否已存在 -if ! docker buildx inspect mybuilder &> /dev/null; then - docker buildx create --use --name=mybuilder -fi -#docker buildx build --platform linux/amd64 -t registry.cn-hangzhou.aliyuncs.com/si-private/chatgpt-next-web:temp -f Dockerfile.linux-build --load . -docker buildx build --platform linux/amd64 -t registry.cn-hangzhou.aliyuncs.com/si-private/chatgpt-next-web:temp -f Dockerfile --load . - -docker tag registry.cn-hangzhou.aliyuncs.com/si-private/chatgpt-next-web:temp registry.cn-hangzhou.aliyuncs.com/si-private/chatgpt-next-web:latest -docker tag registry.cn-hangzhou.aliyuncs.com/si-private/chatgpt-next-web:temp registry.cn-hangzhou.aliyuncs.com/si-private/chatgpt-next-web:test +## 检查构建器是否已存在 +#if ! docker buildx inspect mybuilder &> /dev/null; then +# docker buildx create --use --name=mybuilder +#fi +#docker buildx build --platform linux/amd64 -t registry.cn-hangzhou.aliyuncs.com/si-private/chatgpt-next-web:temp -f Dockerfile --load . +# +#docker tag registry.cn-hangzhou.aliyuncs.com/si-private/chatgpt-next-web:temp registry.cn-hangzhou.aliyuncs.com/si-private/chatgpt-next-web:latest +#docker tag registry.cn-hangzhou.aliyuncs.com/si-private/chatgpt-next-web:temp registry.cn-hangzhou.aliyuncs.com/si-private/chatgpt-next-web:test From 702e17c96b2c533cdb9e0589d19601d57e9abb8b Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Thu, 26 Sep 2024 23:21:42 +0800 Subject: [PATCH 2/3] google api using `x-google-api-key` header --- app/api/google.ts | 5 ++++- app/client/api.ts | 15 +++++++++++---- app/client/platforms/google.ts | 4 ---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/api/google.ts b/app/api/google.ts index e6ab47256..396237eea 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 8285b4d9f..48bbde6bc 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 ecb5ce44b..3c2607271 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) { From 3fb389551ba5284be77734be47b7595c9c425967 Mon Sep 17 00:00:00 2001 From: Dogtiti <499960698@qq.com> Date: Fri, 27 Sep 2024 11:42:16 +0800 Subject: [PATCH 3/3] fix: build error --- app/api/google.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/api/google.ts b/app/api/google.ts index 396237eea..7d3f08be4 100644 --- a/app/api/google.ts +++ b/app/api/google.ts @@ -102,7 +102,7 @@ async function request(req: NextRequest, apiKey: string) { "Cache-Control": "no-store", "x-google-api-key": req.headers.get("x-google-api-key") || - (req.headers.get("Authorization") ?? "").replace("Bearer "), + (req.headers.get("Authorization") ?? "").replace("Bearer ", ""), }, method: req.method, body: req.body,