Skip to content

Commit

Permalink
fix(forefront): switch to gpt4 retry 3 times
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangsx committed Jun 6, 2023
1 parent 4e48f9f commit a176ae7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions model/forefront/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class AccountPool {
const now = moment();
const minInterval = 3 * 60 * 60 + 10 * 60;// 3hour + 10min
for (const item of this.pool) {
console.log(now.unix() - moment(item.last_use_time).unix());
if (now.unix() - moment(item.last_use_time).unix() > minInterval) {
console.log(`find old login account:`, item);
item.last_use_time = now.format(TimeFormat);
this.syncfile();
return item
Expand Down Expand Up @@ -122,9 +122,13 @@ export class Forefrontnew extends Chat {
}
}

private static async switchToGpt4(page: Page) {
private static async switchToGpt4(page: Page, triedTimes: number = 0) {
if (triedTimes === 3) {
return;
}
try {
console.log('switch gpt4....')
triedTimes += 1;
await page.waitForTimeout(2000);
await page.waitForSelector('div > .absolute > .relative > .w-full:nth-child(3) > .relative')
await page.click('div > .absolute > .relative > .w-full:nth-child(3) > .relative');
Expand All @@ -140,10 +144,10 @@ export class Forefrontnew extends Chat {
await page.waitForSelector('.px-4 > .flex > .grid > .block > .group:nth-child(5)')
await page.click('.px-4 > .flex > .grid > .block > .group:nth-child(5)')
console.log('switch gpt4 ok!')
}catch (e) {
} catch (e) {
console.log(e);
await page.reload();
await Forefrontnew.switchToGpt4(page);
await Forefrontnew.switchToGpt4(page, triedTimes);
}
}

Expand Down

0 comments on commit a176ae7

Please sign in to comment.