From 8f43f11c191b850775dfee2698e22d21387f396e Mon Sep 17 00:00:00 2001 From: Ariya Hidayat Date: Mon, 11 Mar 2024 10:29:57 -0700 Subject: [PATCH] Attach the handler once to avoid too many listeners error --- ask-llm.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ask-llm.js b/ask-llm.js index 966d1fe..83a357d 100755 --- a/ask-llm.js +++ b/ask-llm.js @@ -115,11 +115,11 @@ const SYSTEM_PROMPT = 'Answer the question politely and concisely.'; const messages = []; messages.push({ role: 'system', content: SYSTEM_PROMPT }); + let loop = true; const interface = readline.createInterface({ input: process.stdin, output: process.stdout }); + interface.on('close', () => { loop = false; }); const qa = () => { - let loop = true; - interface.on('close', () => { loop = false; }); interface.question('>> ', async (question) => { messages.push({ role: 'user', content: question }); const start = Date.now();