From 35471a41c89cdfdd2b6a59c25b24d415049556fc Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Mon, 25 Dec 2023 00:30:23 +0700 Subject: [PATCH 1/3] Fix & Feat [Auth] Api Key Variable - [+] fix(auth.ts): fix variable name from serverApiKey to systemApiKey - [+] feat(auth.ts): add support for Google API key in addition to Azure API key --- app/api/auth.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/api/auth.ts b/app/api/auth.ts index b41e34e05..043ad0d31 100644 --- a/app/api/auth.ts +++ b/app/api/auth.ts @@ -55,15 +55,18 @@ export function auth(req: NextRequest) { // if user does not provide an api key, inject system api key if (!apiKey) { - const serverApiKey = serverConfig.isAzure + const serverConfig = getServerSideConfig(); + const systemApiKey = serverConfig.isAzure ? serverConfig.azureApiKey + : serverConfig.isGoogle + ? serverConfig.googleApiKey : serverConfig.apiKey; - if (serverApiKey) { + if (systemApiKey) { console.log("[Auth] use system api key"); req.headers.set( "Authorization", - `${serverConfig.isAzure ? "" : "Bearer "}${serverApiKey}`, + `Bearer ${systemApiKey}`, ); } else { console.log("[Auth] admin did not provide an api key"); From 281fe6927a297bf561032dcc5e80f96a90441a84 Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Mon, 25 Dec 2023 00:35:33 +0700 Subject: [PATCH 2/3] Feat [Server Side] Google Api Configuration - [+] feat(server.ts): add support for Google API configuration variables --- app/config/server.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/config/server.ts b/app/config/server.ts index 83c711242..bd2cee656 100644 --- a/app/config/server.ts +++ b/app/config/server.ts @@ -65,6 +65,7 @@ export const getServerSideConfig = () => { } const isAzure = !!process.env.AZURE_URL; + const isGoogle = !!process.env.GOOGLE_URL; const apiKeyEnvVar = process.env.OPENAI_API_KEY ?? ""; const apiKeys = apiKeyEnvVar.split(",").map((v) => v.trim()); @@ -84,6 +85,7 @@ export const getServerSideConfig = () => { azureApiKey: process.env.AZURE_API_KEY, azureApiVersion: process.env.AZURE_API_VERSION, + isGoogle, googleApiKey: process.env.GOOGLE_API_KEY, googleUrl: process.env.GOOGLE_URL, From 753c518d33240ee3abd75152f3b11b6dc4e463b9 Mon Sep 17 00:00:00 2001 From: Fred Liang Date: Mon, 25 Dec 2023 03:46:35 +0800 Subject: [PATCH 3/3] chore: update how to identify google model --- app/config/server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/config/server.ts b/app/config/server.ts index bd2cee656..c6251a5c2 100644 --- a/app/config/server.ts +++ b/app/config/server.ts @@ -65,7 +65,7 @@ export const getServerSideConfig = () => { } const isAzure = !!process.env.AZURE_URL; - const isGoogle = !!process.env.GOOGLE_URL; + const isGoogle = !!process.env.GOOGLE_API_KEY; const apiKeyEnvVar = process.env.OPENAI_API_KEY ?? ""; const apiKeys = apiKeyEnvVar.split(",").map((v) => v.trim());