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

Commit dc1c170

Browse files
committed
chore: remove duplicated model pull function
1 parent 2adee26 commit dc1c170

File tree

2 files changed

+5
-66
lines changed

2 files changed

+5
-66
lines changed

cortex-js/src/infrastructure/commanders/models/model-pull.command.ts

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { CommandRunner, InquirerService, SubCommand } from 'nest-commander';
22
import { exit } from 'node:process';
33
import { ModelsCliUsecases } from '../usecases/models.cli.usecases';
44
import { RepoDesignation, listFiles } from '@huggingface/hub';
5-
import { basename } from 'node:path';
65

76
@SubCommand({
87
name: 'pull',
@@ -29,12 +28,9 @@ export class ModelPullCommand extends CommandRunner {
2928
? undefined
3029
: await this.tryToGetBranches(input[0]);
3130

32-
if (!branches) {
33-
await this.modelsCliUsecases.pullModel(input[0]);
34-
} else {
35-
// if there's metadata.yaml file, we assumed it's a JanHQ model
36-
await this.handleJanHqModel(input[0], branches);
37-
}
31+
await this.modelsCliUsecases.pullModel(
32+
!branches ? input[0] : await this.handleJanHqModel(input[0], branches),
33+
);
3834

3935
console.log('\nDownload complete!');
4036
exit(0);
@@ -83,10 +79,6 @@ export class ModelPullCommand extends CommandRunner {
8379
}
8480

8581
private async handleJanHqModel(repoName: string, branches: string[]) {
86-
const sanitizedRepoName = repoName.trim().startsWith(this.janHqModelPrefix)
87-
? repoName
88-
: `${this.janHqModelPrefix}/${repoName}`;
89-
9082
let selectedTag = branches[0];
9183

9284
if (branches.length > 1) {
@@ -98,27 +90,7 @@ export class ModelPullCommand extends CommandRunner {
9890
console.error("Can't find model revision.");
9991
exit(1);
10092
}
101-
102-
const repo: RepoDesignation = { type: 'model', name: sanitizedRepoName };
103-
let ggufUrl: string | undefined = undefined;
104-
for await (const fileInfo of listFiles({
105-
repo: repo,
106-
revision: revision,
107-
})) {
108-
if (fileInfo.path.endsWith('.gguf')) {
109-
ggufUrl = `https://huggingface.co/${sanitizedRepoName}/resolve/${revision}/${fileInfo.path}`;
110-
break;
111-
}
112-
}
113-
114-
if (!ggufUrl) {
115-
console.error("Can't find model file.");
116-
exit(1);
117-
}
118-
console.log('Downloading', basename(ggufUrl));
119-
await this.modelsCliUsecases.pullModelWithExactUrl(
120-
`${sanitizedRepoName}/${revision}`,
121-
ggufUrl,
122-
);
93+
// Return parsed model Id
94+
return `${repoName}:${revision}`;
12395
}
12496
}

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

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -142,39 +142,6 @@ export class ModelsCliUsecases {
142142
return this.modelsUsecases.remove(modelId);
143143
}
144144

145-
async pullModelWithExactUrl(modelId: string, url: string) {
146-
const tokenizer = await this.getHFModelTokenizer(url);
147-
const promptTemplate = tokenizer?.promptTemplate ?? LLAMA_2;
148-
const stopWords: string[] = [tokenizer?.stopWord ?? ''];
149-
150-
const model: CreateModelDto = {
151-
files: [url],
152-
model: modelId,
153-
name: modelId,
154-
prompt_template: promptTemplate,
155-
156-
stop: stopWords,
157-
158-
engine: 'cortex.llamacpp',
159-
};
160-
if (!(await this.modelsUsecases.findOne(modelId))) {
161-
await this.modelsUsecases.create(model);
162-
}
163-
164-
const bar = new SingleBar({}, Presets.shades_classic);
165-
bar.start(100, 0);
166-
const callback = (progress: number) => {
167-
bar.update(progress);
168-
};
169-
await this.modelsUsecases.downloadModel(modelId, callback);
170-
const fileUrl = join(
171-
await this.fileService.getModelsPath(),
172-
normalizeModelId(modelId),
173-
basename(url),
174-
);
175-
await this.modelsUsecases.update(modelId, { files: [fileUrl] });
176-
}
177-
178145
/**
179146
* Pull model from Model repository (HF, Jan...)
180147
* @param modelId

0 commit comments

Comments
 (0)