From 8555d8eb14e103fd4429920d6b12ec2196e8abcb Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Tue, 21 Mar 2023 12:51:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A6=96=E5=8F=A5aplogy=E6=97=B6?= =?UTF-8?q?=E4=B8=8D=E5=8A=A0=E5=85=A5=E5=88=B0=E8=81=8A=E5=A4=A9=E8=AE=B0?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/SydneyAIClient.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/utils/SydneyAIClient.js b/utils/SydneyAIClient.js index d4dfde5..17f4db3 100644 --- a/utils/SydneyAIClient.js +++ b/utils/SydneyAIClient.js @@ -6,7 +6,7 @@ import fetch, { import crypto from 'crypto' import HttpsProxyAgent from 'https-proxy-agent' -import {Config, pureSydneyInstruction} from './config.js' +import { Config, pureSydneyInstruction } from './config.js' import { isCN } from './common.js' if (!globalThis.fetch) { @@ -322,7 +322,6 @@ export default class SydneyAIClient { role: 'User', message } - conversation.messages.push(userMessage) const ws = await this.createWebSocketConnection() if (Config.debug) { @@ -400,7 +399,7 @@ export default class SydneyAIClient { target: 'chat', type: 4 } - + let apology = false const messagePromise = new Promise((resolve, reject) => { let replySoFar = '' let adaptiveCardsSoFar = null @@ -477,6 +476,9 @@ export default class SydneyAIClient { } if (messages[0].contentOrigin === 'Apology') { console.log('Apology found') + if (!replySoFar) { + apology = true + } stopTokenFound = true clearTimeout(messageTimeout) clearTimeout(firstTimeout) @@ -541,6 +543,9 @@ export default class SydneyAIClient { return } if (message.contentOrigin === 'Apology') { + if (!replySoFar) { + apology = true + } console.log('Apology found') stopTokenFound = true clearTimeout(messageTimeout) @@ -610,10 +615,12 @@ export default class SydneyAIClient { message: reply.text, details: reply } - conversation.messages.push(replyMessage) - - await this.conversationsCache.set(conversationKey, conversation) + if (!apology) { + conversation.messages.push(userMessage) + conversation.messages.push(replyMessage) + await this.conversationsCache.set(conversationKey, conversation) + } return { conversationSignature, conversationId, @@ -622,7 +629,8 @@ export default class SydneyAIClient { messageId: replyMessage.id, conversationExpiryTime, response: reply.text, - details: reply + details: reply, + apology } }