Move Horde status check to respective module
| @@ -137,9 +137,10 @@ import { | ||
| 137 | 137 | horde_settings, |
| 138 | 138 | loadHordeSettings, |
| 139 | 139 | generateHorde, |
| 140 | 140 | checkHordeStatusgetStatusHorde, |
| 141 | 141 | getHordeModels, |
| 142 | 142 | adjustHordeGenerationParams, |
| 143 | + isHordeGenerationNotAllowed, | |
| 143 | 144 | MIN_LENGTH, |
| 144 | 145 | initHorde, |
| 145 | 146 | } from './scripts/horde.js'; |
| @@ -961,18 +962,6 @@ export function setActiveGroup(entityOrKey) { | ||
| 961 | 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 | 965 | export function startStatusLoading() { |
| 977 | 966 | $('.api_loading').show(); |
| 978 | 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 | 8184 | export function cancelTtsPlay() { |
| 8205 | 8185 | if ('speechSynthesis' in window) { |
| 8206 | 8186 | speechSynthesis.cancel(); |
| @@ -1,9 +1,12 @@ | ||
| 1 | 1 | import { |
| 2 | 2 | amount_gen, |
| 3 | 3 | getRequestHeaders, |
| 4 | + main_api, | |
| 4 | 5 | max_context, |
| 6 | + resultCheckStatus, | |
| 5 | 7 | saveSettingsDebounced, |
| 6 | 8 | setGenerationProgress, |
| 9 | + setOnlineStatus, | |
| 7 | 10 | } from '../script.js'; |
| 8 | 11 | import { SECRET_KEYS, writeSecret } from './secrets.js'; |
| 9 | 12 | import { delay } from './utils.js'; |
| @@ -11,20 +14,15 @@ import { isMobile } from './RossAscends-mods.js'; | ||
| 11 | 14 | import { autoSelectInstructPreset } from './instruct-mode.js'; |
| 12 | 15 | import { t } from './i18n.js'; |
| 13 | 16 | import { callGenericPopup, POPUP_TYPE } from './popup.js'; |
| 17 | +import { kai_settings } from './kai-settings.js'; | |
| 14 | 18 | |
| 15 | 19 | export { |
| 16 | - horde_settings, | |
| 17 | - generateHorde, | |
| 18 | - checkHordeStatus, | |
| 19 | - loadHordeSettings, | |
| 20 | - adjustHordeGenerationParams, | |
| 21 | - getHordeModels, | |
| 22 | 20 | MIN_LENGTH, |
| 23 | 21 | }; |
| 24 | 22 | |
| 25 | 23 | let models = []; |
| 26 | 24 | |
| 27 | 25 | export let horde_settings = { |
| 28 | 26 | models: [], |
| 29 | 27 | auto_adjust_response_length: true, |
| 30 | 28 | auto_adjust_context_length: false, |
| @@ -105,7 +103,7 @@ async function cancelTask(taskId) { | ||
| 105 | 103 | * Checks if Horde is online. |
| 106 | 104 | * @returns {Promise<boolean>} True if Horde is online, false otherwise |
| 107 | 105 | */ |
| 108 | 106 | export async function checkHordeStatus() { |
| 109 | 107 | try { |
| 110 | 108 | const response = await fetch('/api/horde/status', { |
| 111 | 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 | 137 | function validateHordeModel() { |
| 128 | 138 | let selectedModels = models.filter(m => horde_settings.models.includes(m.name)); |
| 129 | 139 | |
| @@ -135,7 +145,7 @@ function validateHordeModel() { | ||
| 135 | 145 | return selectedModels; |
| 136 | 146 | } |
| 137 | 147 | |
| 138 | 148 | export async function adjustHordeGenerationParams(max_context_length, max_length) { |
| 139 | 149 | console.log(max_context_length, max_length); |
| 140 | 150 | const workers = await getWorkers(false); |
| 141 | 151 | let maxContextLength = max_context_length; |
| @@ -190,7 +200,7 @@ function setContextSizePreview() { | ||
| 190 | 200 | * @returns {Promise<{text: *, workerName: string}>} |
| 191 | 201 | * @throws {Error} |
| 192 | 202 | */ |
| 193 | 203 | export async function generateHorde(prompt, params, signal, reportProgress) { |
| 194 | 204 | validateHordeModel(); |
| 195 | 205 | delete params.prompt; |
| 196 | 206 | |
| @@ -280,7 +290,7 @@ async function generateHorde(prompt, params, signal, reportProgress) { | ||
| 280 | 290 | * Displays the available models in the Horde model selection dropdown. |
| 281 | 291 | * @param {boolean} force Force refresh of the models |
| 282 | 292 | */ |
| 283 | 293 | export async function getHordeModels(force) { |
| 284 | 294 | const sortByPerformance = (a, b) => b.performance - a.performance; |
| 285 | 295 | const sortByWhitelisted = (a, b) => b.is_whitelisted - a.is_whitelisted; |
| 286 | 296 | const sortByPopular = (a, b) => b.tags?.includes('popular') - a.tags?.includes('popular'); |
| @@ -305,7 +315,7 @@ async function getHordeModels(force) { | ||
| 305 | 315 | setContextSizePreview(); |
| 306 | 316 | } |
| 307 | 317 | |
| 308 | 318 | export function loadHordeSettings(settings) { |
| 309 | 319 | if (settings.horde_settings) { |
| 310 | 320 | Object.assign(horde_settings, settings.horde_settings); |
| 311 | 321 | } |
| @@ -346,6 +356,15 @@ function hordeModelQueueStateString(model) { | ||
| 346 | 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 | 368 | function getHordeModelTemplate(option) { |
| 350 | 369 | const model = models.find(x => x.name === option?.element?.value); |
| 351 | 370 | |