Exported getTextGenServer, extractMessageFromData, getPresetManager methods. Added optional parameters to some methods for generic usage.

092ef261444a5172e6d267cda5517cc05fa1dd54

bmen25124 <bmen25124@gmail.com>

3 files changed, +28 -10Showing whitespace changes
public/script.js+4 -3
@@ -5708,14 +5708,15 @@ function parseAndSaveLogprobs(data, continueFrom) {
57085708/**
57095709 * Extracts the message from the response data.
57105710 * @param {object} data Response data
5711+ * @param {string | null} activeApi if it's set, ignores active API
57115712 * @returns {string} Extracted message
57125713 */
57135714export function extractMessageFromData(data, activeApi = null) {
57145715 if (typeof data === 'string') {
57155716 return data;
57165717 }
57175718
57185719 switch (activeApi ?? main_api) {
57195720 case 'kobold':
57205721 return data.results[0].text;
57215722 case 'koboldhorde':
@@ -8873,7 +8874,7 @@ const swipe_right = () => {
88738874 }
88748875};
88758876
88768877export const CONNECT_API_MAP = {
88778878 // Default APIs not contined inside text gen / chat gen
88788879 'kobold': {
88798880 selected: 'kobold',
public/scripts/st-context.js+8 -1
@@ -6,11 +6,13 @@ import {
66 characters,
77 chat,
88 chat_metadata,
9+ CONNECT_API_MAP,
910 create_save,
1011 deactivateSendButtons,
1112 event_types,
1213 eventSource,
1314 extension_prompts,
15+ extractMessageFromData,
1416 Generate,
1517 generateQuietPrompt,
1618 getCharacters,
@@ -58,6 +60,7 @@ import { MacrosParser } from './macros.js';
5860import { oai_settings } from './openai.js';
5961import { callGenericPopup, Popup, POPUP_RESULT, POPUP_TYPE } from './popup.js';
6062import { power_user, registerDebugFunction } from './power-user.js';
63+import { getPresetManager } from './preset-manager.js';
6164import { humanizedDateTime, isMobile, shouldSendOnEnter } from './RossAscends-mods.js';
6265import { ScraperManager } from './scrapers.js';
6366import { executeSlashCommands, executeSlashCommandsWithOptions, registerSlashCommand } from './slash-commands.js';
@@ -65,7 +68,7 @@ import { SlashCommand } from './slash-commands/SlashCommand.js';
6568import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js';
6669import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';
6770import { tag_map, tags } from './tags.js';
6871import { getTextGenServer, textgenerationwebui_settings } from './textgen-settings.js';
6972import { tokenizers, getTextTokens, getTokenCount, getTokenCountAsync, getTokenizerModel } from './tokenizers.js';
7073import { ToolManager } from './tool-calling.js';
7174import { accountStorage } from './util/AccountStorage.js';
@@ -193,6 +196,10 @@ export function getContext() {
193196 saveWorldInfo,
194197 updateWorldInfoList,
195198 convertCharacterBook,
199+ CONNECT_API_MAP,
200+ getTextGenServer,
201+ extractMessageFromData,
202+ getPresetManager,
196203 };
197204}
198205
public/scripts/textgen-settings.js+16 -6
@@ -318,8 +318,13 @@ export function validateTextGenUrl() {
318318 control.val(formattedUrl);
319319}
320320
321-export function getTextGenServer() {
321+/**
322- switch (settings.type) {
322+ * @param {string | null} type if it's set, ignores active API
323+ * @returns
324+ */
325+export function getTextGenServer(type = null) {
326+ const selectedType = type ?? settings.type;
327+ switch (selectedType) {
323328 case FEATHERLESS:
324329 return FEATHERLESS_SERVER;
325330 case MANCER:
@@ -333,7 +338,7 @@ export function getTextGenServer() {
333338 case OPENROUTER:
334339 return OPENROUTER_SERVER;
335340 default:
336341 return settings.server_urls[settings.typeselectedType] ?? '';
337342 }
338343}
339344
@@ -1215,8 +1220,13 @@ function isDynamicTemperatureSupported() {
12151220 return settings.dynatemp && DYNATEMP_BLOCK?.dataset?.tgType?.includes(settings.type);
12161221}
12171222
1218-function getLogprobsNumber() {
1223+/**
1219- if (settings.type === VLLM || settings.type === INFERMATICAI) {
1224+ * @param {string | null} type if it's set, ignores active API
1225+ * @returns {number}
1226+ */
1227+export function getLogprobsNumber(type = null) {
1228+ const selectedType = type || settings.type;
1229+ if (selectedType === VLLM || selectedType === INFERMATICAI) {
12201230 return 5;
12211231 }
12221232
@@ -1228,7 +1238,7 @@ function getLogprobsNumber() {
12281238 * @param {string} str Input string
12291239 * @returns {string} Output string
12301240 */
12311241export function replaceMacrosInList(str) {
12321242 if (!str || typeof str !== 'string') {
12331243 return str;
12341244 }