Instructions to use ntedvs/irex with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use ntedvs/irex with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # if on a CUDA device, also pip install mlx[cuda] # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("ntedvs/irex") prompt = "Once upon a time in" text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- MLX LM
How to use ntedvs/irex with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Generate some text mlx_lm.generate --model "ntedvs/irex" --prompt "Once upon a time"
- Atomic Chat
Download engine.py from ntedvs/irex: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/ntedvs/irex/resolve/main/engine.py
- Command line
-
hf download hf://ntedvs/irex/engine.py
-
curl -L -o engine.py https://huggingface.co/ntedvs/irex/resolve/main/engine.py
1.03 kB
| """JavaScript regex semantics via embedded QuickJS.""" | |
| import json | |
| import quickjs | |
| _JS = r""" | |
| function compiles(p, f) { try { new RegExp(p, f); return true } catch (e) { return false } } | |
| function tests(p, f, xs) { const r = new RegExp(p, f); return JSON.stringify(JSON.parse(xs).map(s => r.test(s))) } | |
| """ | |
| _ctx = quickjs.Context() | |
| _ctx.set_time_limit(0.05) # seconds; guards against catastrophic backtracking | |
| _ctx.eval(_JS) | |
| _compiles, _tests = _ctx.get("compiles"), _ctx.get("tests") | |
| def compiles(pattern: str, flags: str = "") -> bool: | |
| return bool(_compiles(pattern, flags)) | |
| def test(pattern: str, flags: str, strings: list[str]) -> list[bool]: | |
| return json.loads(_tests(pattern, flags, json.dumps(strings))) | |
| def literal(pattern: str, flags: str = "") -> str: | |
| return f"/{pattern}/{flags}" | |
| def parse_literal(s: str) -> tuple[str, str]: | |
| s = s.strip() | |
| if not s.startswith("/") or s.rfind("/") == 0: | |
| raise ValueError(f"not a regex literal: {s!r}") | |
| i = s.rfind("/") | |
| return s[1:i], s[i + 1:] | |