File size: 1,365 Bytes
127ebd5 | 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 | """Call a running ``python -m deepedu_decision.serve`` over HTTP (standard library only).
python -m deepedu_decision.serve --model <path or hub id> --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())
|