Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions cortex-js/src/domain/models/model.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const ModelLoadingEvents = [
'stopped',
'starting-failed',
'stopping-failed',
'model-downloaded',
'model-deleted',
] as const;
export type ModelLoadingEvent = (typeof ModelLoadingEvents)[number];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ export class ModelsController {
})
@Get('download/:modelId(*)')
downloadModel(@Param('modelId') modelId: string) {
return this.modelsUsecases.pullModel(modelId);
this.modelsUsecases.pullModel(modelId, false);

return {
message: 'Download model started successfully.',
};
}

@ApiOperation({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export class DownloadManagerService {
(downloadState) => downloadState.id !== downloadId,
);
}
this.eventEmitter.emit('download.event', this.allDownloadStates);
};
if (!inSequence) {
return Promise.all(
Expand Down Expand Up @@ -140,7 +141,7 @@ export class DownloadManagerService {
}

const writer = createWriteStream(destination);
const totalBytes = response.headers['content-length'];
const totalBytes = Number(response.headers['content-length']);

// update download state
const currentDownloadState = this.allDownloadStates.find(
Expand Down
15 changes: 15 additions & 0 deletions cortex-js/src/usecases/models/models.usecases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ export class ModelsUsecases {
existsSync(modelFolder) &&
rmdirSync(modelFolder, { recursive: true }),
)
.then(() => {
const modelEvent: ModelEvent = {
model: id,
event: 'model-deleted',
metadata: {},
};
this.eventEmitter.emit(modelEvent.event, modelEvent);
})
.then(() => {
return {
message: 'Model removed successfully',
Expand Down Expand Up @@ -342,6 +350,7 @@ export class ModelsUsecases {
const toDownloads: Record<string, string> = files
.filter((e) => this.validFileDownload(e))
.reduce((acc: Record<string, string>, file) => {
// @ts-expect-error ignore
acc[file.downloadUrl] = join(modelFolder, file.rfilename);
return acc;
}, {});
Expand Down Expand Up @@ -389,6 +398,12 @@ export class ModelsUsecases {
});
}
}
const modelEvent: ModelEvent = {
model: modelId,
event: 'model-downloaded',
metadata: {},
};
this.eventEmitter.emit(modelEvent.event, modelEvent);
},
inSequence,
);
Expand Down