@@ -65,50 +65,47 @@ class Alpaca {
6565 * 5. Download models + convert + quantize
6666 *
6767 **************************************************************************************************************/
68- const outputFile = path . resolve ( this . home , 'models' , model , 'ggml-model-q4_0.bin' )
69- if ( fs . existsSync ( outputFile ) ) {
70- console . log ( `Skip conversion, file already exists: ${ outputFile } ` )
71- } else {
68+
69+ const currentVersions = {
70+ "7B" : 'ggml-model-q4_0.bin' ,
71+ "13B" : 'ggml-model-q4_1.bin' ,
72+ "30B" : 'ggml-model-q4_0.bin' ,
73+ }
74+
75+ const outputFile = path . resolve ( this . home , 'models' , model , currentVersions [ model ] )
76+
77+ const modelExists = ( f ) => {
78+ if ( fs . existsSync ( f ) ) {
79+ console . log ( `Skip conversion, file already exists: ${ f } ` )
80+ return true
81+ }
82+ // delete other model files in folder in case of an upgrade
83+
84+ const dir = path . dirname ( f ) ;
85+ const files = fs . readdirSync ( dir ) ;
86+ if ( files . length !== 0 ) console . log ( "Upgrading model, removing old files..." )
87+
88+ for ( const file of files ) {
89+ fs . unlinkSync ( path . join ( dir , file ) ) ;
90+ console . log ( `Removed old model file: ${ file } in ${ dir } ` )
91+ }
92+ return false
93+ }
94+
95+ if ( ! modelExists ( outputFile ) ) {
7296 const dir = path . resolve ( this . home , "models" , model )
7397 console . log ( "dir" , dir )
7498 await fs . promises . mkdir ( dir , { recursive : true } ) . catch ( ( e ) => {
7599 console . log ( "mkdir" , e )
76100 } )
77101 console . log ( "downloading torrent" )
78102 let url
79- switch ( model ) {
80- case "7B" :
81- //await this.root.torrent.add('magnet:?xt=urn:btih:5aaceaec63b03e51a98f04fd5c42320b2a033010&dn=ggml-alpaca-7b-q4.bin&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce', dir)
82- //console.log("renaming")
83- //await fs.promises.rename(
84- // path.resolve(dir, "ggml-alpaca-7b-q4.bin"),
85- // path.resolve(dir, "ggml-model-q4_0.bin")
86- //)
87- url = "https://huggingface.co/Pi3141/alpaca-7B-ggml/resolve/main/ggml-model-q4_0.bin"
88- await this . root . down ( url , path . resolve ( dir , "ggml-model-q4_0.bin" ) )
89- break ;
90-
91- case "13B" :
92- /*
93- await this.root.torrent.add('magnet:?xt=urn:btih:053b3d54d2e77ff020ebddf51dad681f2a651071&dn=ggml-alpaca-13b-q4.bin&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.com%3A2810%2Fannounce', dir)
94- console.log("renaming")
95- await fs.promises.rename(
96- path.resolve(dir, "ggml-alpaca-13b-q4.bin"),
97- path.resolve(dir, "ggml-model-q4_0.bin")
98- )
99- */
100- url = "https://huggingface.co/Pi3141/alpaca-13B-ggml/resolve/main/ggml-model-q4_1.bin"
101- await this . root . down ( url , path . resolve ( dir , "ggml-model-q4_0.bin" ) )
102- break ;
103103
104- case "30B" :
105- url = "https://huggingface.co/Pi3141/alpaca-30B-ggml/resolve/main/ggml-model-q4_0.bin"
106- await this . root . down ( url , path . resolve ( dir , "ggml-model-q4_0.bin" ) )
107- break ;
108-
109- default :
110- console . log ( "Select either model 7B, 13B, or 30B" )
111- break ;
104+ if ( Object . keys ( currentVersions ) . includes ( model ) ) {
105+ url = `https://huggingface.co/Pi3141/alpaca-${ model } -ggml/resolve/main/${ currentVersions [ model ] } `
106+ await this . root . down ( url , path . resolve ( dir , currentVersions [ model ] ) )
107+ } else {
108+ console . log ( "Select either model 7B, 13B, or 30B" )
112109 }
113110 }
114111 }
0 commit comments