Spaces:
Runtime error
Runtime error
Download scripts/test_ldce.py from welcometoFightclub/acpc-testing-7: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/spaces/welcometoFightclub/acpc-testing-7/resolve/main/scripts/test_ldce.py
- Command line
-
hf download hf://spaces/welcometoFightclub/acpc-testing-7/scripts/test_ldce.py
-
curl -L -o test_ldce.py https://huggingface.co/spaces/welcometoFightclub/acpc-testing-7/resolve/main/scripts/test_ldce.py
1.6 kB
| """Test LDCE-specific queries to check for hallucination.""" | |
| 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 | |
| with httpx.Client(timeout=120) as client: | |
| with client.stream("POST", f"{API}/query", json={ | |
| "query": query, | |
| "session_id": "test-ldce-fix", | |
| "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 == "error": | |
| print(f"ERROR: {event['message']}") | |
| return | |
| elif etype == "done": | |
| print(f"Latency: {event['latency_ms']}ms") | |
| if sql_table: | |
| table_lines = sql_table.split("\n") | |
| print(f"\nSQL TABLE ({len(table_lines)-2} data rows):") | |
| for line in table_lines[:22]: | |
| print(f" {line}") | |
| else: | |
| print("\n[NO SQL TABLE RETURNED]") | |
| response = "".join(tokens) | |
| print(f"\nRESPONSE ({len(response)} chars):") | |
| print(response[:2000]) | |
| if __name__ == "__main__": | |
| test_query("What are the cutoff ranks for LDCE Ahmedabad?") | |
| test_query("LDCE computer engineering cutoff") | |