Move Horde status check to respective module

8449b4bb276e1f396df2b068cfadd5b84b7aee4f

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +33 -34Ignore whitespace
public/script.js+2 -22
@@ -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}
963964
964async 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
976export function startStatusLoading() {965export 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}
81948183
8195function 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
8204export function cancelTtsPlay() {8184export function cancelTtsPlay() {
8205 if ('speechSynthesis' in window) {8185 if ('speechSynthesis' in window) {
8206 speechSynthesis.cancel();8186 speechSynthesis.cancel();
public/scripts/horde.js+31 -12
@@ -1,9 +1,12 @@
1import {1import {
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';
8import { SECRET_KEYS, writeSecret } from './secrets.js';11import { SECRET_KEYS, writeSecret } from './secrets.js';
9import { delay } from './utils.js';12import { delay } from './utils.js';
@@ -11,20 +14,15 @@ import { isMobile } from './RossAscends-mods.js';
11import { autoSelectInstructPreset } from './instruct-mode.js';14import { autoSelectInstructPreset } from './instruct-mode.js';
12import { t } from './i18n.js';15import { t } from './i18n.js';
13import { callGenericPopup, POPUP_TYPE } from './popup.js';16import { callGenericPopup, POPUP_TYPE } from './popup.js';
17import { kai_settings } from './kai-settings.js';
1418
15export {19export {
16 horde_settings,
17 generateHorde,
18 checkHordeStatus,
19 loadHordeSettings,
20 adjustHordeGenerationParams,
21 getHordeModels,
22 MIN_LENGTH,20 MIN_LENGTH,
23};21};
2422
25let models = [];23let models = [];
2624
27let horde_settings = {25export 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 otherwise104 * @returns {Promise<boolean>} True if Horde is online, false otherwise
107 */105 */
108async function checkHordeStatus() {106export 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}
126124
125export 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
127function validateHordeModel() {137function 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));
129139
@@ -135,7 +145,7 @@ function validateHordeModel() {
135 return selectedModels;145 return selectedModels;
136}146}
137147
138async function adjustHordeGenerationParams(max_context_length, max_length) {148export 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 */
193async function generateHorde(prompt, params, signal, reportProgress) {203export async function generateHorde(prompt, params, signal, reportProgress) {
194 validateHordeModel();204 validateHordeModel();
195 delete params.prompt;205 delete params.prompt;
196206
@@ -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 models291 * @param {boolean} force Force refresh of the models
282 */292 */
283async function getHordeModels(force) {293export 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}
307317
308function loadHordeSettings(settings) {318export 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}
348358
359export 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
349function getHordeModelTemplate(option) {368function getHordeModelTemplate(option) {
350 const model = models.find(x => x.name === option?.element?.value);369 const model = models.find(x => x.name === option?.element?.value);
351370