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
File size: 1,032 Bytes
521b329 | 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 | """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:]
|