"""Call a running ``python -m deepedu_decision.serve`` over HTTP (standard library only). python -m deepedu_decision.serve --model --port 9100 python examples/client.py --url http://localhost:9100 """ import argparse import json import urllib.error import urllib.request parser = argparse.ArgumentParser() parser.add_argument("--url", default="http://localhost:9100") args = parser.parse_args() body = { "state": "Customer message: 'I was charged twice for my March invoice and need one of the charges reversed.'", "questions": { "route": { "type": "choice", "instructions": "Which team should handle this message?", "criteria": {"billing": "Charges, invoices, refunds", "technical": "Bugs, outages", "sales": "Pricing"}, }, "urgent": {"type": "noul", "instructions": "Does the customer ask for immediate action?"}, }, } request = urllib.request.Request(args.url.rstrip("/") + "/v1/systemone", json.dumps(body).encode(), {"Content-Type": "application/json"}) try: with urllib.request.urlopen(request, timeout=120) as response: print(json.dumps(json.load(response), indent=2)) except urllib.error.HTTPError as err: # 422: over the context limit or unsupported; 503: server busy print(err.code, err.read().decode())