From f98f83471a3722bfa970501048aa67ec99ca547f Mon Sep 17 00:00:00 2001 From: Alex Denton <125566609+alexdenton123@users.noreply.github.com> Date: Sun, 8 Dec 2024 23:31:03 +0100 Subject: [PATCH] Update index.js Changes for LLM API - Avoid sending partial API requests when streaming. - Avoid checking character length when using API as it can afford more characters. --- public/scripts/extensions/expressions/index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/public/scripts/extensions/expressions/index.js b/public/scripts/extensions/expressions/index.js index 4130a5b05..fdc146c1a 100644 --- a/public/scripts/extensions/expressions/index.js +++ b/public/scripts/extensions/expressions/index.js @@ -697,6 +697,11 @@ async function moduleWorker() { return; } + // If using LLM api then check if streamingProcessor is finished to avoid sending multiple requests to the API + if (extension_settings.expressions.api === EXPRESSION_API.llm && context.streamingProcessor && !context.streamingProcessor.isFinished) { + return; + } + // API is busy if (inApiCall) { console.debug('Classification API is busy'); @@ -995,6 +1000,11 @@ function sampleClassifyText(text) { // Replace macros, remove asterisks and quotes let result = substituteParams(text).replace(/[*"]/g, ''); + // If using LLM api there is no need to check length of characters + if (extension_settings.expressions.api === EXPRESSION_API.llm) { + return result.trim(); + } + const SAMPLE_THRESHOLD = 500; const HALF_SAMPLE_THRESHOLD = SAMPLE_THRESHOLD / 2;