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.
This commit is contained in:
Alex Denton
2024-12-08 23:31:03 +01:00
committed by GitHub
parent 9a13128398
commit f98f83471a

View File

@ -697,6 +697,11 @@ async function moduleWorker() {
return; 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 // API is busy
if (inApiCall) { if (inApiCall) {
console.debug('Classification API is busy'); console.debug('Classification API is busy');
@ -995,6 +1000,11 @@ function sampleClassifyText(text) {
// Replace macros, remove asterisks and quotes // Replace macros, remove asterisks and quotes
let result = substituteParams(text).replace(/[*"]/g, ''); 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 SAMPLE_THRESHOLD = 500;
const HALF_SAMPLE_THRESHOLD = SAMPLE_THRESHOLD / 2; const HALF_SAMPLE_THRESHOLD = SAMPLE_THRESHOLD / 2;