Torrent downloader + alpaca.13B

This commit is contained in:
cocktailpeanut 2023-03-19 21:08:24 -04:00
parent d5e2d2026e
commit e02476d3d1
6 changed files with 2890 additions and 16 deletions

View File

@ -10,7 +10,7 @@ class Alpaca {
constructor(root) {
this.root = root
this.home = path.resolve(this.root.home, "alpaca")
this.url = "https://github.com/cocktailpeanut/alpaca.cpp.git"
this.url = "https://github.com/candywrap/alpaca.cpp.git"
}
async make() {
let success
@ -70,14 +70,32 @@ class Alpaca {
console.log(`Skip conversion, file already exists: ${outputFile}`)
} else {
const task = `downloading ${outputFile}`
const url = "https://ipfs.io/ipfs/QmQ1bf2BTnYxq73MFJWu1B7bQ2UD6qG7D7YDCxhTndVkPC"
const dir = path.resolve(this.home, "models", model)
console.log("dir", dir)
await fs.promises.mkdir(dir, { recursive: true }).catch((e) => {
console.log("mkdir", e)
})
console.log("down", url)
await this.root.down(url, path.resolve(dir, "ggml-model-q4_0.bin"))
if (model === "7B") {
//const url = "https://ipfs.io/ipfs/QmQ1bf2BTnYxq73MFJWu1B7bQ2UD6qG7D7YDCxhTndVkPC"
//console.log("down", url)
//await this.root.down(url, path.resolve(dir, "ggml-model-q4_0.bin"))
console.log("downloading torrent")
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)
console.log("renaming")
await fs.promises.rename(
path.resolve(dir, "ggml-alpaca-7b-q4.bin"),
path.resolve(dir, "ggml-model-q4_0.bin")
)
} else if (model === "13B") {
console.log("downloading torrent")
await this.root.torrent.add('magnet:?xt=urn:btih:AU5T2VGS4577AIHL3X2R3LLID4VGKEDR&dn=ggml-alpaca-13b-q4.bin&xl=8136637097&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce', dir)
console.log("renaming")
await fs.promises.rename(
path.resolve(dir, "ggml-alpaca-13b-q4.bin"),
path.resolve(dir, "ggml-model-q4_0.bin")
)
}
}
}
}

View File

@ -19,6 +19,7 @@ const platform = os.platform()
const shell = platform === 'win32' ? 'powershell.exe' : 'bash';
const L = require("./llama")
const A = require("./alpaca")
const TorrentDownloader = require("./torrent")
const exists = s => new Promise(r=>fs.access(s, fs.constants.F_OK, e => r(!e)))
const escapeNewLine = (platform, arg) => platform === 'win32' ? arg.replaceAll(/\n/g, "\\n").replaceAll(/\r/g, "\\r") : arg
const escapeDoubleQuotes = (platform, arg) => platform === 'win32' ? arg.replaceAll(/"/g, '`"') : arg.replaceAll(/"/g, '\\"')
@ -45,7 +46,7 @@ class Dalai {
} catch (e) {
console.log("E", e)
}
this.torrent = new TorrentDownloader()
this.config = {
name: 'xterm-color',
cols: 200,

1864
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "dalai",
"version": "0.2.45",
"version": "0.2.46",
"description": "",
"main": "index.js",
"author": "cocktailpeanut",
@ -27,6 +27,7 @@
"socket.io-client": "^4.6.1",
"tar": "^6.1.13",
"terminal-kit": "^3.0.0",
"webtorrent": "1.9.7",
"yargs": "^17.7.1"
},
"devDependencies": {

52
torrent.js Normal file
View File

@ -0,0 +1,52 @@
const WebTorrent = require('webtorrent')
const term = require( 'terminal-kit' ).terminal;
const path = require('path')
const fs = require('fs')
class TorrentDownloader {
constructor() {
this.client = new WebTorrent()
this.start = {}
this.progressbar = {}
}
add(url, folder, cb) {
return new Promise((resolve, reject) => {
let e = fs.existsSync(folder)
if (!e) {
fs.mkdirSync(folder, { recursive: true })
}
this.client.add(url, { path: folder }, (torrent) => {
this.progressbar[url] = term.progressBar({
width: 120,
title: torrent.name,
eta: true,
percent: true
});
torrent.on('metadata', (m) => {
this.start[torrent.name] = Date.now()
console.log({ metadata: m })
term("\n")
})
torrent.on('download', bytes => {
if (cb) {
cb({ progress: torrent.progress, speed: torrent.downloadSpeed, downloaded: torrent.downloaded })
}
this.progressbar[url].update(torrent.progress)
})
torrent.on('done', () => {
console.log('torrent download finished')
const end = Date.now()
const elapsed = end - this.start[torrent.name]
console.log({ start: this.start[torrent.name], end: end, elapsed })
this.progressbar[url].update(1)
term("\n")
resolve(torrent)
for (const file of torrent.files) {
// do something with file
console.log("file", file.name, file.size)
}
})
})
})
}
}
module.exports = TorrentDownloader

958
yarn.lock

File diff suppressed because it is too large Load Diff