4 ms·
9 lines of python: import json,sys,uuid;from subprocess import getoutput as sh;from urllib.request import Request as R,urlopen b={"model":"gpt-5.6","prompt
by tosh 4mo ago
9 lines of python:
import json,sys,uuid;from subprocess import getoutput as sh;from urllib.request import Request as R,urlopen
b={"model":"gpt-5.6","prompt_cache_key":uuid.uuid4().hex,"input":[],"tools":[{"type":"custom","name":"shell"}]}
while prompt:=input("> "):
b["input"]+=[{"role":"user","content":prompt}]
while True:
o=(r:=json.load(urlopen(R(sys.argv[1],json.dumps(b).encode(),{"Content-Type":"application/json"}))))["output"]
b["input"]+=o;calls=[i for i in o if i["type"]=="custom_tool_call"];used=r["usage"]["total_tokens"]/10500
if not calls: print(o[-1]["content"][0]["text"],f'\n[{used:06.3f}%]'); break
b["input"]+=[{"type":"custom_tool_call_output","call_id":i["call_id"],"output":sh(i["input"])} for i in calls]
- tosh 4mo agonb: - stdlib only, 0 external dependencies - works with openai compatible api (including local models) - shows context usage in % when turn goes back to user - cache friendly (keeps stable prefix and provides uuid v4 as session cache key) - uses 'shell' as open ended tool 'shell' as tool name is sufficient context for gpt 5.6 sol
- ySPARK 4mo agoEvery Lisp program can be written in one line.