3 ms·
In 9 lines of python: (from https://news.ycombinator.com/item?id=49006862 https://news.ycombinator.com/item?id=49006862 ) import json,sys;from subprocess impor
by JSR_FDED 2mo ago
In 9 lines of python: (from https://news.ycombinator.com/item?id=49006862 https://news.ycombinator.com/item?id=49006862 )
import json,sys;from subprocess import getoutput as sh;from urllib.request import Request as R,urlopen
url=sys.argv[1];h=[];b=dict(model="gpt-5.6",input=h,tools=[dict(type="custom",name="sh")])
while p:=input("> "):
h+=[dict(role="user",content=p)];H={"Content-Type":"application/json"}
while True:
o=(r:=json.load(urlopen(R(url,json.dumps(b).encode(),H))))["output"]
h+=o;c=[i for i in o if i["type"]=="custom_tool_call"];z=r["usage"]["total_tokens"]/10500
if not c:print(o[-1]["content"][0]["text"],f'\n[{z:06.3f}%]');break
h+=[dict(type="custom_tool_call_output",call_id=i["call_id"],output=sh(i["input"])) for i in c]