Spaces:
Build error
Build error
File size: 1,157 Bytes
0387a1c | 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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | from __future__ import annotations
"""
Sample test case (manual integration check).
1) Run the API:
uvicorn main:app --reload --host 127.0.0.1 --port 8000
2) Run:
python sample_test.py
"""
import json
import os
import urllib.request
BASE_URL = os.environ.get("BASE_URL", "http://127.0.0.1:8000")
def post_json(path: str, payload: dict) -> dict:
body = json.dumps(payload).encode("utf-8")
req = urllib.request.Request(
BASE_URL + path,
data=body,
headers={"Content-Type": "application/json"},
method="POST",
)
with urllib.request.urlopen(req, timeout=30) as resp: # nosec - local dev call
return json.loads(resp.read().decode("utf-8"))
def main() -> None:
email = {
"from_email": "customer@example.com",
"subject": "Need help resetting my password",
"body": "Hi, I cannot log in. Please help me reset my password. Thanks!",
}
print("POST /classify")
print(post_json("/classify", email))
print()
print("POST /generate-reply")
print(post_json("/generate-reply", {**email, "tone": "formal"}))
if __name__ == "__main__":
main()
|