fix(ui): use revised metadata model types

We can also totally remove the fetch logic because we store the same model data in state now.
This commit is contained in:
psychedelicious 2024-03-14 10:32:04 +11:00
parent 437a413ca3
commit 4c417adc82
6 changed files with 17 additions and 39 deletions

View File

@ -1,16 +1,14 @@
import type { RootState } from 'app/store/store'; import type { RootState } from 'app/store/store';
import { selectValidControlNets } from 'features/controlAdapters/store/controlAdaptersSlice'; import { selectValidControlNets } from 'features/controlAdapters/store/controlAdaptersSlice';
import { fetchModelConfigWithTypeGuard } from 'features/metadata/util/modelFetchingHelpers';
import type { import type {
CollectInvocation, CollectInvocation,
ControlNetInvocation, ControlNetInvocation,
CoreMetadataInvocation, CoreMetadataInvocation,
NonNullableGraph, NonNullableGraph,
} from 'services/api/types'; } from 'services/api/types';
import { isControlNetModelConfig } from 'services/api/types';
import { CONTROL_NET_COLLECT } from './constants'; import { CONTROL_NET_COLLECT } from './constants';
import { getModelMetadataField, upsertMetadata } from './metadata'; import { upsertMetadata } from './metadata';
export const addControlNetToLinearGraph = async ( export const addControlNetToLinearGraph = async (
state: RootState, state: RootState,
@ -27,10 +25,6 @@ export const addControlNetToLinearGraph = async (
} }
); );
// const metadataAccumulator = graph.nodes[METADATA_ACCUMULATOR] as
// | MetadataAccumulatorInvocation
// | undefined;
const controlNetMetadata: CoreMetadataInvocation['controlnets'] = []; const controlNetMetadata: CoreMetadataInvocation['controlnets'] = [];
if (validControlNets.length) { if (validControlNets.length) {
@ -95,10 +89,8 @@ export const addControlNetToLinearGraph = async (
graph.nodes[controlNetNode.id] = controlNetNode as ControlNetInvocation; graph.nodes[controlNetNode.id] = controlNetNode as ControlNetInvocation;
const modelConfig = await fetchModelConfigWithTypeGuard(model.key, isControlNetModelConfig);
controlNetMetadata.push({ controlNetMetadata.push({
control_model: getModelMetadataField(modelConfig), control_model: model,
control_weight: weight, control_weight: weight,
control_mode: controlMode, control_mode: controlMode,
begin_step_percent: beginStepPct, begin_step_percent: beginStepPct,

View File

@ -1,16 +1,14 @@
import type { RootState } from 'app/store/store'; import type { RootState } from 'app/store/store';
import { selectValidIPAdapters } from 'features/controlAdapters/store/controlAdaptersSlice'; import { selectValidIPAdapters } from 'features/controlAdapters/store/controlAdaptersSlice';
import { fetchModelConfigWithTypeGuard } from 'features/metadata/util/modelFetchingHelpers';
import type { import type {
CollectInvocation, CollectInvocation,
CoreMetadataInvocation, CoreMetadataInvocation,
IPAdapterInvocation, IPAdapterInvocation,
NonNullableGraph, NonNullableGraph,
} from 'services/api/types'; } from 'services/api/types';
import { isIPAdapterModelConfig } from 'services/api/types';
import { IP_ADAPTER_COLLECT } from './constants'; import { IP_ADAPTER_COLLECT } from './constants';
import { getModelMetadataField, upsertMetadata } from './metadata'; import { upsertMetadata } from './metadata';
export const addIPAdapterToLinearGraph = async ( export const addIPAdapterToLinearGraph = async (
state: RootState, state: RootState,
@ -67,11 +65,9 @@ export const addIPAdapterToLinearGraph = async (
graph.nodes[ipAdapterNode.id] = ipAdapterNode; graph.nodes[ipAdapterNode.id] = ipAdapterNode;
const modelConfig = await fetchModelConfigWithTypeGuard(model.key, isIPAdapterModelConfig);
ipAdapterMetdata.push({ ipAdapterMetdata.push({
weight: weight, weight: weight,
ip_adapter_model: getModelMetadataField(modelConfig), ip_adapter_model: model,
begin_step_percent: beginStepPct, begin_step_percent: beginStepPct,
end_step_percent: endStepPct, end_step_percent: endStepPct,
image: ipAdapterNode.image, image: ipAdapterNode.image,

View File

@ -1,16 +1,14 @@
import type { RootState } from 'app/store/store'; import type { RootState } from 'app/store/store';
import { selectValidT2IAdapters } from 'features/controlAdapters/store/controlAdaptersSlice'; import { selectValidT2IAdapters } from 'features/controlAdapters/store/controlAdaptersSlice';
import { fetchModelConfigWithTypeGuard } from 'features/metadata/util/modelFetchingHelpers'; import type {
import { CollectInvocation,
type CollectInvocation, CoreMetadataInvocation,
type CoreMetadataInvocation, NonNullableGraph,
isT2IAdapterModelConfig, T2IAdapterInvocation,
type NonNullableGraph,
type T2IAdapterInvocation,
} from 'services/api/types'; } from 'services/api/types';
import { T2I_ADAPTER_COLLECT } from './constants'; import { T2I_ADAPTER_COLLECT } from './constants';
import { getModelMetadataField, upsertMetadata } from './metadata'; import { upsertMetadata } from './metadata';
export const addT2IAdaptersToLinearGraph = async ( export const addT2IAdaptersToLinearGraph = async (
state: RootState, state: RootState,
@ -89,13 +87,11 @@ export const addT2IAdaptersToLinearGraph = async (
graph.nodes[t2iAdapterNode.id] = t2iAdapterNode; graph.nodes[t2iAdapterNode.id] = t2iAdapterNode;
const modelConfig = await fetchModelConfigWithTypeGuard(t2iAdapter.model.key, isT2IAdapterModelConfig);
t2iAdapterMetadata.push({ t2iAdapterMetadata.push({
begin_step_percent: beginStepPct, begin_step_percent: beginStepPct,
end_step_percent: endStepPct, end_step_percent: endStepPct,
resize_mode: resizeMode, resize_mode: resizeMode,
t2i_adapter_model: getModelMetadataField(modelConfig), t2i_adapter_model: t2iAdapter.model,
weight: weight, weight: weight,
image: t2iAdapterNode.image, image: t2iAdapterNode.image,
}); });

View File

@ -1,7 +1,5 @@
import type { RootState } from 'app/store/store'; import type { RootState } from 'app/store/store';
import { fetchModelConfigWithTypeGuard } from 'features/metadata/util/modelFetchingHelpers'; import type { NonNullableGraph } from 'services/api/types';
import type { ModelMetadataField, NonNullableGraph } from 'services/api/types';
import { isVAEModelConfig } from 'services/api/types';
import { import {
CANVAS_IMAGE_TO_IMAGE_GRAPH, CANVAS_IMAGE_TO_IMAGE_GRAPH,
@ -25,7 +23,7 @@ import {
TEXT_TO_IMAGE_GRAPH, TEXT_TO_IMAGE_GRAPH,
VAE_LOADER, VAE_LOADER,
} from './constants'; } from './constants';
import { getModelMetadataField, upsertMetadata } from './metadata'; import { upsertMetadata } from './metadata';
export const addVAEToGraph = async ( export const addVAEToGraph = async (
state: RootState, state: RootState,
@ -151,8 +149,6 @@ export const addVAEToGraph = async (
} }
if (vae) { if (vae) {
const modelConfig = await fetchModelConfigWithTypeGuard(vae.key, isVAEModelConfig); upsertMetadata(graph, { vae });
const vaeMetadata: ModelMetadataField = getModelMetadataField(modelConfig);
upsertMetadata(graph, { vae: vaeMetadata });
} }
}; };

View File

@ -1,5 +1,6 @@
import type { JSONObject } from 'common/types'; import type { JSONObject } from 'common/types';
import type { AnyModelConfig, CoreMetadataInvocation, ModelMetadataField, NonNullableGraph } from 'services/api/types'; import type { ModelIdentifierField } from 'features/nodes/types/common';
import type { AnyModelConfig, CoreMetadataInvocation, NonNullableGraph } from 'services/api/types';
import { METADATA } from './constants'; import { METADATA } from './constants';
@ -72,7 +73,7 @@ export const setMetadataReceivingNode = (graph: NonNullableGraph, nodeId: string
}); });
}; };
export const getModelMetadataField = ({ key, hash, name, base, type }: AnyModelConfig): ModelMetadataField => ({ export const getModelMetadataField = ({ key, hash, name, base, type }: AnyModelConfig): ModelIdentifierField => ({
key, key,
hash, hash,
name, name,

View File

@ -141,9 +141,6 @@ export type ImageWatermarkInvocation = S['ImageWatermarkInvocation'];
export type SeamlessModeInvocation = S['SeamlessModeInvocation']; export type SeamlessModeInvocation = S['SeamlessModeInvocation'];
export type CoreMetadataInvocation = S['CoreMetadataInvocation']; export type CoreMetadataInvocation = S['CoreMetadataInvocation'];
// Metadata fields
export type ModelMetadataField = S['ModelMetadataField'];
// ControlNet Nodes // ControlNet Nodes
export type ControlNetInvocation = S['ControlNetInvocation']; export type ControlNetInvocation = S['ControlNetInvocation'];
export type T2IAdapterInvocation = S['T2IAdapterInvocation']; export type T2IAdapterInvocation = S['T2IAdapterInvocation'];