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