From 37f76c4ca5f07fe257f2fb8f9026e7c1f5b9f204 Mon Sep 17 00:00:00 2001 From: Pierre-Gilles Leymarie Date: Fri, 8 Nov 2024 13:55:21 +0100 Subject: [PATCH] ChatGPT: Add "NO_RESPONSE" option in case no answer is needed (#2163) --- server/lib/gateway/gateway.forwardMessageToOpenAI.js | 2 +- .../gateway/gateway.forwardMessageToOpenAI.test.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/server/lib/gateway/gateway.forwardMessageToOpenAI.js b/server/lib/gateway/gateway.forwardMessageToOpenAI.js index bcdae2a0f9..29e84052c3 100644 --- a/server/lib/gateway/gateway.forwardMessageToOpenAI.js +++ b/server/lib/gateway/gateway.forwardMessageToOpenAI.js @@ -11,7 +11,7 @@ const intentTranslation = { INFO: 'info.get-info', }; -const disableOpenAiFirstReply = new Set(['GET_TEMPERATURE', 'GET_HUMIDITY']); +const disableOpenAiFirstReply = new Set(['GET_TEMPERATURE', 'GET_HUMIDITY', 'NO_RESPONSE']); /** * @public diff --git a/server/test/lib/gateway/gateway.forwardMessageToOpenAI.test.js b/server/test/lib/gateway/gateway.forwardMessageToOpenAI.test.js index e6913af973..8eeca35d4e 100644 --- a/server/test/lib/gateway/gateway.forwardMessageToOpenAI.test.js +++ b/server/test/lib/gateway/gateway.forwardMessageToOpenAI.test.js @@ -205,6 +205,18 @@ describe('gateway.forwardMessageToOpenAI', () => { intent: 'temperature-sensor.get-in-room', }); }); + it('should do nothing, no-response was sent', async () => { + gateway.gladysGatewayClient.openAIAsk = fake.resolves({ + type: 'NO_RESPONSE', + answer: '', + room: '', + }); + const classification = await gateway.forwardMessageToOpenAI({ message, previousQuestions, context }); + expect(classification).to.deep.equal({ + intent: undefined, + }); + assert.notCalled(messageManager.reply); + }); it('should start scene from OpenAI', async () => { gateway.gladysGatewayClient.openAIAsk = fake.resolves({ type: 'SCENE_START',