Download service/request.py from roudone/PabJev-4b: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/roudone/PabJev-4b/resolve/main/service/request.py
- Command line
-
hf download hf://roudone/PabJev-4b/service/request.py
-
curl -L -o request.py https://huggingface.co/roudone/PabJev-4b/resolve/main/service/request.py
1.3 kB
| #!/usr/bin/env python3 | |
| """Send one SystemOne JSON request and print the complete probability response.""" | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import urllib.error | |
| import urllib.request | |
| def main() -> None: | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("request_json", type=Path, nargs="?", | |
| default=Path(__file__).resolve().parent.parent / "examples/choice.json") | |
| parser.add_argument("--endpoint", default="http://127.0.0.1:18100/v1/systemone") | |
| parser.add_argument("--timeout", type=float, default=600) | |
| args = parser.parse_args() | |
| body = json.loads(args.request_json.read_text(encoding="utf-8")) | |
| request = urllib.request.Request( | |
| args.endpoint, data=json.dumps(body, ensure_ascii=False).encode("utf-8"), | |
| headers={"Content-Type": "application/json"}, | |
| ) | |
| try: | |
| with urllib.request.urlopen(request, timeout=args.timeout) as response: | |
| result = json.load(response) | |
| except urllib.error.HTTPError as exc: | |
| detail = exc.read().decode("utf-8", errors="replace") | |
| raise SystemExit(f"HTTP {exc.code}: {detail}") from exc | |
| print(json.dumps(result, ensure_ascii=False, indent=2)) | |
| if __name__ == "__main__": | |
| main() | |