mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
feat: 轮询geminiKeys,用英文逗号隔开 (#744)
This commit is contained in:
parent
25520ba9fe
commit
7974c6a1c9
7 changed files with 17 additions and 13 deletions
|
|
@ -100,7 +100,7 @@ export class bym extends plugin {
|
||||||
let client = new CustomGoogleGeminiClient({
|
let client = new CustomGoogleGeminiClient({
|
||||||
e,
|
e,
|
||||||
userId: e.sender.user_id,
|
userId: e.sender.user_id,
|
||||||
key: Config.geminiKey,
|
key: Config.getGeminiKey(),
|
||||||
model: Config.geminiModel,
|
model: Config.geminiModel,
|
||||||
baseUrl: Config.geminiBaseUrl,
|
baseUrl: Config.geminiBaseUrl,
|
||||||
debug: Config.debug
|
debug: Config.debug
|
||||||
|
|
|
||||||
|
|
@ -617,7 +617,7 @@ ${translateLangLabels}
|
||||||
let client = new CustomGoogleGeminiClient({
|
let client = new CustomGoogleGeminiClient({
|
||||||
e,
|
e,
|
||||||
userId: e.sender.user_id,
|
userId: e.sender.user_id,
|
||||||
key: Config.geminiKey,
|
key: Config.getGeminiKey(),
|
||||||
model: 'gemini-1.5-flash-latest',
|
model: 'gemini-1.5-flash-latest',
|
||||||
baseUrl: Config.geminiBaseUrl,
|
baseUrl: Config.geminiBaseUrl,
|
||||||
debug: Config.debug
|
debug: Config.debug
|
||||||
|
|
|
||||||
|
|
@ -592,7 +592,7 @@ export function supportGuoba () {
|
||||||
{
|
{
|
||||||
field: 'geminiKey',
|
field: 'geminiKey',
|
||||||
label: 'API密钥',
|
label: 'API密钥',
|
||||||
bottomHelpMessage: '前往https://makersuite.google.com/app/apikey获取',
|
bottomHelpMessage: '前往https://makersuite.google.com/app/apikey获取,如果有多个Keys,用英文逗号隔开',
|
||||||
component: 'InputPassword'
|
component: 'InputPassword'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -721,7 +721,7 @@ class Core {
|
||||||
let client = new CustomGoogleGeminiClient({
|
let client = new CustomGoogleGeminiClient({
|
||||||
e,
|
e,
|
||||||
userId: e.sender.user_id,
|
userId: e.sender.user_id,
|
||||||
key: Config.geminiKey,
|
key: Config.getGeminiKey(),
|
||||||
model: Config.geminiModel,
|
model: Config.geminiModel,
|
||||||
baseUrl: Config.geminiBaseUrl,
|
baseUrl: Config.geminiBaseUrl,
|
||||||
debug: Config.debug
|
debug: Config.debug
|
||||||
|
|
|
||||||
|
|
@ -267,17 +267,21 @@ config.version = defaultConfig.version
|
||||||
|
|
||||||
export const Config = new Proxy(config, {
|
export const Config = new Proxy(config, {
|
||||||
get(target, property) {
|
get(target, property) {
|
||||||
if (property === 'geminiKey') {
|
if (property === 'getGeminiKey') {
|
||||||
if (typeof target[property] === 'string' && target[property].includes(',')) {
|
return function () {
|
||||||
const keys = target[property].split(',').map(key => key.trim()).filter(Boolean)
|
if (target["geminiKey"]?.length === 0) {
|
||||||
const selectedKey = keys[Math.floor(Math.random() * keys.length)]
|
return "";
|
||||||
console.log(`[ChatGPT-Plugin] 当前使用的Gemini Key: ${selectedKey.slice(0, 8)}...`)
|
}
|
||||||
return selectedKey
|
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]
|
return target[property]
|
||||||
},
|
},
|
||||||
set (target, property, value) {
|
set(target, property, value) {
|
||||||
target[property] = value
|
target[property] = value
|
||||||
const change = lodash.transform(target, function (result, value, key) {
|
const change = lodash.transform(target, function (result, value, key) {
|
||||||
if (!lodash.isEqual(value, defaultConfig[key])) {
|
if (!lodash.isEqual(value, defaultConfig[key])) {
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ export class WebsiteTool extends AbstractTool {
|
||||||
let client = new CustomGoogleGeminiClient({
|
let client = new CustomGoogleGeminiClient({
|
||||||
e,
|
e,
|
||||||
userId: e?.sender?.user_id,
|
userId: e?.sender?.user_id,
|
||||||
key: Config.geminiKey,
|
key: Config.getGeminiKey(),
|
||||||
model: Config.geminiModel,
|
model: Config.geminiModel,
|
||||||
baseUrl: Config.geminiBaseUrl,
|
baseUrl: Config.geminiBaseUrl,
|
||||||
debug: Config.debug
|
debug: Config.debug
|
||||||
|
|
|
||||||
|
|
@ -146,7 +146,7 @@ export async function translate (msg, to = 'auto', from = 'auto', ai = Config.tr
|
||||||
}
|
}
|
||||||
case 'gemini': {
|
case 'gemini': {
|
||||||
let client = new CustomGoogleGeminiClient({
|
let client = new CustomGoogleGeminiClient({
|
||||||
key: Config.geminiKey,
|
key: Config.getGeminiKey(),
|
||||||
model: Config.geminiModel,
|
model: Config.geminiModel,
|
||||||
baseUrl: Config.geminiBaseUrl,
|
baseUrl: Config.geminiBaseUrl,
|
||||||
debug: Config.debug
|
debug: Config.debug
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue