fix: 试图拯救浏览器模式,不行就弃了

This commit is contained in:
ikechan8370 2023-03-26 21:43:35 +08:00
parent 6f8eb1dd84
commit f1479f0e10
2 changed files with 24 additions and 67 deletions

View file

@ -256,6 +256,14 @@ export class chatgpt extends plugin {
await redis.del(`CHATGPT:CONVERSATIONS_BING:${e.sender.user_id}`)
await this.reply('已结束当前对话,请@我进行聊天以开启新的对话', true)
}
} else if (use === 'browser') {
let c = await redis.get(`CHATGPT:CONVERSATIONS_BROWSER:${e.sender.user_id}`)
if (!c) {
await this.reply('当前没有开启对话', true)
} else {
await redis.del(`CHATGPT:CONVERSATIONS_BROWSER:${e.sender.user_id}`)
await this.reply('已结束当前对话,请@我进行聊天以开启新的对话', true)
}
}
} else {
let at = ats[0]
@ -309,6 +317,14 @@ export class chatgpt extends plugin {
await redis.del(`CHATGPT:CONVERSATIONS_BING:${qq}`)
await this.reply(`已结束${atUser}的对话TA仍可以@我进行聊天以开启新的对话`, true)
}
} else if (use === 'browser') {
let c = await redis.get(`CHATGPT:CONVERSATIONS_BROWSER:${qq}`)
if (!c) {
await this.reply(`当前${atUser}没有开启对话`, true)
} else {
await redis.del(`CHATGPT:CONVERSATIONS_BROWSER:${qq}`)
await this.reply(`已结束${atUser}的对话TA仍可以@我进行聊天以开启新的对话`, true)
}
}
}
}
@ -674,6 +690,10 @@ export class chatgpt extends plugin {
key = `CHATGPT:CONVERSATIONS_CHATGLM:${e.sender.user_id}`
break
}
case 'browser': {
key = `CHATGPT:CONVERSATIONS_BROWSER:${e.sender.user_id}`
break
}
}
let ctime = new Date()
previousConversation = await redis.get(key) || JSON.stringify({
@ -745,15 +765,15 @@ export class chatgpt extends plugin {
}
if (useTTS) {
if (Config.ttsSpace && response.length <= Config.ttsAutoFallbackThreshold) {
let audio_err = false
let audioErr = false
try {
let wav = await generateAudio(response, speaker, '中日混合(中文用[ZH][ZH]包裹起来,日文用[JA][JA]包裹起来)')
await e.reply(segment.record(wav))
} catch (err) {
await this.reply('合成语音发生错误,我用文本回复你吧')
audio_err = true
audioErr = true
}
if (Config.alsoSendText || audio_err) {
if (Config.alsoSendText || audioErr) {
await this.reply(`${response}`, e.isGroup)
if (quotemessage.length > 0) {
this.reply(await makeForwardMsg(this.e, quotemessage))

View file

@ -372,69 +372,6 @@ export class ChatGPTPuppeteer extends Puppeteer {
}
}
// async getLastMessage(): Promise<string | null> {
// const messages = await this.getMessages()
// if (messages) {
// return messages[messages.length - 1]
// } else {
// return null
// }
// }
// async getPrompts(): Promise<string[]> {
// // Get all prompts
// const messages = await this._page.$$(
// '.text-base:has(.whitespace-pre-wrap):not(:has(button:nth-child(2))) .whitespace-pre-wrap'
// )
// // Prompts are always plaintext
// return Promise.all(messages.map((a) => a.evaluate((el) => el.textContent)))
// }
// async getMessages(): Promise<string[]> {
// // Get all complete messages
// // (in-progress messages that are being streamed back don't contain action buttons)
// const messages = await this._page.$$(
// '.text-base:has(.whitespace-pre-wrap):has(button:nth-child(2)) .whitespace-pre-wrap'
// )
// if (this._markdown) {
// const htmlMessages = await Promise.all(
// messages.map((a) => a.evaluate((el) => el.innerHTML))
// )
// const markdownMessages = htmlMessages.map((messageHtml) => {
// // parse markdown from message HTML
// messageHtml = messageHtml
// .replaceAll('Copy code</button>', '</button>')
// .replace(/Copy code\s*<\/button>/gim, '</button>')
// return html2md(messageHtml, {
// ignoreTags: [
// 'button',
// 'svg',
// 'style',
// 'form',
// 'noscript',
// 'script',
// 'meta',
// 'head'
// ],
// skipTags: ['button', 'svg']
// })
// })
// return markdownMessages
// } else {
// // plaintext
// const plaintextMessages = await Promise.all(
// messages.map((a) => a.evaluate((el) => el.textContent))
// )
// return plaintextMessages
// }
// }
async sendMessage (
message,
opts = {}
@ -496,7 +433,7 @@ export class ChatGPTPuppeteer extends Puppeteer {
}
}
],
model: Config.plus ? 'text-davinci-002-render-sha' : 'text-davinci-002-render-sha',
model: Config.plus ? Config.useGPT4 ? 'gpt-4' : 'text-davinci-002-render-sha' : 'text-davinci-002-render-sha',
parent_message_id: parentMessageId
}