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 | * Extracts the message from the response data. | 5709 | * Extracts the message from the response data. |
| 5710 | * @param {object} data Response data | 5710 | * @param {object} data Response data |
| 5711 | * @param {string} activeApi If it's set, ignores active API | ||
| 5711 | * @returns {string} Extracted message | 5712 | * @returns {string} Extracted message |
| 5712 | */ | 5713 | */ |
| 5713 | function extractMessageFromData(data) { | 5714 | export function extractMessageFromData(data, activeApi = null) { |
| 5714 | if (typeof data === 'string') { | 5715 | if (typeof data === 'string') { |
| 5715 | return data; | 5716 | return data; |
| 5716 | } | 5717 | } |
| 5717 | 5718 | ||
| 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 | }; |
| 8875 | 8876 | ||
| 8876 | const CONNECT_API_MAP = { | 8877 | export const CONNECT_API_MAP = { |
| 8877 | // Default APIs not contined inside text gen / chat gen | 8878 | // Default APIs not contined inside text gen / chat gen |
| 8878 | 'kobold': { | 8879 | 'kobold': { |
| 8879 | selected: 'kobold', | 8880 | selected: 'kobold', |
| @@ -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'; | |||
| 58 | import { oai_settings } from './openai.js'; | 60 | import { oai_settings } from './openai.js'; |
| 59 | import { callGenericPopup, Popup, POPUP_RESULT, POPUP_TYPE } from './popup.js'; | 61 | import { callGenericPopup, Popup, POPUP_RESULT, POPUP_TYPE } from './popup.js'; |
| 60 | import { power_user, registerDebugFunction } from './power-user.js'; | 62 | import { power_user, registerDebugFunction } from './power-user.js'; |
| 63 | import { getPresetManager } from './preset-manager.js'; | ||
| 61 | import { humanizedDateTime, isMobile, shouldSendOnEnter } from './RossAscends-mods.js'; | 64 | import { humanizedDateTime, isMobile, shouldSendOnEnter } from './RossAscends-mods.js'; |
| 62 | import { ScraperManager } from './scrapers.js'; | 65 | import { ScraperManager } from './scrapers.js'; |
| 63 | import { executeSlashCommands, executeSlashCommandsWithOptions, registerSlashCommand } from './slash-commands.js'; | 66 | import { executeSlashCommands, executeSlashCommandsWithOptions, registerSlashCommand } from './slash-commands.js'; |
| @@ -65,7 +68,7 @@ import { SlashCommand } from './slash-commands/SlashCommand.js'; | |||
| 65 | import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js'; | 68 | import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js'; |
| 66 | import { SlashCommandParser } from './slash-commands/SlashCommandParser.js'; | 69 | import { SlashCommandParser } from './slash-commands/SlashCommandParser.js'; |
| 67 | import { tag_map, tags } from './tags.js'; | 70 | import { tag_map, tags } from './tags.js'; |
| 68 | import { textgenerationwebui_settings } from './textgen-settings.js'; | 71 | import { getTextGenServer, textgenerationwebui_settings } from './textgen-settings.js'; |
| 69 | import { tokenizers, getTextTokens, getTokenCount, getTokenCountAsync, getTokenizerModel } from './tokenizers.js'; | 72 | import { tokenizers, getTextTokens, getTokenCount, getTokenCountAsync, getTokenizerModel } from './tokenizers.js'; |
| 70 | import { ToolManager } from './tool-calling.js'; | 73 | import { ToolManager } from './tool-calling.js'; |
| 71 | import { accountStorage } from './util/AccountStorage.js'; | 74 | import { 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 | } |
| 198 | 205 | ||
| @@ -318,8 +318,14 @@ export function validateTextGenUrl() { | |||
| 318 | control.val(formattedUrl); | 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 | 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 | } |
| 339 | 345 | ||
| @@ -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 | } |
| 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 | return 5; | 1232 | return 5; |
| 1221 | } | 1233 | } |
| 1222 | 1234 | ||
| @@ -1228,7 +1240,7 @@ function getLogprobsNumber() { | |||
| 1228 | * @param {string} str Input string | 1240 | * @param {string} str Input string |
| 1229 | * @returns {string} Output string | 1241 | * @returns {string} Output string |
| 1230 | */ | 1242 | */ |
| 1231 | function replaceMacrosInList(str) { | 1243 | export function replaceMacrosInList(str) { |
| 1232 | if (!str || typeof str !== 'string') { | 1244 | if (!str || typeof str !== 'string') { |
| 1233 | return str; | 1245 | return str; |
| 1234 | } | 1246 | } |