Merge pull request #21 from ixuan789/main

捕获OpenAI认证阶段异常
This commit is contained in:
ikechan8370 2022-12-09 17:10:00 +08:00 committed by GitHub
commit 09c7d39555
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View file

@ -117,7 +117,12 @@ export class chatgpt extends plugin {
async chatgpt (e) {
let question = _.trimStart(e.msg, '#chatgpt')
question = question.trimStart()
await this.chatGPTApi.ensureAuth()
try {
await this.chatGPTApi.ensureAuth()
} catch (e) {
logger.error(e)
await this.reply(`OpenAI认证失败请检查Token${e}`, true)
}
let c
logger.info(`chatgpt question: ${question}`)
let previousConversation = await redis.get(`CHATGPT:CONVERSATIONS:${e.sender.user_id}`)

View file

@ -123,6 +123,12 @@ export class chatgpt extends plugin {
}
// let question = _.trimStart(e.msg, '#chatgpt')
let question = e.msg.trimStart()
try {
await this.chatGPTApi.ensureAuth()
} catch (e) {
logger.error(e)
await this.reply(`OpenAI认证失败请检查Token${e}`, true)
}
let c
logger.info(`chatgpt question: ${question}`)
let previousConversation = await redis.get(`CHATGPT:CONVERSATIONS:${e.sender.user_id}`)
@ -146,7 +152,6 @@ export class chatgpt extends plugin {
}
try {
// console.log({ c })
await this.chatGPTApi.ensureAuth()
const response = await c.sendMessage(question)
logger.info(response)
// 更新redis中的conversation对象因为send后c已经被自动更新了