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 -10Ignore whitespace
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} 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+18 -6
@@ -318,8 +318,14 @@ export function validateTextGenUrl() {
318318 control.val(formattedUrl);
319319}
320320
321-export 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+ */
326+export function getTextGenServer(type = null) {
327+ const selectedType = type ?? settings.type;
328+ switch (selectedType) {
323329 case FEATHERLESS:
324330 return FEATHERLESS_SERVER;
325331 case MANCER:
@@ -333,7 +339,7 @@ export function getTextGenServer() {
333339 case OPENROUTER:
334340 return OPENROUTER_SERVER;
335341 default:
336342 return settings.server_urls[settings.typeselectedType] ?? '';
337343 }
338344}
339345
@@ -1215,8 +1221,14 @@ function isDynamicTemperatureSupported() {
12151221 return settings.dynatemp && DYNATEMP_BLOCK?.dataset?.tgType?.includes(settings.type);
12161222}
12171223
1218-function 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+ */
1229+export function getLogprobsNumber(type = null) {
1230+ const selectedType = type ?? settings.type;
1231+ if (selectedType === VLLM || selectedType === INFERMATICAI) {
12201232 return 5;
12211233 }
12221234
@@ -1228,7 +1240,7 @@ function getLogprobsNumber() {
12281240 * @param {string} str Input string
12291241 * @returns {string} Output string
12301242 */
12311243export function replaceMacrosInList(str) {
12321244 if (!str || typeof str !== 'string') {
12331245 return str;
12341246 }