From d4a0cfc83646591c452c3d174871842990c3828a Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Wed, 7 Dec 2022 10:37:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=91=BD=E4=BB=A4=E6=AD=A3=E5=88=99?= =?UTF-8?q?=EF=BC=9B=E6=9B=B4=E6=94=B9=E4=B8=BA=E5=9B=9E=E5=A4=8D=E6=B6=88?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 5a355ee..50842fb 100644 --- a/index.js +++ b/index.js @@ -17,12 +17,14 @@ export class example extends plugin { rule: [ { /** 命令正则匹配 */ - reg: '^#chatgpt.*$', + reg: '^#chatgpt([\s\S]*)', /** 执行方法 */ fnc: 'chatgpt' } ] }) + const api = new ChatGPTAPI({ sessionToken: SESSION_TOKEN, markdown: false }) + this.chatGPTApi = api } /** * 调用chatgpt接口 @@ -31,11 +33,17 @@ export class example extends plugin { async chatgpt (e) { logger.info(e.msg) let question = _.trimStart(e.msg, "#chatgpt") + question = question.trimStart() logger.info(`chatgpt question: ${question}`) - const api = new ChatGPTAPI({ sessionToken: SESSION_TOKEN, markdown: false }) - await api.ensureAuth() - const response = await api.sendMessage(question) + await this.chatGPTApi.ensureAuth() + // @todo conversation + // const response = await this.chatGPTApi.sendMessage(question, { conversationId: '0c382256-d267-4dd4-90e3-a01dd22c20a2', onProgress: this.onProgress }) + const response = await this.chatGPTApi.sendMessage(question) /** 最后回复消息 */ - await this.reply(`${response}`) + await this.reply(`${response}`, true) + } + + onProgress(partialResponse) { + console.log(partialResponse) } }