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

Commit e4ed6cd

Browse files
committed
fix: get metadata for selected quantization only
1 parent cf35eec commit e4ed6cd

File tree

3 files changed

+22
-26
lines changed

3 files changed

+22
-26
lines changed

cortex-js/src/domain/models/huggingface.interface.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export interface HuggingFaceRepoData {
1717
downloadUrl?: string;
1818
fileSize?: number;
1919
quantization?: Quantization;
20-
stopWord?: string;
2120
}[];
2221
createdAt: string;
2322
}

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { CommandRunner, SubCommand } from 'nest-commander';
2-
import { Presets, SingleBar } from 'cli-progress';
32
import { exit } from 'node:process';
43
import { ModelsCliUsecases } from '../usecases/models.cli.usecases';
54

@@ -19,12 +18,7 @@ export class ModelPullCommand extends CommandRunner {
1918
exit(1);
2019
}
2120

22-
const bar = new SingleBar({}, Presets.shades_classic);
23-
bar.start(100, 0);
24-
const callback = (progress: number) => {
25-
bar.update(progress);
26-
};
27-
await this.modelsCliUsecases.pullModel(input[0], callback);
21+
await this.modelsCliUsecases.pullModel(input[0]);
2822
console.log('\nDownload complete!');
2923
exit(0);
3024
}

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

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { HuggingFaceRepoData } from '@/domain/models/huggingface.interface';
66
import { gguf } from '@huggingface/gguf';
77
import { InquirerService } from 'nest-commander';
88
import { Inject, Injectable } from '@nestjs/common';
9+
import { Presets, SingleBar } from 'cli-progress';
910

1011
const AllQuantizations = [
1112
'Q3_K_S',
@@ -71,11 +72,16 @@ export class ModelsCliUsecases {
7172
return this.modelsUsecases.remove(modelId);
7273
}
7374

74-
async pullModel(modelId: string, callback: (progress: number) => void) {
75+
async pullModel(modelId: string) {
7576
if (modelId.includes('/')) {
7677
await this.pullHuggingFaceModel(modelId);
7778
}
7879

80+
const bar = new SingleBar({}, Presets.shades_classic);
81+
bar.start(100, 0);
82+
const callback = (progress: number) => {
83+
bar.update(progress);
84+
};
7985
await this.modelsUsecases.downloadModel(modelId, callback);
8086
}
8187

@@ -96,9 +102,21 @@ export class ModelsCliUsecases {
96102
.find((e: any) => e.quantization === quantization);
97103

98104
if (!sibling) throw 'No expected quantization found';
105+
106+
let stopWord = '';
107+
try {
108+
const { metadata } = await gguf(sibling.downloadUrl!);
109+
// @ts-expect-error "tokenizer.ggml.eos_token_id"
110+
const index = metadata['tokenizer.ggml.eos_token_id'];
111+
// @ts-expect-error "tokenizer.ggml.tokens"
112+
stopWord = metadata['tokenizer.ggml.tokens'][index] ?? '';
113+
} catch (err) {
114+
console.log('Failed to get stop word: ', err);
115+
}
116+
99117
const stopWords: string[] = [];
100-
if (sibling.stopWord) {
101-
stopWords.push(sibling.stopWord);
118+
if (stopWord.length > 0) {
119+
stopWords.push(stopWord);
102120
}
103121

104122
const model: CreateModelDto = {
@@ -149,21 +167,6 @@ export class ModelsCliUsecases {
149167
for (let i = 0; i < data.siblings.length; i++) {
150168
const downloadUrl = `https://huggingface.co/${paths[2]}/${paths[3]}/resolve/main/${data.siblings[i].rfilename}`;
151169
data.siblings[i].downloadUrl = downloadUrl;
152-
153-
if (downloadUrl.endsWith('.gguf')) {
154-
// getting stop word
155-
let stopWord = '';
156-
try {
157-
const { metadata } = await gguf(downloadUrl);
158-
// @ts-expect-error "tokenizer.ggml.eos_token_id"
159-
const index = metadata['tokenizer.ggml.eos_token_id'];
160-
// @ts-expect-error "tokenizer.ggml.tokens"
161-
stopWord = metadata['tokenizer.ggml.tokens'][index] ?? '';
162-
data.siblings[i].stopWord = stopWord;
163-
} catch (err) {
164-
console.log('Failed to get stop word: ', err);
165-
}
166-
}
167170
}
168171

169172
AllQuantizations.forEach((quantization) => {

0 commit comments

Comments
 (0)