fix 'unusual query volume' check

This commit is contained in:
被遗忘的记忆
2024-10-30 01:23:01 +08:00
committed by GitHub
parent 4ebf967839
commit 78ab7c9b34
+17 -11
View File
@@ -529,16 +529,19 @@ class YouProvider {
} }
checkAndSwitchMode() { checkAndSwitchMode() {
// 如果当前模式不可用
if (!this.modeStatus[this.currentMode]) {
const availableModes = Object.keys(this.modeStatus).filter(mode => this.modeStatus[mode]); const availableModes = Object.keys(this.modeStatus).filter(mode => this.modeStatus[mode]);
if (availableModes.length === 0) { if (availableModes.length === 0) {
console.log("两种模式达到请求上限。"); console.warn("两种模式达到请求上限。");
} else if (availableModes.length === 1) { } else if (availableModes.length === 1) {
console.log(`当前模式 ${this.currentMode} 已达到请求次数阈值`);
this.currentMode = availableModes[0]; this.currentMode = availableModes[0];
this.rotationEnabled = false; this.rotationEnabled = false;
} }
} }
}
async getCompletion({username, messages, stream = false, proxyModel, useCustomMode = false}) { async getCompletion({username, messages, stream = false, proxyModel, useCustomMode = false}) {
if (this.networkMonitor.isNetworkBlocked()) { if (this.networkMonitor.isNetworkBlocked()) {
@@ -559,6 +562,9 @@ class YouProvider {
// 检查 // 检查
if (this.isRotationEnabled) { if (this.isRotationEnabled) {
this.checkAndSwitchMode(); this.checkAndSwitchMode();
if (!Object.values(this.modeStatus).some(status => status)) {
return;
}
} }
// 处理模式轮换逻辑 // 处理模式轮换逻辑
if (this.isCustomModeEnabled && this.isRotationEnabled && this.rotationEnabled) { if (this.isCustomModeEnabled && this.isRotationEnabled && this.rotationEnabled) {
@@ -568,6 +574,8 @@ class YouProvider {
if (this.switchCounter >= this.switchThreshold) { if (this.switchCounter >= this.switchThreshold) {
this.switchMode(); this.switchMode();
} }
} else {
console.log(`当前模式: ${this.currentMode}`);
} }
// 根据轮换状态决定是否使用自定义模式 // 根据轮换状态决定是否使用自定义模式
@@ -774,6 +782,7 @@ class YouProvider {
}, traceId); }, traceId);
}; };
const self = this;
page.exposeFunction("callback" + traceId, async (event, data) => { page.exposeFunction("callback" + traceId, async (event, data) => {
if (isEnding) return; if (isEnding) return;
@@ -794,20 +803,17 @@ class YouProvider {
// 检测 'unusual query volume' // 检测 'unusual query volume'
if (tokenContent.includes('unusual query volume')) { if (tokenContent.includes('unusual query volume')) {
console.log("检测到请求量异常提示");
isEnding = true;
if (self.isRotationEnabled) { if (self.isRotationEnabled) {
self.modeStatus[self.currentMode] = false; self.modeStatus[self.currentMode] = false;
self.checkAndSwitchMode(); self.checkAndSwitchMode();
emitter.emit("error", new Error(`模式达到请求上限,已切换模式 ${self.currentMode},请重试请求。`)); if (Object.values(self.modeStatus).some(status => status)) {
console.log(`模式达到请求上限,已切换模式 ${self.currentMode},请重试请求。`);
} else {
emitter.emit("error", new Error("检测到请求量异常提示,请求终止。"));
} }
await cleanup(); } else {
return; console.log("检测到请求量异常提示,请求终止。");
}
isEnding = true;
} }
process.stdout.write(tokenContent); process.stdout.write(tokenContent);