@@ -6,6 +6,7 @@ import { HuggingFaceRepoData } from '@/domain/models/huggingface.interface';
66import { gguf } from '@huggingface/gguf' ;
77import { InquirerService } from 'nest-commander' ;
88import { Inject , Injectable } from '@nestjs/common' ;
9+ import { Presets , SingleBar } from 'cli-progress' ;
910
1011const 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