Move Horde status check to respective module

8449b4bb276e1f396df2b068cfadd5b84b7aee4f

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

2 files changed, +33 -34Showing whitespace changes
public/script.js+2 -22
@@ -137,9 +137,10 @@ import {
137137 horde_settings,
138138 loadHordeSettings,
139139 generateHorde,
140140 checkHordeStatusgetStatusHorde,
141141 getHordeModels,
142142 adjustHordeGenerationParams,
143+ isHordeGenerationNotAllowed,
143144 MIN_LENGTH,
144145 initHorde,
145146} from './scripts/horde.js';
@@ -961,18 +962,6 @@ export function setActiveGroup(entityOrKey) {
961962 if (active_group) active_character = null;
962963}
963964
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-
976965export function startStatusLoading() {
977966 $('.api_loading').show();
978967 $('.api_button').addClass('disabled');
@@ -8192,15 +8181,6 @@ export function setGenerationProgress(progress) {
81928181 }
81938182}
81948183
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-
82048184export function cancelTtsPlay() {
82058185 if ('speechSynthesis' in window) {
82068186 speechSynthesis.cancel();
public/scripts/horde.js+31 -12
@@ -1,9 +1,12 @@
11import {
22 amount_gen,
33 getRequestHeaders,
4+ main_api,
45 max_context,
6+ resultCheckStatus,
57 saveSettingsDebounced,
68 setGenerationProgress,
9+ setOnlineStatus,
710} from '../script.js';
811import { SECRET_KEYS, writeSecret } from './secrets.js';
912import { delay } from './utils.js';
@@ -11,20 +14,15 @@ import { isMobile } from './RossAscends-mods.js';
1114import { autoSelectInstructPreset } from './instruct-mode.js';
1215import { t } from './i18n.js';
1316import { callGenericPopup, POPUP_TYPE } from './popup.js';
17+import { kai_settings } from './kai-settings.js';
1418
1519export {
16- horde_settings,
17- generateHorde,
18- checkHordeStatus,
19- loadHordeSettings,
20- adjustHordeGenerationParams,
21- getHordeModels,
2220 MIN_LENGTH,
2321};
2422
2523let models = [];
2624
2725export let horde_settings = {
2826 models: [],
2927 auto_adjust_response_length: true,
3028 auto_adjust_context_length: false,
@@ -105,7 +103,7 @@ async function cancelTask(taskId) {
105103 * Checks if Horde is online.
106104 * @returns {Promise<boolean>} True if Horde is online, false otherwise
107105 */
108106export async function checkHordeStatus() {
109107 try {
110108 const response = await fetch('/api/horde/status', {
111109 method: 'POST',
@@ -124,6 +122,18 @@ async function checkHordeStatus() {
124122 }
125123}
126124
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+
127137function validateHordeModel() {
128138 let selectedModels = models.filter(m => horde_settings.models.includes(m.name));
129139
@@ -135,7 +145,7 @@ function validateHordeModel() {
135145 return selectedModels;
136146}
137147
138148export async function adjustHordeGenerationParams(max_context_length, max_length) {
139149 console.log(max_context_length, max_length);
140150 const workers = await getWorkers(false);
141151 let maxContextLength = max_context_length;
@@ -190,7 +200,7 @@ function setContextSizePreview() {
190200 * @returns {Promise<{text: *, workerName: string}>}
191201 * @throws {Error}
192202 */
193203export async function generateHorde(prompt, params, signal, reportProgress) {
194204 validateHordeModel();
195205 delete params.prompt;
196206
@@ -280,7 +290,7 @@ async function generateHorde(prompt, params, signal, reportProgress) {
280290 * Displays the available models in the Horde model selection dropdown.
281291 * @param {boolean} force Force refresh of the models
282292 */
283293export async function getHordeModels(force) {
284294 const sortByPerformance = (a, b) => b.performance - a.performance;
285295 const sortByWhitelisted = (a, b) => b.is_whitelisted - a.is_whitelisted;
286296 const sortByPopular = (a, b) => b.tags?.includes('popular') - a.tags?.includes('popular');
@@ -305,7 +315,7 @@ async function getHordeModels(force) {
305315 setContextSizePreview();
306316}
307317
308318export function loadHordeSettings(settings) {
309319 if (settings.horde_settings) {
310320 Object.assign(horde_settings, settings.horde_settings);
311321 }
@@ -346,6 +356,15 @@ function hordeModelQueueStateString(model) {
346356 return `ETA: ${model.eta}s, Speed: ${model.performance}, Queue: ${model.queued}, Workers: ${model.count}`;
347357}
348358
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+
349368function getHordeModelTemplate(option) {
350369 const model = models.find(x => x.name === option?.element?.value);
351370