Move Horde status check to respective module
| @@ -137,9 +137,10 @@ import { | |||
| 137 | horde_settings, | 137 | horde_settings, |
| 138 | loadHordeSettings, | 138 | loadHordeSettings, |
| 139 | generateHorde, | 139 | generateHorde, |
| 140 | checkHordeStatus, | 140 | getStatusHorde, |
| 141 | getHordeModels, | 141 | getHordeModels, |
| 142 | adjustHordeGenerationParams, | 142 | adjustHordeGenerationParams, |
| 143 | isHordeGenerationNotAllowed, | ||
| 143 | MIN_LENGTH, | 144 | MIN_LENGTH, |
| 144 | initHorde, | 145 | initHorde, |
| 145 | } from './scripts/horde.js'; | 146 | } from './scripts/horde.js'; |
| @@ -961,18 +962,6 @@ export function setActiveGroup(entityOrKey) { | |||
| 961 | if (active_group) active_character = null; | 962 | if (active_group) active_character = null; |
| 962 | } | 963 | } |
| 963 | 964 | ||
| 964 | async function getStatusHorde() { | ||
| 965 | try { | ||
| 966 | const hordeStatus = await checkHordeStatus(); | ||
| 967 | setOnlineStatus(hordeStatus ? t`Connected` : 'no_connection'); | ||
| 968 | } | ||
| 969 | catch { | ||
| 970 | setOnlineStatus('no_connection'); | ||
| 971 | } | ||
| 972 | |||
| 973 | return resultCheckStatus(); | ||
| 974 | } | ||
| 975 | |||
| 976 | export function startStatusLoading() { | 965 | export function startStatusLoading() { |
| 977 | $('.api_loading').show(); | 966 | $('.api_loading').show(); |
| 978 | $('.api_button').addClass('disabled'); | 967 | $('.api_button').addClass('disabled'); |
| @@ -8192,15 +8181,6 @@ export function setGenerationProgress(progress) { | |||
| 8192 | } | 8181 | } |
| 8193 | } | 8182 | } |
| 8194 | 8183 | ||
| 8195 | function isHordeGenerationNotAllowed() { | ||
| 8196 | if (main_api == 'koboldhorde' && kai_settings.preset_settings == 'gui') { | ||
| 8197 | toastr.error(t`GUI Settings preset is not supported for Horde. Please select another preset.`); | ||
| 8198 | return true; | ||
| 8199 | } | ||
| 8200 | |||
| 8201 | return false; | ||
| 8202 | } | ||
| 8203 | |||
| 8204 | export function cancelTtsPlay() { | 8184 | export function cancelTtsPlay() { |
| 8205 | if ('speechSynthesis' in window) { | 8185 | if ('speechSynthesis' in window) { |
| 8206 | speechSynthesis.cancel(); | 8186 | speechSynthesis.cancel(); |
| @@ -1,9 +1,12 @@ | |||
| 1 | import { | 1 | import { |
| 2 | amount_gen, | 2 | amount_gen, |
| 3 | getRequestHeaders, | 3 | getRequestHeaders, |
| 4 | main_api, | ||
| 4 | max_context, | 5 | max_context, |
| 6 | resultCheckStatus, | ||
| 5 | saveSettingsDebounced, | 7 | saveSettingsDebounced, |
| 6 | setGenerationProgress, | 8 | setGenerationProgress, |
| 9 | setOnlineStatus, | ||
| 7 | } from '../script.js'; | 10 | } from '../script.js'; |
| 8 | import { SECRET_KEYS, writeSecret } from './secrets.js'; | 11 | import { SECRET_KEYS, writeSecret } from './secrets.js'; |
| 9 | import { delay } from './utils.js'; | 12 | import { delay } from './utils.js'; |
| @@ -11,20 +14,15 @@ import { isMobile } from './RossAscends-mods.js'; | |||
| 11 | import { autoSelectInstructPreset } from './instruct-mode.js'; | 14 | import { autoSelectInstructPreset } from './instruct-mode.js'; |
| 12 | import { t } from './i18n.js'; | 15 | import { t } from './i18n.js'; |
| 13 | import { callGenericPopup, POPUP_TYPE } from './popup.js'; | 16 | import { callGenericPopup, POPUP_TYPE } from './popup.js'; |
| 17 | import { kai_settings } from './kai-settings.js'; | ||
| 14 | 18 | ||
| 15 | export { | 19 | export { |
| 16 | horde_settings, | ||
| 17 | generateHorde, | ||
| 18 | checkHordeStatus, | ||
| 19 | loadHordeSettings, | ||
| 20 | adjustHordeGenerationParams, | ||
| 21 | getHordeModels, | ||
| 22 | MIN_LENGTH, | 20 | MIN_LENGTH, |
| 23 | }; | 21 | }; |
| 24 | 22 | ||
| 25 | let models = []; | 23 | let models = []; |
| 26 | 24 | ||
| 27 | let horde_settings = { | 25 | export let horde_settings = { |
| 28 | models: [], | 26 | models: [], |
| 29 | auto_adjust_response_length: true, | 27 | auto_adjust_response_length: true, |
| 30 | auto_adjust_context_length: false, | 28 | auto_adjust_context_length: false, |
| @@ -105,7 +103,7 @@ async function cancelTask(taskId) { | |||
| 105 | * Checks if Horde is online. | 103 | * Checks if Horde is online. |
| 106 | * @returns {Promise<boolean>} True if Horde is online, false otherwise | 104 | * @returns {Promise<boolean>} True if Horde is online, false otherwise |
| 107 | */ | 105 | */ |
| 108 | async function checkHordeStatus() { | 106 | export async function checkHordeStatus() { |
| 109 | try { | 107 | try { |
| 110 | const response = await fetch('/api/horde/status', { | 108 | const response = await fetch('/api/horde/status', { |
| 111 | method: 'POST', | 109 | method: 'POST', |
| @@ -124,6 +122,18 @@ async function checkHordeStatus() { | |||
| 124 | } | 122 | } |
| 125 | } | 123 | } |
| 126 | 124 | ||
| 125 | export async function getStatusHorde() { | ||
| 126 | try { | ||
| 127 | const hordeStatus = await checkHordeStatus(); | ||
| 128 | setOnlineStatus(hordeStatus ? t`Connected` : 'no_connection'); | ||
| 129 | } | ||
| 130 | catch { | ||
| 131 | setOnlineStatus('no_connection'); | ||
| 132 | } | ||
| 133 | |||
| 134 | return resultCheckStatus(); | ||
| 135 | } | ||
| 136 | |||
| 127 | function validateHordeModel() { | 137 | function validateHordeModel() { |
| 128 | let selectedModels = models.filter(m => horde_settings.models.includes(m.name)); | 138 | let selectedModels = models.filter(m => horde_settings.models.includes(m.name)); |
| 129 | 139 | ||
| @@ -135,7 +145,7 @@ function validateHordeModel() { | |||
| 135 | return selectedModels; | 145 | return selectedModels; |
| 136 | } | 146 | } |
| 137 | 147 | ||
| 138 | async function adjustHordeGenerationParams(max_context_length, max_length) { | 148 | export async function adjustHordeGenerationParams(max_context_length, max_length) { |
| 139 | console.log(max_context_length, max_length); | 149 | console.log(max_context_length, max_length); |
| 140 | const workers = await getWorkers(false); | 150 | const workers = await getWorkers(false); |
| 141 | let maxContextLength = max_context_length; | 151 | let maxContextLength = max_context_length; |
| @@ -190,7 +200,7 @@ function setContextSizePreview() { | |||
| 190 | * @returns {Promise<{text: *, workerName: string}>} | 200 | * @returns {Promise<{text: *, workerName: string}>} |
| 191 | * @throws {Error} | 201 | * @throws {Error} |
| 192 | */ | 202 | */ |
| 193 | async function generateHorde(prompt, params, signal, reportProgress) { | 203 | export async function generateHorde(prompt, params, signal, reportProgress) { |
| 194 | validateHordeModel(); | 204 | validateHordeModel(); |
| 195 | delete params.prompt; | 205 | delete params.prompt; |
| 196 | 206 | ||
| @@ -280,7 +290,7 @@ async function generateHorde(prompt, params, signal, reportProgress) { | |||
| 280 | * Displays the available models in the Horde model selection dropdown. | 290 | * Displays the available models in the Horde model selection dropdown. |
| 281 | * @param {boolean} force Force refresh of the models | 291 | * @param {boolean} force Force refresh of the models |
| 282 | */ | 292 | */ |
| 283 | async function getHordeModels(force) { | 293 | export async function getHordeModels(force) { |
| 284 | const sortByPerformance = (a, b) => b.performance - a.performance; | 294 | const sortByPerformance = (a, b) => b.performance - a.performance; |
| 285 | const sortByWhitelisted = (a, b) => b.is_whitelisted - a.is_whitelisted; | 295 | const sortByWhitelisted = (a, b) => b.is_whitelisted - a.is_whitelisted; |
| 286 | const sortByPopular = (a, b) => b.tags?.includes('popular') - a.tags?.includes('popular'); | 296 | const sortByPopular = (a, b) => b.tags?.includes('popular') - a.tags?.includes('popular'); |
| @@ -305,7 +315,7 @@ async function getHordeModels(force) { | |||
| 305 | setContextSizePreview(); | 315 | setContextSizePreview(); |
| 306 | } | 316 | } |
| 307 | 317 | ||
| 308 | function loadHordeSettings(settings) { | 318 | export function loadHordeSettings(settings) { |
| 309 | if (settings.horde_settings) { | 319 | if (settings.horde_settings) { |
| 310 | Object.assign(horde_settings, settings.horde_settings); | 320 | Object.assign(horde_settings, settings.horde_settings); |
| 311 | } | 321 | } |
| @@ -346,6 +356,15 @@ function hordeModelQueueStateString(model) { | |||
| 346 | return `ETA: ${model.eta}s, Speed: ${model.performance}, Queue: ${model.queued}, Workers: ${model.count}`; | 356 | return `ETA: ${model.eta}s, Speed: ${model.performance}, Queue: ${model.queued}, Workers: ${model.count}`; |
| 347 | } | 357 | } |
| 348 | 358 | ||
| 359 | export function isHordeGenerationNotAllowed() { | ||
| 360 | if (main_api == 'koboldhorde' && kai_settings.preset_settings == 'gui') { | ||
| 361 | toastr.error(t`GUI Settings preset is not supported for Horde. Please select another preset.`); | ||
| 362 | return true; | ||
| 363 | } | ||
| 364 | |||
| 365 | return false; | ||
| 366 | } | ||
| 367 | |||
| 349 | function getHordeModelTemplate(option) { | 368 | function getHordeModelTemplate(option) { |
| 350 | const model = models.find(x => x.name === option?.element?.value); | 369 | const model = models.find(x => x.name === option?.element?.value); |
| 351 | 370 | ||