From ae996460d1b637c101635a130376bb2e011f0e7e Mon Sep 17 00:00:00 2001 From: Kenneth Lane Thompson Date: Fri, 3 Feb 2023 14:24:05 +0800 Subject: [PATCH 1/2] Resolve the failure of the resetSession() call caused by userDataDir. Correct the malfunction in the login process resulting from userDataDir. --- legacy/src/chatgpt-api-browser.ts | 2 ++ legacy/src/chatgpt-api.ts | 2 +- legacy/src/utils.ts | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/legacy/src/chatgpt-api-browser.ts b/legacy/src/chatgpt-api-browser.ts index e34233fb..80e899f5 100644 --- a/legacy/src/chatgpt-api-browser.ts +++ b/legacy/src/chatgpt-api-browser.ts @@ -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) { diff --git a/legacy/src/chatgpt-api.ts b/legacy/src/chatgpt-api.ts index 0efe2b37..40179de2 100644 --- a/legacy/src/chatgpt-api.ts +++ b/legacy/src/chatgpt-api.ts @@ -212,7 +212,7 @@ export class ChatGPTAPI extends AChatGPTAPI { } } ], - model: 'text-davinci-002-render-next', + model: 'text-davinci-002-render', parent_message_id: parentMessageId } diff --git a/legacy/src/utils.ts b/legacy/src/utils.ts index 5f4cfb37..7df13a0e 100644 --- a/legacy/src/utils.ts +++ b/legacy/src/utils.ts @@ -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') From 8595dd1d7c1ba330444201bc68fee3ba407ae82a Mon Sep 17 00:00:00 2001 From: Kenneth Lane Thompson Date: Fri, 3 Feb 2023 18:00:58 +0800 Subject: [PATCH 2/2] Change the model from 'text-davinci-002-render-next' to 'text-davinci-002-render'. --- legacy/src/chatgpt-api-browser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy/src/chatgpt-api-browser.ts b/legacy/src/chatgpt-api-browser.ts index 80e899f5..df0bd458 100644 --- a/legacy/src/chatgpt-api-browser.ts +++ b/legacy/src/chatgpt-api-browser.ts @@ -466,7 +466,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI { ], model: this._isProAccount ? 'text-davinci-002-render-paid' - : 'text-davinci-002-render-next', + : 'text-davinci-002-render', parent_message_id: parentMessageId }