-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathreleases.js
63 lines (61 loc) · 1.46 KB
/
releases.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const fetch = require('cross-fetch')
const os = require('os')
const GPU = require('./gpu')
const search = (releases, condition) => {
// iterate through releases until a release matching the exact condition is found
for(let release of releases) {
let matched = true
for(let key in condition) {
if (release[key] === condition[key]) {
} else {
matched = false
break
}
}
if (matched) {
return release
}
}
}
module.exports = async () => {
const platform = os.platform()
const arch = os.arch()
// returns the release URL to download
const response = await fetch("https://api.github.com/repos/ggerganov/llama.cpp/releases/latest").then((res) => {
return res.json()
})
const releases = response.assets.map((r) => {
return r.browser_download_url
}).map((x) => {
let info = {
url: x
}
if (/macos/i.test(x)) {
info.platform = "darwin"
} else if (/win/i.test(x)) {
info.platform = "win32"
} else if (/ubuntu/i.test(x)){
info.platform = "linux"
}
if (/arm64/i.test(x)) {
info.arch = "arm64"
} else if (/x64/i.test(x)) {
info.arch = "x64"
}
if (/-cuda-/i.test(x)) {
info.gpu = 'nvidia'
} else {
if (info.arch === 'arm64' && info.arch === 'arm64') {
info.gpu = 'apple'
}
}
return info
})
const gpu = await GPU()
const match = search(releases, {
platform,
arch,
gpu
})
return match
}