CoolFace
Apppublic

LeonardoMdSA/Context-aware-NLP-classification-platform-with-MCP

sourceHugging Facemitupdated 7mo agoView on Hugging Face
2likes
test_backend.py62 linesDownload Raw Back to root
1# Manual smoke test of backend2 3import requests4import json5 6API_URL = "http://127.0.0.1:8000"7 8# Sample document9document_text = "Invoice for Q4 2025: total amount $4,500."10 11# Optional metadata12metadata = {13    "department": "finance",14    "priority": "high"15}16 17payload = {18    "text": document_text,19    "metadata": metadata20}21 22 23def test_classify():24    try:25        response = requests.post(f"{API_URL}/classify", json=payload, timeout=30)26        response.raise_for_status()27        print("Classification Result:")28        print(json.dumps(response.json(), indent=4))29    except Exception as e:30        print("Classification test failed:", str(e))31 32 33def test_context():34    try:35        # POST to /context with JSON body36        response = requests.post(f"{API_URL}/context", json=payload, timeout=30)37        response.raise_for_status()38        print("\nContext Result:")39        print(json.dumps(response.json(), indent=4))40    except Exception as e:41        print("Context test failed:", str(e))42 43 44def test_predict():45    try:46        # GET to /predict with query param47        response = requests.get(f"{API_URL}/predict", params={"query": document_text}, timeout=30)48        response.raise_for_status()49        print("\nPredict Result (GET /predict):")50        print(json.dumps(response.json(), indent=4))51    except Exception as e:52        print("Predict test failed:", str(e))53 54 55if __name__ == "__main__":56    print("Testing /classify endpoint...")57    test_classify()58    print("\nTesting /context endpoint...")59    test_context()60    print("\nTesting /predict endpoint...")61    test_predict()62