Spaces:
Runtime error
Runtime error
File size: 2,029 Bytes
bb0f4d5 | 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 52 53 54 55 56 57 58 59 60 61 62 | """Quick test script to verify SQL + RAG responses."""
import json
import httpx
API = "http://localhost:8000"
def test_query(query: str):
print(f"\n{'='*80}")
print(f"QUERY: {query}")
print('='*80)
tokens = []
sql_table = None
sources = []
with httpx.Client(timeout=120) as client:
with client.stream("POST", f"{API}/query", json={
"query": query,
"session_id": "test-verify",
"language": "en-IN",
}) as resp:
for line in resp.iter_lines():
if not line.startswith("data: "):
continue
event = json.loads(line[6:])
etype = event.get("type")
if etype == "token":
tokens.append(event["content"])
elif etype == "sql_table":
sql_table = event["content"]
elif etype == "sources":
sources = event["content"]
elif etype == "error":
print(f"ERROR: {event['message']}")
return
elif etype == "done":
print(f"Latency: {event['latency_ms']}ms")
if sql_table:
# Show just first 20 lines of table
table_lines = sql_table.split("\n")
print(f"\nSQL TABLE ({len(table_lines)-2} data rows):")
for line in table_lines[:17]: # header + sep + 15 rows
print(f" {line}")
if len(table_lines) > 17:
print(f" ... ({len(table_lines)-17} more lines)")
response = "".join(tokens)
print(f"\nRESPONSE ({len(response)} chars):")
print(response)
if sources:
print(f"\nSOURCES ({len(sources)}):")
for s in sources:
print(f" - {s.get('label', '')}")
if __name__ == "__main__":
test_query("What are the best engineering colleges in Gujarat for computer science?")
test_query("Top 5 colleges for computer engineering with lowest cutoff")
|