Merge pull request #3554 from bmen25124/new_exports

Exported getTextGenServer, extractMessageFromData methods. added opti…
This commit is contained in:
Cohee 2025-02-25 12:23:09 +02:00 committed by GitHub
commit 20a982491a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 10 deletions

View File

@ -5708,14 +5708,15 @@ function parseAndSaveLogprobs(data, continueFrom) {
/**
* Extracts the message from the response data.
* @param {object} data Response data
* @param {string} 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',

View File

@ -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,
};
}

View File

@ -318,8 +318,14 @@ export function validateTextGenUrl() {
control.val(formattedUrl);
}
export function getTextGenServer() {
switch (settings.type) {
/**
* Gets the API URL for the selected text generation type.
* @param {string} type If it's set, ignores active type
* @returns {string} API URL
*/
export function getTextGenServer(type = null) {
const selectedType = type ?? settings.type;
switch (selectedType) {
case FEATHERLESS:
return FEATHERLESS_SERVER;
case MANCER:
@ -333,7 +339,7 @@ export function getTextGenServer() {
case OPENROUTER:
return OPENROUTER_SERVER;
default:
return settings.server_urls[settings.type] ?? '';
return settings.server_urls[selectedType] ?? '';
}
}
@ -1215,8 +1221,14 @@ function isDynamicTemperatureSupported() {
return settings.dynatemp && DYNATEMP_BLOCK?.dataset?.tgType?.includes(settings.type);
}
function getLogprobsNumber() {
if (settings.type === VLLM || settings.type === INFERMATICAI) {
/**
* Gets the number of logprobs to request based on the selected type.
* @param {string} type If it's set, ignores active type
* @returns {number} Number of logprobs to request
*/
export function getLogprobsNumber(type = null) {
const selectedType = type ?? settings.type;
if (selectedType === VLLM || selectedType === INFERMATICAI) {
return 5;
}
@ -1228,7 +1240,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;
}