fix: Revert scheduler back to zod validation

This commit is contained in:
blessedcoolant 2023-06-18 20:02:36 +12:00
parent 59b5dfc3e0
commit 06428fac67
4 changed files with 11 additions and 9 deletions

View File

@ -41,9 +41,9 @@ export const SCHEDULER_ITEMS = [
'heun',
'heun_k',
'unipc',
];
] as const;
export type Scheduler = typeof SCHEDULERS;
export type Scheduler = (typeof SCHEDULER_ITEMS)[number];
// Valid upscaling levels
export const UPSCALING_LEVELS: Array<{ label: string; value: string }> = [

View File

@ -1,4 +1,4 @@
import { SCHEDULER_ITEMS } from 'app/constants';
import { SCHEDULER_ITEMS, Scheduler } from 'app/constants';
import { RootState } from 'app/store/store';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import IAIMantineSelect from 'common/components/IAIMantineSelect';
@ -25,12 +25,13 @@ const ParamScheduler = () => {
useEffect(() => {
if (selectedSchedulers.length === 0)
dispatch(setSelectedSchedulers(SCHEDULER_ITEMS));
dispatch(setSelectedSchedulers([...SCHEDULER_ITEMS]));
const schedulerFound = activeSchedulers.find(
(activeSchedulers) => activeSchedulers.label === scheduler
);
if (!schedulerFound) dispatch(setScheduler(activeSchedulers[0].value));
if (!schedulerFound)
dispatch(setScheduler(activeSchedulers[0].value as Scheduler));
}, [dispatch, selectedSchedulers, scheduler, activeSchedulers]);
const handleChange = useCallback(
@ -38,7 +39,7 @@ const ParamScheduler = () => {
if (!v) {
return;
}
dispatch(setScheduler(v));
dispatch(setScheduler(v as Scheduler));
},
[dispatch]
);

View File

@ -1,5 +1,6 @@
import type { PayloadAction } from '@reduxjs/toolkit';
import { createSlice } from '@reduxjs/toolkit';
import { Scheduler } from 'app/constants';
import { configChanged } from 'features/system/store/configSlice';
import { clamp, sortBy } from 'lodash-es';
import { ImageDTO } from 'services/api';
@ -132,7 +133,7 @@ export const generationSlice = createSlice({
setWidth: (state, action: PayloadAction<number>) => {
state.width = action.payload;
},
setScheduler: (state, action: PayloadAction<string>) => {
setScheduler: (state, action: PayloadAction<Scheduler>) => {
state.scheduler = action.payload;
},
setSeed: (state, action: PayloadAction<number>) => {

View File

@ -1,4 +1,4 @@
import { NUMPY_RAND_MAX } from 'app/constants';
import { NUMPY_RAND_MAX, SCHEDULER_ITEMS } from 'app/constants';
import { z } from 'zod';
/**
@ -73,7 +73,7 @@ export const isValidCfgScale = (val: unknown): val is CfgScaleParam =>
/**
* Zod schema for scheduler parameter
*/
export const zScheduler = z.string();
export const zScheduler = z.enum(SCHEDULER_ITEMS);
/**
* Type alias for scheduler parameter, inferred from its zod schema
*/