Spaces:
Running
Running
Download worker.js from SamJoshua/chat-template-checker: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/SamJoshua/chat-template-checker/resolve/main/worker.js
- Command line
-
hf download hf://spaces/SamJoshua/chat-template-checker/worker.js
-
curl -L -o worker.js https://huggingface.co/spaces/SamJoshua/chat-template-checker/resolve/main/worker.js
1.13 kB
| let py, ready; | |
| async function init() { | |
| importScripts("https://cdn.jsdelivr.net/pyodide/v0.29.3/full/pyodide.js"); | |
| py = await loadPyodide(); | |
| await py.loadPackage(["micropip", "jinja2", "markupsafe"]); | |
| const v = py.runPython("import jinja2; jinja2.__version__"); | |
| if (v.split(".").map(Number).join(".") < "3.1.6") await py.runPythonAsync("import micropip; await micropip.install('jinja2>=3.1.6')"); | |
| for (const f of ["ctt_bench.py", "web_checker.py"]) py.FS.writeFile(f, await (await fetch(f)).text()); | |
| py.runPython("import web_checker"); | |
| } | |
| ready = init().then(() => postMessage({ type: "ready" }), (e) => postMessage({ type: "initerror", error: String(e) })); | |
| onmessage = async (ev) => { | |
| await ready; | |
| const { id, template, special } = ev.data; | |
| try { | |
| py.globals.set("_t", template); py.globals.set("_s", JSON.stringify(special)); | |
| const out = py.runPython("web_checker.run(_t, _s)"); | |
| postMessage({ type: "result", id, data: JSON.parse(out) }); | |
| } catch (e) { postMessage({ type: "result", id, data: { ok: false, error: "Could not run the template: " + String(e).split("\n").slice(-2)[0] } }); } | |
| }; | |