From bc989580a9d39f4d1a7b7c10d04415d6839c846b Mon Sep 17 00:00:00 2001 From: Kevin Dang <77701718+kevinthedang@users.noreply.github.com> Date: Sat, 20 Apr 2024 10:03:22 -0700 Subject: [PATCH] Fix Capacity Command (#49) * fix: capacity while replace if * fix: command name in config --- src/events/messageCreate.ts | 12 ++++++------ src/utils/jsonHandler.ts | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts index 3f0f827..54234ba 100644 --- a/src/events/messageCreate.ts +++ b/src/events/messageCreate.ts @@ -36,13 +36,13 @@ export default event(Events.MessageCreate, async ({ log, msgHist, tokens, ollama } // check if there is a set capacity in config - if (typeof config.options['history-capacity'] !== 'number') + if (typeof config.options['modify-capacity'] !== 'number') log(`Capacity is undefined, using default capacity of ${msgHist.capacity}.`) - else if (config.options['history-capacity'] === msgHist.capacity) + else if (config.options['modify-capacity'] === msgHist.capacity) log(`Capacity matches config as ${msgHist.capacity}, no changes made.`) else { - log(`New Capacity found. Setting Context Capacity to ${config.options['history-capacity']}.`) - msgHist.capacity = config.options['history-capacity'] + log(`New Capacity found. Setting Context Capacity to ${config.options['modify-capacity']}.`) + msgHist.capacity = config.options['modify-capacity'] } resolve(config) @@ -52,7 +52,7 @@ export default event(Events.MessageCreate, async ({ log, msgHist, tokens, ollama let response: ChatResponse // check if we can push, if not, remove oldest - if (msgHist.size() === msgHist.capacity) msgHist.dequeue() + while (msgHist.size() >= msgHist.capacity) msgHist.dequeue() // push user response before ollama query msgHist.enqueue({ @@ -70,7 +70,7 @@ export default event(Events.MessageCreate, async ({ log, msgHist, tokens, ollama if (response == undefined) { msgHist.pop(); return } // if queue is full, remove the oldest message - if (msgHist.size() === msgHist.capacity) msgHist.dequeue() + while (msgHist.size() >= msgHist.capacity) msgHist.dequeue() // successful query, save it in context history msgHist.enqueue({ diff --git a/src/utils/jsonHandler.ts b/src/utils/jsonHandler.ts index d133f9c..1ec95a6 100644 --- a/src/utils/jsonHandler.ts +++ b/src/utils/jsonHandler.ts @@ -6,7 +6,7 @@ export interface Configuration { 'message-stream'?: boolean, 'message-style'?: boolean, 'toggle-chat'?: boolean, - 'history-capacity'?: number + 'modify-capacity'?: number } }