Download source/examples/client.py from DeepEduVN/bungpt-open: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/DeepEduVN/bungpt-open/resolve/main/source/examples/client.py
- Command line
-
hf download hf://DeepEduVN/bungpt-open/source/examples/client.py
-
curl -L -o client.py https://huggingface.co/DeepEduVN/bungpt-open/resolve/main/source/examples/client.py
1.37 kB
| """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()) | |