Commit 74368462 authored by Travis Fischer's avatar Travis Fischer Committed by GitHub

Merge pull request #294 from lvlinkeji/v3

parents a1875fe6 1ec65e40
...@@ -8,6 +8,7 @@ import { AChatGPTAPI } from './abstract-chatgpt-api' ...@@ -8,6 +8,7 @@ import { AChatGPTAPI } from './abstract-chatgpt-api'
import { getBrowser, getOpenAIAuth, getPage } from './openai-auth' import { getBrowser, getOpenAIAuth, getPage } from './openai-auth'
import { import {
browserPostEventStream, browserPostEventStream,
deleteFolderRecursive,
isRelevantRequest, isRelevantRequest,
markdownToText, markdownToText,
maximizePage, maximizePage,
...@@ -351,6 +352,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI { ...@@ -351,6 +352,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
console.log('>>> closing session', this._email) console.log('>>> closing session', this._email)
await this.closeSession() await this.closeSession()
console.log('<<< closing session', this._email) console.log('<<< closing session', this._email)
await deleteFolderRecursive(this._userDataDir)
await this.initSession() await this.initSession()
console.log(`ChatGPT "${this._email}" refreshSession success`) console.log(`ChatGPT "${this._email}" refreshSession success`)
} catch (err) { } catch (err) {
...@@ -464,7 +466,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI { ...@@ -464,7 +466,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
], ],
model: this._isProAccount model: this._isProAccount
? 'text-davinci-002-render-paid' ? 'text-davinci-002-render-paid'
: 'text-davinci-002-render-next', : 'text-davinci-002-render',
parent_message_id: parentMessageId parent_message_id: parentMessageId
} }
......
...@@ -212,7 +212,7 @@ export class ChatGPTAPI extends AChatGPTAPI { ...@@ -212,7 +212,7 @@ export class ChatGPTAPI extends AChatGPTAPI {
} }
} }
], ],
model: 'text-davinci-002-render-next', model: 'text-davinci-002-render',
parent_message_id: parentMessageId parent_message_id: parentMessageId
} }
......
...@@ -3,6 +3,7 @@ import type { ...@@ -3,6 +3,7 @@ import type {
EventSourceParseCallback, EventSourceParseCallback,
EventSourceParser EventSourceParser
} from 'eventsource-parser' } from 'eventsource-parser'
import fs from 'fs'
import type { Page } from 'puppeteer' import type { Page } from 'puppeteer'
import { remark } from 'remark' import { remark } from 'remark'
import stripMarkdown from 'strip-markdown' import stripMarkdown from 'strip-markdown'
...@@ -32,6 +33,20 @@ export async function minimizePage(page: Page) { ...@@ -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) { export async function maximizePage(page: Page) {
const session = await page.target().createCDPSession() const session = await page.target().createCDPSession()
const goods = await session.send('Browser.getWindowForTarget') const goods = await session.send('Browser.getWindowForTarget')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment