File size: 2,017 Bytes
82a89bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""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()