Resolve the failure of the resetSession() call caused by userDataDir. Correct the malfunction in the login process resulting from userDataDir.

chatgpt-api-old-v3
Kenneth Lane Thompson 2023-02-03 14:24:05 +08:00
rodzic 5980524acb
commit ae996460d1
3 zmienionych plików z 18 dodań i 1 usunięć

Wyświetl plik

@ -8,6 +8,7 @@ import { AChatGPTAPI } from './abstract-chatgpt-api'
import { getBrowser, getOpenAIAuth, getPage } from './openai-auth'
import {
browserPostEventStream,
deleteFolderRecursive,
isRelevantRequest,
markdownToText,
maximizePage,
@ -351,6 +352,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
console.log('>>> closing session', this._email)
await this.closeSession()
console.log('<<< closing session', this._email)
await deleteFolderRecursive(this._userDataDir)
await this.initSession()
console.log(`ChatGPT "${this._email}" refreshSession success`)
} catch (err) {

Wyświetl plik

@ -212,7 +212,7 @@ export class ChatGPTAPI extends AChatGPTAPI {
}
}
],
model: 'text-davinci-002-render-next',
model: 'text-davinci-002-render',
parent_message_id: parentMessageId
}

Wyświetl plik

@ -3,6 +3,7 @@ import type {
EventSourceParseCallback,
EventSourceParser
} from 'eventsource-parser'
import fs from 'fs'
import type { Page } from 'puppeteer'
import { remark } from 'remark'
import stripMarkdown from 'strip-markdown'
@ -32,6 +33,20 @@ export async function minimizePage(page: Page) {
})
}
export async function deleteFolderRecursive(path: string) {
if (fs.existsSync(path)) {
fs.readdirSync(path).forEach(function (file, index) {
var curPath = path + '/' + file
if (fs.lstatSync(curPath).isDirectory()) {
deleteFolderRecursive(curPath)
} else {
fs.unlinkSync(curPath)
}
})
fs.rmdirSync(path)
}
}
export async function maximizePage(page: Page) {
const session = await page.target().createCDPSession()
const goods = await session.send('Browser.getWindowForTarget')