Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit b6c05d8

Browse files
committed
fix: remove model also remove yaml file
1 parent f7284c5 commit b6c05d8

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

cortex-js/src/infrastructure/commanders/usecases/models.cli.usecases.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ export class ModelsCliUsecases {
180180
* @param modelId
181181
*/
182182
async pullModel(modelId: string) {
183+
if (await this.modelsUsecases.findOne(modelId)) {
184+
console.error('Model already exists');
185+
process.exit(1);
186+
}
187+
183188
if (modelId.includes('/') || modelId.includes(':')) {
184189
await this.pullHuggingFaceModel(modelId);
185190
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export const normalizeModelId = (modelId: string): string => {
2-
return modelId.replace(':', '-');
2+
return modelId.replace(':', '-').replace('/', '-');
33
};

cortex-js/src/infrastructure/repositories/model/model.repository.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
mkdirSync,
99
readFileSync,
1010
readdirSync,
11+
rmSync,
1112
writeFileSync,
1213
} from 'fs';
1314
import { load, dump } from 'js-yaml';
@@ -103,8 +104,13 @@ export class ModelRepositoryImpl implements ModelRepository {
103104
* This would remove the model yaml file from the models folder
104105
* @param id model id
105106
*/
106-
remove(id: string): Promise<void> {
107+
async remove(id: string): Promise<void> {
107108
this.models.delete(id);
109+
const yamlFilePath = join(
110+
await this.fileService.getModelsPath(),
111+
this.fileModel.get(id) ?? id,
112+
);
113+
if (existsSync(yamlFilePath)) rmSync(yamlFilePath);
108114
return Promise.resolve();
109115
}
110116

0 commit comments

Comments
 (0)