diff --git a/README.md b/README.md index 5593b1d..352ab7e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +Just a fork for some testing - nothing to see here + + # SillyTavern MultiPlayer (STMP) SillyTavern MultiPlayer is an LLM chat interface that allows multiple users to chat together with one or more AI characters. diff --git a/src/api-calls.js b/src/api-calls.js index b358392..f295cc7 100644 --- a/src/api-calls.js +++ b/src/api-calls.js @@ -39,10 +39,8 @@ async function getAPIDefaults(shouldReturn = null) { TCAPIDefaults = TCAPICallParams; HordeAPIDefaults = HordeAPICallParams; if (shouldReturn) { - let defaults = [TCAPIDefaults, HordeAPIDefaults] - return defaults + return [TCAPIDefaults, HordeAPIDefaults]; } - } catch (error) { logger.error('Error reading or parsing default-API-Parameters.json:', error); } @@ -53,15 +51,18 @@ async function getAPIDefaults(shouldReturn = null) { // and AIChatUserList but BEFORE sending the network request. Enables single-pass // streaming setup (initialize listeners early) without a separate dry-run. async function getAIResponse(isStreaming, hordeKey, engineMode, user, liveConfig, liveAPI, preInitCallback, parsedMessage, shouldContinue) { - // logger.warn('getAIResponse liveAPI:', liveAPI) - // logger.warn(`liveConfig: ${JSON.stringify(liveConfig)}`); const isCCSelected = liveAPI.type === 'CC'; const isClaude = liveAPI.claude; - let apiCallParams; - try { - apiCallParams = engineMode === 'TC' ? TCAPIDefaults : HordeAPIDefaults; + if (!TCAPIDefaults || !HordeAPIDefaults) { + await getAPIDefaults(); + } + let apiCallParams = engineMode === 'TC' ? TCAPIDefaults : HordeAPIDefaults; + + if (!apiCallParams && !isCCSelected) { + throw new Error("API Default Parameters could not be loaded."); + } const charFile = liveConfig.promptConfig.selectedCharacter; const cardData = await fio.charaRead(charFile, 'png'); @@ -137,9 +138,9 @@ async function getAIResponse(isStreaming, hordeKey, engineMode, user, liveConfig apiCallParams.max_tokens = Number(liveConfig.promptConfig.responseLength); } - } + } + - const [finalApiCallParams, entitiesList] = await setStopStrings(liveConfig, apiCallParams, includedChatObjects, liveAPI); // Pre-stream initializer (if provided) @@ -353,7 +354,7 @@ async function setStopStrings(liveConfig, APICallParams, includedChatObjects, li //logger.info(APICallParams) //logger.info(targetObj) // logger.debug(liveAPI) - // logger.debug(liveConfig) + // logger.debug(liveConfig) if (liveAPI.claude === (1 || true)) { //for claude //logger.info('setting Claude stop strings') APICallParams.stop_sequences = targetObj @@ -374,12 +375,15 @@ async function setStopStrings(liveConfig, APICallParams, includedChatObjects, li //MARK: replaceMacros function replaceMacros(string, username = null, charname = null) { //logger.debug(username, charname) - var replacedString = string + if (typeof string !== 'string') { + return ''; + } + var replacedString = string; if (username !== null && charname !== null) { - replacedString = replacedString.replace(/{{user}}/g, username); - replacedString = replacedString.replace(/{{char}}/g, charname); + replacedString = replacedString.replace(/{{user}}/g, username); + replacedString = replacedString.replace(/{{char}}/g, charname); } - return replacedString + return replacedString; } function collapseNewlines(x) { diff --git a/src/stream.js b/src/stream.js index c5d295e..458eb4e 100644 --- a/src/stream.js +++ b/src/stream.js @@ -186,10 +186,14 @@ const createTextListener = async (parsedMessage, liveConfig, AIChatUserList, use const isPrefillDisabled = liveConfig.promptConfig.killResponsePrefill === true; - if (!isPrefillDisabled && !haveInsertedPrefillForDisplayYet && !shouldContinue && liveConfig.promptConfig.responsePrefill.length > 0) { - //logger.error('TEXTLISTENER: inserting prefill for display:', liveConfig.promptConfig.responsePrefill) - //this just adds the prefill into the displayed output. - accumulatedStreamOutput += liveConfig.promptConfig.responsePrefill; + if (!isPrefillDisabled && !haveInsertedPrefillForDisplayYet && !shouldContinue && + // (liveConfig?.promptConfig?.responsePrefill ?? []) forces array + (Array.isArray(liveConfig?.promptConfig?.responsePrefill) ? + liveConfig.promptConfig.responsePrefill : + []).length > 0 + ) { + // Add the prefill value to the output string. + accumulatedStreamOutput += String(liveConfig?.promptConfig?.responsePrefill ?? []); haveInsertedPrefillForDisplayYet = true; }