File size: 2,835 Bytes
5ce45af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
# Run the side-by-side demo server once against live endpoints and record what each side streamed.
#   MINI_URL=http://127.0.0.1:9007 MINI_MODEL=inkling-2-mini OTHER_URL=http://127.0.0.1:18811 bash tools/demo_live.sh
# Writes results/raw/demo_live.json: per side, the HTTP status, seconds, characters and whether text arrived.
set -u
R=/data/train/mini
PORT=${PORT:-8701}
export MINI_URL=${MINI_URL:-http://127.0.0.1:9007} MINI_MODEL=${MINI_MODEL:-inkling-2-mini}
export OTHER_URL=${OTHER_URL:-http://127.0.0.1:18811} OTHER_MODEL=${OTHER_MODEL:-anthropic/claude-opus-5.5} OTHER_KEY_ENV=${OTHER_KEY_ENV:-DEMO_NO_KEY}
cd $R/src
$R/venv/bin/python demo/server.py --port $PORT --max-tokens 400 > $R/logs/demo_live.log 2>&1 &
S=$!
sleep 4
$R/venv/bin/python - "$PORT" > $R/results/raw/demo_live.json <<'EOF'
import json, sys, time, urllib.request
port = sys.argv[1]
out = {"task": "Write a Python function that merges overlapping intervals. Code only.", "measured": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())}
out["page"] = urllib.request.urlopen(f"http://127.0.0.1:{port}/", timeout=20).status
out["info"] = json.load(urllib.request.urlopen(f"http://127.0.0.1:{port}/info", timeout=20))
for side in ("mini", "other"):
    t0 = time.time()
    rec = {}
    try:
        req = urllib.request.Request(f"http://127.0.0.1:{port}/stream/{side}", data=json.dumps({"task": out["task"]}).encode(),
                                     headers={"Content-Type": "application/json"})
        with urllib.request.urlopen(req, timeout=300) as r:
            rec["status"] = r.status
            text, first, usage = "", None, None
            for line in r:
                line = line.decode("utf-8", "replace").strip()
                if not line.startswith("data: ") or line == "data: [DONE]":
                    continue
                try:
                    d = json.loads(line[6:])
                except ValueError:
                    continue
                for c in d.get("choices") or []:
                    piece = (c.get("delta") or {}).get("content") or (c.get("delta") or {}).get("reasoning") or (c.get("delta") or {}).get("reasoning_content") or ""
                    if piece and first is None:
                        first = time.time() - t0
                    text += piece
                usage = d.get("usage") or usage
            rec.update(seconds=round(time.time() - t0, 2), first_text_s=round(first, 2) if first else None, characters=len(text),
                       completion_tokens=(usage or {}).get("completion_tokens"), has_def=("def " in text))
    except Exception as e:
        rec.update(error=f"{type(e).__name__}: {str(e)[:200]}", seconds=round(time.time() - t0, 2))
    out[side] = rec
print(json.dumps(out, indent=1))
EOF
kill $S 2>/dev/null
cat $R/results/raw/demo_live.json