"""Smart engine on a small fixed document (two AI-written paragraphs) with the app's default settings: time per job and the AI score before -> after. For comparing engine settings (SMART_*, HUM_* variables apply as on the Space); absolute times on a CPU-only PC are much longer than on the GPU, the comparison is what counts. python devtools/bench_smart.py [--passes 4] [--tag name]""" import argparse import os import sys import tempfile import time from pathlib import Path ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(ROOT)) sys.path.insert(0, str(Path(__file__).resolve().parent)) import env # noqa: E402 env.load() os.environ.setdefault("LT_MODE", "off") os.environ.setdefault("SKIP_MODEL_LOAD", "1") sys.stdout.reconfigure(encoding="utf-8") from docx import Document # noqa: E402 def main(): ap = argparse.ArgumentParser() ap.add_argument("--passes", type=int, default=4) ap.add_argument("--tag", default="run") a = ap.parse_args() import groqai as G import smart as S d = Document() d.add_heading("Results", level=1) from samples_domains import DOMAINS # plain AI-written prose: little that must stay fixed for k in ("management", "economics"): d.add_paragraph(DOMAINS[k]) path = Path(tempfile.mkdtemp()) / f"bench_smart_{a.tag}.docx" d.save(path) class Rep: frac, desc = 0.0, "" def __call__(self, frac, desc=""): self.frac, self.desc = frac, desc S._score_doc(Document(str(path))) # load the detector before the clock starts t0 = time.time() res = S.smart_docx(str(path), 0, a.passes, 0.9, "Fast (recommended)", 0.80, 0.50, Rep()) took = time.time() - t0 acct = G.ACCT.get() print(f"[bench_smart] {a.tag}: {took:.0f}s | AI {res['before']['pct']}% -> {res['after']['pct']}% | " f"Groq ${G.spent(acct) if acct else 0:.4f}") for line in res["log"]: print(" ", line) if __name__ == "__main__": main()