File size: 1,518 Bytes
b4d57a6 9c30c74 b4d57a6 9c30c74 b4d57a6 9c30c74 b4d57a6 9c30c74 b4d57a6 9c30c74 b4d57a6 |
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 |
#!/usr/bin/env python3
"""Simple smoke check that hits the running FastAPI server root and /query.
This uses only the standard library so it should work in the project's venv.
"""
from __future__ import annotations
import json
import urllib.request
def get_root() -> str:
with urllib.request.urlopen("http://127.0.0.1:8000/") as resp:
return resp.read().decode("utf-8")
def post_query(q: str):
"""Test SQL-based query endpoint."""
data = json.dumps({"query": q, "top_k": 5}).encode("utf-8")
req = urllib.request.Request("http://127.0.0.1:8000/query-sql", data=data, headers={"Content-Type": "application/json"})
with urllib.request.urlopen(req, timeout=30) as resp:
return json.load(resp)
def main() -> None:
print("Checking http://127.0.0.1:8000/ ...")
try:
root = get_root()
print("Root response length:", len(root))
except Exception as e:
print("Failed to GET root:", e)
return
sample_q = "ืื ืืืขืืืช ืืขืืงืจืืืช ืฉืืฉืชืืฉืื ืืฆืืื ืื?"
print("Posting sample query to /query-sql ...")
try:
resp = post_query(sample_q)
print("Query response keys:", list(resp.keys()))
print("Summary (truncated):\n", (resp.get("summary") or "(no summary)")[:800])
if resp.get("sql_queries"):
print(f"Generated {len(resp['sql_queries'])} SQL queries")
except Exception as e:
print("Failed to POST /query-sql:", e)
if __name__ == "__main__":
main()
|