@ovotech/genesys-web-messaging-tester-cli
Version:
63 lines (62 loc) • 2.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.shouldEndConversation = void 0;
const containsTerminatingPhrases_1 = require("./containsTerminatingPhrases");
function shouldEndConversation(utterances, failPhrases, passPhrases) {
if (utterances.length === 0) {
return { hasEnded: false };
}
const lastMessage = utterances.slice(-1);
if (lastMessage.length === 1 && lastMessage[0].content === '') {
const who = lastMessage[0].role === 'customer' ? 'AI' : 'Chatbot';
return {
hasEnded: true,
reason: { type: 'fail', description: `${who} didn't have a response` },
};
}
const lastMsg = utterances.slice(-1);
if (lastMsg[0]?.content) {
const phraseResult = (0, containsTerminatingPhrases_1.containsTerminatingPhrases)(lastMsg[0].content, {
pass: passPhrases,
fail: failPhrases,
});
if (phraseResult.phraseFound) {
return {
hasEnded: true,
reason: {
type: phraseResult.phraseIndicates,
description: `Terminating phrase found in response: '${lastMsg[0].content}'`,
},
};
}
}
// const lastTwoChatGptMsgs = messages.filter((m) => m.role === 'assistant').slice(-2);
// if (lastTwoChatGptMsgs.length === 2) {
// const areMessagesTheSame = lastTwoChatGptMsgs[0].content === lastTwoChatGptMsgs[1].content;
// if (areMessagesTheSame) {
// return {
// hasEnded: true,
// reason: {
// type: 'fail',
// description: 'AI has repeated itself',
// },
// };
// }
// }
// const lastTwoChatBotMsgs = utterances.filter((m) => m.role === 'bot').slice(-2);
// if (lastTwoChatBotMsgs.length === 2) {
// const areMessagesTheSame = lastTwoChatBotMsgs[0].content === lastTwoChatBotMsgs[1].content;
// if (areMessagesTheSame) {
// return {
// hasEnded: true,
//
// reason: {
// type: 'fail',
// description: 'The Chatbot repeated itself',
// },
// };
// }
// }
return { hasEnded: false };
}
exports.shouldEndConversation = shouldEndConversation;