Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienos.com/blob/main/scripts/allen/measure.py # aienos.com Source of www.aienos.com, served from my own hardware Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienos.com / scripts / allen / measure.py` 27 lines ยท 1481 bytes Raw Blame History 1 import json, sys, time, http.client, ssl 2 def run(host, port, tls, q, path="/allen/api/chat", hdr=None): 3 c = (http.client.HTTPSConnection(host, port, timeout=200, context=ssl.create_default_context()) if tls 4 else http.client.HTTPConnection(host, port, timeout=200)) 5 body = json.dumps({"messages": [{"role": "user", "content": q}]}) 6 t0 = time.monotonic(); c.request("POST", path, body, dict({"Content-Type": "application/json"}, **(hdr or {}))); r = c.getresponse() 7 ev=None; start=None; first=None; last=None; n=0; done=None 8 for line in r: 9 line=line.rstrip(b"\n") 10 if line.startswith(b"event: "): ev=line[7:].decode(); continue 11 if line.startswith(b"data: "): 12 d=json.loads(line[6:]); t=time.monotonic() 13 if ev=="start": start=t 14 elif ev is None and d: 15 n+=1; last=t 16 if first is None: first=t 17 elif ev=="done": done=d 18 elif ev=="error": done={"error":d} 19 ev=None 20 tps = (n-1)/(last-first) if n>1 and last>first else None 21 return {"status": r.status, "queue_ms": int(((start or t0)-t0)*1000), "ttft_ms": int(((first or t0)-t0)*1000), 22 "tokens": n, "tok_s": round(tps,2) if tps else None, "server": done} 23 for arg in sys.argv[1:]: 24 where, q = arg.split("|",1) 25 if where=="hub": res=run("www.aienos.com",443,True,q) 26 else: res=run("100.64.0.2",18110,False,q) 27 print(where, json.dumps(res)); sys.stdout.flush()