Physical-AI-Backend / test_rag.py
Fizu123's picture
Upload 16 files
1c29d49 verified
import requests
import time
BASE_URL = "http://127.0.0.1:8000"
def test_api():
print("--- Testing RAG Chatbot API ---")
# 1. Health Check
try:
response = requests.get(f"{BASE_URL}/health")
if response.status_code == 200:
print("[OK] Health Check Passed!")
else:
print(f"[FAIL] Health Check Failed: {response.text}")
return
except requests.exceptions.ConnectionError:
print("[FAIL] Could not connect to server. Is it running?")
return
# 2. Reload Documents (Indexing) - SKIPPING TO AVOID RE-TRIGGERING
print("\nSkipping Indexing for this test run...")
# try:
# response = requests.post(f"{BASE_URL}/reload-documents")
# if response.status_code == 200:
# print(f"[OK] Indexing Response: {response.json()}")
# else:
# print(f"[FAIL] Indexing Failed: {response.text}")
# except Exception as e:
# print(f"[FAIL] Error during indexing: {e}")
# 3. Ask a Question
print("\nAsking: 'What is Physical AI?'...")
payload = {
"query": "What is Physical AI?",
"translate_urdu": False
}
try:
start_time = time.time()
response = requests.post(f"{BASE_URL}/ask", json=payload)
duration = time.time() - start_time
if response.status_code == 200:
data = response.json()
print(f"[OK] Answer ({duration:.2f}s):")
print(f"Answer: {data['answer']}")
print(f"Sources: {data['chapter']} / {data['section']}")
else:
print(f"[FAIL] Ask Failed: {response.text}")
except Exception as e:
print(f"[FAIL] Error during asking: {e}")
if __name__ == "__main__":
test_api()