diff --git a/public/script.js b/public/script.js index 39601458f..db75672ba 100644 --- a/public/script.js +++ b/public/script.js @@ -5708,14 +5708,15 @@ function parseAndSaveLogprobs(data, continueFrom) { /** * Extracts the message from the response data. * @param {object} data Response data + * @param {string | null} activeApi if it's set, ignores active API * @returns {string} Extracted message */ -function extractMessageFromData(data) { +export function extractMessageFromData(data, activeApi = null) { if (typeof data === 'string') { return data; } - switch (main_api) { + switch (activeApi ?? main_api) { case 'kobold': return data.results[0].text; case 'koboldhorde': @@ -8873,7 +8874,7 @@ const swipe_right = () => { } }; -const CONNECT_API_MAP = { +export const CONNECT_API_MAP = { // Default APIs not contined inside text gen / chat gen 'kobold': { selected: 'kobold', diff --git a/public/scripts/st-context.js b/public/scripts/st-context.js index a9a604032..729418552 100644 --- a/public/scripts/st-context.js +++ b/public/scripts/st-context.js @@ -6,11 +6,13 @@ import { characters, chat, chat_metadata, + CONNECT_API_MAP, create_save, deactivateSendButtons, event_types, eventSource, extension_prompts, + extractMessageFromData, Generate, generateQuietPrompt, getCharacters, @@ -58,6 +60,7 @@ import { MacrosParser } from './macros.js'; import { oai_settings } from './openai.js'; import { callGenericPopup, Popup, POPUP_RESULT, POPUP_TYPE } from './popup.js'; import { power_user, registerDebugFunction } from './power-user.js'; +import { getPresetManager } from './preset-manager.js'; import { humanizedDateTime, isMobile, shouldSendOnEnter } from './RossAscends-mods.js'; import { ScraperManager } from './scrapers.js'; import { executeSlashCommands, executeSlashCommandsWithOptions, registerSlashCommand } from './slash-commands.js'; @@ -65,7 +68,7 @@ import { SlashCommand } from './slash-commands/SlashCommand.js'; import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js'; import { SlashCommandParser } from './slash-commands/SlashCommandParser.js'; import { tag_map, tags } from './tags.js'; -import { textgenerationwebui_settings } from './textgen-settings.js'; +import { getTextGenServer, textgenerationwebui_settings } from './textgen-settings.js'; import { tokenizers, getTextTokens, getTokenCount, getTokenCountAsync, getTokenizerModel } from './tokenizers.js'; import { ToolManager } from './tool-calling.js'; import { accountStorage } from './util/AccountStorage.js'; @@ -193,6 +196,10 @@ export function getContext() { saveWorldInfo, updateWorldInfoList, convertCharacterBook, + CONNECT_API_MAP, + getTextGenServer, + extractMessageFromData, + getPresetManager, }; } diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index aab6213f4..f2c304a95 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -318,8 +318,13 @@ export function validateTextGenUrl() { control.val(formattedUrl); } -export function getTextGenServer() { - switch (settings.type) { +/** + * @param {string | null} type if it's set, ignores active API + * @returns + */ +export function getTextGenServer(type = null) { + const selectedType = type ?? settings.type; + switch (selectedType) { case FEATHERLESS: return FEATHERLESS_SERVER; case MANCER: @@ -333,7 +338,7 @@ export function getTextGenServer() { case OPENROUTER: return OPENROUTER_SERVER; default: - return settings.server_urls[settings.type] ?? ''; + return settings.server_urls[selectedType] ?? ''; } } @@ -1215,8 +1220,13 @@ function isDynamicTemperatureSupported() { return settings.dynatemp && DYNATEMP_BLOCK?.dataset?.tgType?.includes(settings.type); } -function getLogprobsNumber() { - if (settings.type === VLLM || settings.type === INFERMATICAI) { +/** + * @param {string | null} type if it's set, ignores active API + * @returns {number} + */ +export function getLogprobsNumber(type = null) { + const selectedType = type || settings.type; + if (selectedType === VLLM || selectedType === INFERMATICAI) { return 5; } @@ -1228,7 +1238,7 @@ function getLogprobsNumber() { * @param {string} str Input string * @returns {string} Output string */ -function replaceMacrosInList(str) { +export function replaceMacrosInList(str) { if (!str || typeof str !== 'string') { return str; }