Merge pull request #3554 from bmen25124/new_exports Exported getTextGenServer, extractMessageFromData methods. added opti…

20a982491ac3e20b3186839ee92f096260d34d64

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
3 files changed, +30 -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} 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+18 -6
@@ -318,8 +318,14 @@ export function validateTextGenUrl() {
318 control.val(formattedUrl);318 control.val(formattedUrl);
319}319}
320320
321export function getTextGenServer() {321/**
322 switch (settings.type) {322 * Gets the API URL for the selected text generation type.
323 * @param {string} type If it's set, ignores active type
324 * @returns {string} API URL
325 */
326export function getTextGenServer(type = null) {
327 const selectedType = type ?? settings.type;
328 switch (selectedType) {
323 case FEATHERLESS:329 case FEATHERLESS:
324 return FEATHERLESS_SERVER;330 return FEATHERLESS_SERVER;
325 case MANCER:331 case MANCER:
@@ -333,7 +339,7 @@ export function getTextGenServer() {
333 case OPENROUTER:339 case OPENROUTER:
334 return OPENROUTER_SERVER;340 return OPENROUTER_SERVER;
335 default:341 default:
336 return settings.server_urls[settings.type] ?? '';342 return settings.server_urls[selectedType] ?? '';
337 }343 }
338}344}
339345
@@ -1215,8 +1221,14 @@ function isDynamicTemperatureSupported() {
1215 return settings.dynatemp && DYNATEMP_BLOCK?.dataset?.tgType?.includes(settings.type);1221 return settings.dynatemp && DYNATEMP_BLOCK?.dataset?.tgType?.includes(settings.type);
1216}1222}
12171223
1218function getLogprobsNumber() {1224/**
1219 if (settings.type === VLLM || settings.type === INFERMATICAI) {1225 * Gets the number of logprobs to request based on the selected type.
1226 * @param {string} type If it's set, ignores active type
1227 * @returns {number} Number of logprobs to request
1228 */
1229export function getLogprobsNumber(type = null) {
1230 const selectedType = type ?? settings.type;
1231 if (selectedType === VLLM || selectedType === INFERMATICAI) {
1220 return 5;1232 return 5;
1221 }1233 }
12221234
@@ -1228,7 +1240,7 @@ function getLogprobsNumber() {
1228 * @param {string} str Input string1240 * @param {string} str Input string
1229 * @returns {string} Output string1241 * @returns {string} Output string
1230 */1242 */
1231function replaceMacrosInList(str) {1243export function replaceMacrosInList(str) {
1232 if (!str || typeof str !== 'string') {1244 if (!str || typeof str !== 'string') {
1233 return str;1245 return str;
1234 }1246 }