feat: refactor model API structure to support specific model types with dedicated API clients for Checkpoints, LoRAs, and Embeddings

refactor: consolidate model API client creation into a factory function for better maintainability
feat: implement move operations for LoRAs and handle unsupported operations for Checkpoints and Embeddings
This commit is contained in:
Will Miao
2025-08-04 19:37:53 +08:00
parent 65ec6aacb7
commit 342a722991
29 changed files with 341 additions and 213 deletions

View File

@@ -0,0 +1,35 @@
import { LoraApiClient } from './loraApi.js';
import { CheckpointApiClient } from './checkpointApi.js';
import { EmbeddingApiClient } from './embeddingApi.js';
import { MODEL_TYPES } from './apiConfig.js';
import { state } from '../state/index.js';
export function createModelApiClient(modelType) {
switch (modelType) {
case MODEL_TYPES.LORA:
return new LoraApiClient();
case MODEL_TYPES.CHECKPOINT:
return new CheckpointApiClient();
case MODEL_TYPES.EMBEDDING:
return new EmbeddingApiClient();
default:
throw new Error(`Unsupported model type: ${modelType}`);
}
}
let _singletonClient = null;
export function getModelApiClient() {
const currentType = state.currentPageType;
if (!_singletonClient || _singletonClient.modelType !== currentType) {
_singletonClient = createModelApiClient(currentType);
}
return _singletonClient;
}
export function resetAndReload(updateFolders = false) {
const client = getModelApiClient();
return client.loadMoreWithVirtualScroll(true, updateFolders);
}