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) {
5708/**5708/**
5709 * Extracts the message from the response data.5709 * Extracts the message from the response data.
5710 * @param {object} data Response data5710 * @param {object} data Response data
5711 * @param {string | null} activeApi if it's set, ignores active API
5711 * @returns {string} Extracted message5712 * @returns {string} Extracted message
5712 */5713 */
5713function extractMessageFromData(data) {5714export function extractMessageFromData(data, activeApi = null) {
5714 if (typeof data === 'string') {5715 if (typeof data === 'string') {
5715 return data;5716 return data;
5716 }5717 }
57175718
5718 switch (main_api) {5719 switch (activeApi ?? main_api) {
5719 case 'kobold':5720 case 'kobold':
5720 return data.results[0].text;5721 return data.results[0].text;
5721 case 'koboldhorde':5722 case 'koboldhorde':
@@ -8873,7 +8874,7 @@ const swipe_right = () => {
8873 }8874 }
8874};8875};
88758876
8876const CONNECT_API_MAP = {8877export const CONNECT_API_MAP = {
8877 // Default APIs not contined inside text gen / chat gen8878 // Default APIs not contined inside text gen / chat gen
8878 'kobold': {8879 'kobold': {
8879 selected: 'kobold',8880 selected: 'kobold',
public/scripts/st-context.js+8 -1
@@ -6,11 +6,13 @@ import {
6 characters,6 characters,
7 chat,7 chat,
8 chat_metadata,8 chat_metadata,
9 CONNECT_API_MAP,
9 create_save,10 create_save,
10 deactivateSendButtons,11 deactivateSendButtons,
11 event_types,12 event_types,
12 eventSource,13 eventSource,
13 extension_prompts,14 extension_prompts,
15 extractMessageFromData,
14 Generate,16 Generate,
15 generateQuietPrompt,17 generateQuietPrompt,
16 getCharacters,18 getCharacters,
@@ -58,6 +60,7 @@ import { MacrosParser } from './macros.js';
58import { oai_settings } from './openai.js';60import { oai_settings } from './openai.js';
59import { callGenericPopup, Popup, POPUP_RESULT, POPUP_TYPE } from './popup.js';61import { callGenericPopup, Popup, POPUP_RESULT, POPUP_TYPE } from './popup.js';
60import { power_user, registerDebugFunction } from './power-user.js';62import { power_user, registerDebugFunction } from './power-user.js';
63import { getPresetManager } from './preset-manager.js';
61import { humanizedDateTime, isMobile, shouldSendOnEnter } from './RossAscends-mods.js';64import { humanizedDateTime, isMobile, shouldSendOnEnter } from './RossAscends-mods.js';
62import { ScraperManager } from './scrapers.js';65import { ScraperManager } from './scrapers.js';
63import { executeSlashCommands, executeSlashCommandsWithOptions, registerSlashCommand } from './slash-commands.js';66import { executeSlashCommands, executeSlashCommandsWithOptions, registerSlashCommand } from './slash-commands.js';
@@ -65,7 +68,7 @@ import { SlashCommand } from './slash-commands/SlashCommand.js';
65import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js';68import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js';
66import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';69import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';
67import { tag_map, tags } from './tags.js';70import { tag_map, tags } from './tags.js';
68import { textgenerationwebui_settings } from './textgen-settings.js';71import { getTextGenServer, textgenerationwebui_settings } from './textgen-settings.js';
69import { tokenizers, getTextTokens, getTokenCount, getTokenCountAsync, getTokenizerModel } from './tokenizers.js';72import { tokenizers, getTextTokens, getTokenCount, getTokenCountAsync, getTokenizerModel } from './tokenizers.js';
70import { ToolManager } from './tool-calling.js';73import { ToolManager } from './tool-calling.js';
71import { accountStorage } from './util/AccountStorage.js';74import { accountStorage } from './util/AccountStorage.js';
@@ -193,6 +196,10 @@ export function getContext() {
193 saveWorldInfo,196 saveWorldInfo,
194 updateWorldInfoList,197 updateWorldInfoList,
195 convertCharacterBook,198 convertCharacterBook,
199 CONNECT_API_MAP,
200 getTextGenServer,
201 extractMessageFromData,
202 getPresetManager,
196 };203 };
197}204}
198205
public/scripts/textgen-settings.js+16 -6
@@ -318,8 +318,13 @@ export function validateTextGenUrl() {
318 control.val(formattedUrl);318 control.val(formattedUrl);
319}319}
320320
321export function getTextGenServer() {321/**
322 switch (settings.type) {322 * @param {string | null} type if it's set, ignores active API
323 * @returns
324 */
325export function getTextGenServer(type = null) {
326 const selectedType = type ?? settings.type;
327 switch (selectedType) {
323 case FEATHERLESS:328 case FEATHERLESS:
324 return FEATHERLESS_SERVER;329 return FEATHERLESS_SERVER;
325 case MANCER:330 case MANCER:
@@ -333,7 +338,7 @@ export function getTextGenServer() {
333 case OPENROUTER:338 case OPENROUTER:
334 return OPENROUTER_SERVER;339 return OPENROUTER_SERVER;
335 default:340 default:
336 return settings.server_urls[settings.type] ?? '';341 return settings.server_urls[selectedType] ?? '';
337 }342 }
338}343}
339344
@@ -1215,8 +1220,13 @@ function isDynamicTemperatureSupported() {
1215 return settings.dynatemp && DYNATEMP_BLOCK?.dataset?.tgType?.includes(settings.type);1220 return settings.dynatemp && DYNATEMP_BLOCK?.dataset?.tgType?.includes(settings.type);
1216}1221}
12171222
1218function 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 */
1227export function getLogprobsNumber(type = null) {
1228 const selectedType = type || settings.type;
1229 if (selectedType === VLLM || selectedType === INFERMATICAI) {
1220 return 5;1230 return 5;
1221 }1231 }
12221232
@@ -1228,7 +1238,7 @@ function getLogprobsNumber() {
1228 * @param {string} str Input string1238 * @param {string} str Input string
1229 * @returns {string} Output string1239 * @returns {string} Output string
1230 */1240 */
1231function replaceMacrosInList(str) {1241export function replaceMacrosInList(str) {
1232 if (!str || typeof str !== 'string') {1242 if (!str || typeof str !== 'string') {
1233 return str;1243 return str;
1234 }1244 }