operations-granite/HuggingFace-Granite-AI-Practice-Agent-Dev
0
1#!/usr/bin/env python32"""3Test RAG API endpoints4"""5 6import requests7import json8 9BASE_URL = "http://localhost:7860"10 11print("๐งช Testing RAG API Endpoints")12print("=" * 70)13 14# Test 1: RAG Health Endpoint (no auth needed)15print("\n1๏ธโฃ Testing RAG health endpoint...")16try:17 response = requests.get(f"{BASE_URL}/api/rag/health", timeout=5)18 if response.status_code == 200:19 data = response.json()20 print(f" โ
RAG Health: {data.get('message')}")21 print(f" ๐ Available endpoints: {len(data.get('endpoints', []))}")22 else:23 print(f" โ Health check failed: {response.status_code}")24except Exception as e:25 print(f" โ Request failed: {e}")26 27# Test 2: Get embedding stats (requires auth - skip for now)28print("\n2๏ธโฃ Testing embedding stats endpoint...")29try:30 # For now, test without auth to see if endpoint exists31 response = requests.get(f"{BASE_URL}/api/rag/embeddings/stats", timeout=5)32 if response.status_code == 401:33 print(f" โ
Endpoint exists (requires authentication)")34 elif response.status_code == 200:35 data = response.json()36 print(f" โ
Total embeddings: {data['data']['total_embeddings']}")37 else:38 print(f" โ ๏ธ Status: {response.status_code}")39except Exception as e:40 print(f" โ Request failed: {e}")41 42# Test 3: Semantic search (requires auth - skip for now)43print("\n3๏ธโฃ Testing semantic search endpoint...")44try:45 response = requests.post(46 f"{BASE_URL}/api/rag/semantic-search",47 json={"query": "budget discussions", "limit": 3},48 timeout=549 )50 if response.status_code == 401:51 print(f" โ
Endpoint exists (requires authentication)")52 elif response.status_code == 200:53 data = response.json()54 print(f" โ
Search returned {data['data']['count']} results")55 else:56 print(f" โ ๏ธ Status: {response.status_code}")57except Exception as e:58 print(f" โ Request failed: {e}")59 60# Test 4: Check if backend is responding at all61print("\n4๏ธโฃ Testing base API...")62try:63 response = requests.get(f"{BASE_URL}/api/meetings", timeout=5)64 print(f" โ
Backend is responding (status: {response.status_code})")65except Exception as e:66 print(f" โ Backend not responding: {e}")67 68print("\n" + "=" * 70)69print("โ
RAG Endpoint Tests Complete")70print("=" * 70)71print("\n๐ Summary:")72print(" - RAG endpoints are registered in the backend")73print(" - Endpoints require authentication (expected)")74print(" - Backend is running and responding to requests")75print("\n๐ To test with authentication:")76print(" 1. Login via frontend: http://localhost:5173")77print(" 2. Get JWT token from browser dev tools")78print(" 3. Use token in Authorization header")79 