Spaces:
Runtime error
Runtime error
Download scripts/test_query.py from welcometoFightclub/acpc-testing-7: direct link, hf CLI and curl.
- Browser
- Download file 2.03 kB
-
https://huggingface.co/spaces/welcometoFightclub/acpc-testing-7/resolve/main/scripts/test_query.py
- Command line
-
hf download hf://spaces/welcometoFightclub/acpc-testing-7/scripts/test_query.py
-
curl -L -o test_query.py https://huggingface.co/spaces/welcometoFightclub/acpc-testing-7/resolve/main/scripts/test_query.py
2.03 kB
| """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") | |