char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

rankaiyxfeat(ui): add symbolic math support to JS sandbox via nerdamer (#25948)61328e6a9

char/aliceai-t5-moe
1.0 KiB32 linesraw
1const logs = [];
2const fmt = (value) => {
3	if (typeof value === 'string') return value;
4	try {
5		return JSON.stringify(value);
6	} catch {
7		return String(value);
8	}
9};
10const capture =
11	(level, prefix) =>
12	(...args) => {
13		logs.push(prefix + args.map(fmt).join(' '));
14	};
15console.log = capture('log', '');
16console.info = capture('info', '');
17console.debug = capture('debug', '');
18console.warn = capture('warn', 'warn: ');
19console.error = capture('error', 'error: ');
20self.onmessage = async (event) => {
21	const reply = { logs, result: null, error: null };
22	try {
23		const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
24		// The prelude bundled ahead of this shim defines self.nerdamer,
25		// passed into the execution scope as the `nerdamer` parameter.
26		const value = await new AsyncFunction('nerdamer', event.data.code)(self.nerdamer);
27		if (value !== undefined) reply.result = fmt(value);
28	} catch (err) {
29		reply.error = err instanceof Error ? err.stack || err.message : String(err);
30	}
31	self.postMessage(reply);
32};