diff --git a/apps/bym.js b/apps/bym.js index 9e9fb073..b3720146 100644 --- a/apps/bym.js +++ b/apps/bym.js @@ -100,7 +100,7 @@ export class bym extends plugin { let client = new CustomGoogleGeminiClient({ e, userId: e.sender.user_id, - key: Config.geminiKey, + key: Config.getGeminiKey(), model: Config.geminiModel, baseUrl: Config.geminiBaseUrl, debug: Config.debug diff --git a/apps/entertainment.js b/apps/entertainment.js index 1071f504..53072f82 100644 --- a/apps/entertainment.js +++ b/apps/entertainment.js @@ -617,7 +617,7 @@ ${translateLangLabels} let client = new CustomGoogleGeminiClient({ e, userId: e.sender.user_id, - key: Config.geminiKey, + key: Config.getGeminiKey(), model: 'gemini-1.5-flash-latest', baseUrl: Config.geminiBaseUrl, debug: Config.debug diff --git a/guoba.support.js b/guoba.support.js index 31b4ce20..a92c0b29 100644 --- a/guoba.support.js +++ b/guoba.support.js @@ -592,7 +592,7 @@ export function supportGuoba () { { field: 'geminiKey', label: 'API密钥', - bottomHelpMessage: '前往https://makersuite.google.com/app/apikey获取', + bottomHelpMessage: '前往https://makersuite.google.com/app/apikey获取,如果有多个Keys,用英文逗号隔开', component: 'InputPassword' }, { diff --git a/model/core.js b/model/core.js index a215914c..d8c19af5 100644 --- a/model/core.js +++ b/model/core.js @@ -721,7 +721,7 @@ class Core { let client = new CustomGoogleGeminiClient({ e, userId: e.sender.user_id, - key: Config.geminiKey, + key: Config.getGeminiKey(), model: Config.geminiModel, baseUrl: Config.geminiBaseUrl, debug: Config.debug diff --git a/utils/config.js b/utils/config.js index d2f9f7c5..f9e7e5a4 100644 --- a/utils/config.js +++ b/utils/config.js @@ -267,17 +267,21 @@ config.version = defaultConfig.version export const Config = new Proxy(config, { get(target, property) { - if (property === 'geminiKey') { - if (typeof target[property] === 'string' && target[property].includes(',')) { - const keys = target[property].split(',').map(key => key.trim()).filter(Boolean) - const selectedKey = keys[Math.floor(Math.random() * keys.length)] - console.log(`[ChatGPT-Plugin] 当前使用的Gemini Key: ${selectedKey.slice(0, 8)}...`) - return selectedKey + if (property === 'getGeminiKey') { + return function () { + if (target["geminiKey"]?.length === 0) { + return ""; + } + const geminiKeyArr = target["geminiKey"]?.trim().split(/[,,]/); + const randomIndex = Math.floor(Math.random() * geminiKeyArr.length); + logger.info(`[chatgpt]随机使用第${randomIndex + 1}个gemini Key: ${geminiKeyArr[randomIndex].replace(/(.{7}).*(.{10})/, '$1****$2')}`); + return geminiKeyArr[randomIndex]; } } + return target[property] }, - set (target, property, value) { + set(target, property, value) { target[property] = value const change = lodash.transform(target, function (result, value, key) { if (!lodash.isEqual(value, defaultConfig[key])) { diff --git a/utils/tools/WebsiteTool.js b/utils/tools/WebsiteTool.js index cc062211..a67683c1 100644 --- a/utils/tools/WebsiteTool.js +++ b/utils/tools/WebsiteTool.js @@ -65,7 +65,7 @@ export class WebsiteTool extends AbstractTool { let client = new CustomGoogleGeminiClient({ e, userId: e?.sender?.user_id, - key: Config.geminiKey, + key: Config.getGeminiKey(), model: Config.geminiModel, baseUrl: Config.geminiBaseUrl, debug: Config.debug diff --git a/utils/translate.js b/utils/translate.js index a9330df4..c765b6fa 100644 --- a/utils/translate.js +++ b/utils/translate.js @@ -146,7 +146,7 @@ export async function translate (msg, to = 'auto', from = 'auto', ai = Config.tr } case 'gemini': { let client = new CustomGoogleGeminiClient({ - key: Config.geminiKey, + key: Config.getGeminiKey(), model: Config.geminiModel, baseUrl: Config.geminiBaseUrl, debug: Config.debug