Download scripts/web-server.mjs from williamKang112/llm-fit: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/williamKang112/llm-fit/resolve/main/scripts/web-server.mjs
- Command line
-
hf download hf://williamKang112/llm-fit/scripts/web-server.mjs
-
curl -L -o web-server.mjs https://huggingface.co/williamKang112/llm-fit/resolve/main/scripts/web-server.mjs
1.43 kB
| import http from 'node:http'; | |
| import fs from 'node:fs/promises'; | |
| import path from 'node:path'; | |
| import { fileURLToPath } from 'node:url'; | |
| import { estimateFit } from '../src/core.mjs'; | |
| const __dirname = path.dirname(fileURLToPath(import.meta.url)); | |
| const webRoot = path.resolve(__dirname, '../web'); | |
| const port = Number(process.env.PORT || 4173); | |
| const server = http.createServer(async (req, res) => { | |
| if (!req.url) return res.end(); | |
| if (req.url.startsWith('/api/fit')) { | |
| const u = new URL(req.url, `http://localhost:${port}`); | |
| const profile = { | |
| ramGB: Number(u.searchParams.get('ram') || 16), | |
| vramGB: Number(u.searchParams.get('vram') || 8), | |
| cpuTier: String(u.searchParams.get('cpu') || 'mid'), | |
| platform: String(u.searchParams.get('platform') || 'apple-silicon'), | |
| }; | |
| const data = estimateFit(profile); | |
| res.setHeader('Content-Type', 'application/json'); | |
| return res.end(JSON.stringify({ profile, data })); | |
| } | |
| const filePath = req.url === '/' ? path.join(webRoot, 'index.html') : path.join(webRoot, req.url); | |
| try { | |
| const content = await fs.readFile(filePath); | |
| const type = filePath.endsWith('.js') ? 'text/javascript' : 'text/html'; | |
| res.setHeader('Content-Type', type); | |
| res.end(content); | |
| } catch { | |
| res.statusCode = 404; | |
| res.end('Not found'); | |
| } | |
| }); | |
| server.listen(port, () => { | |
| console.log(`llm-fit web on http://localhost:${port}`); | |
| }); | |