Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { modelChanged } from 'features/parameters/store/generationSlice';
import { setActiveTab } from 'features/ui/store/uiSlice';
import { forEach } from 'lodash-es';
import { find, forEach } from 'lodash-es';
import { NON_REFINER_BASE_MODELS } from 'services/api/constants';
import {
MainModelConfigEntity,
Expand Down Expand Up @@ -37,17 +37,25 @@ export const addTabChangedListener = () => {
}
});

// this could still be undefined even tho TS doesn't say so
const firstValidCanvasModel = validCanvasModels[0];
// Check if current selected model exists on Canvas Models
const currentModel = find(
validCanvasModels,
(model) =>
model.model_name === getState().generation.model?.model_name
);

if (!firstValidCanvasModel) {
// If it does, set it or else set the first in list
const validModel = currentModel ? currentModel : validCanvasModels[0];

// Make sure the valid model exists. Can be undefined in some cases.
if (!validModel) {
// uh oh, we have no models that are valid for canvas
dispatch(modelChanged(null));
return;
}

// only store the model name and base model in redux
const { base_model, model_name, model_type } = firstValidCanvasModel;
const { base_model, model_name, model_type } = validModel;

dispatch(modelChanged({ base_model, model_name, model_type }));
}
Expand Down