abiramavarshini/rag-backend
0
1import requests2 3def test_api():4 base_url = "http://localhost:8000"5 6 # 1. Login7 print("Testing Login...")8 login_data = {"email": "test@example.com", "password": "password123"}9 response = requests.post(f"{base_url}/auth/login", json=login_data)10 if response.status_code == 200:11 token = response.json()["access_token"]12 print(f"Login successful! Token: {token[:20]}...")13 else:14 print(f"Login failed: {response.status_code} - {response.text}")15 return16 17 # 2. Ask question18 print("\nTesting RAG Ask...")19 headers = {"Authorization": f"Bearer {token}"}20 ask_data = {"query": "What is this project about?"}21 response = requests.post(f"{base_url}/rag/ask", json=ask_data, headers=headers)22 if response.status_code == 200:23 print("Ask successful!")24 print(f"Response: {json.dumps(response.json(), indent=2)}")25 else:26 print(f"Ask failed: {response.status_code} - {response.text}")27 28if __name__ == "__main__":29 import json30 test_api()31 