File size: 1,837 Bytes
01fa9b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import requests
import json

# Test the Flask API
def test_api():
    url = "http://localhost:5001/compute"
    
    # Test data
    test_data = {
        "prompt": "What is the capital of France?",
        "max_length": 256,
        "temperature": 0.7,
        "top_p": 0.9
    }
    
    try:
        print("Testing the /compute endpoint...")
        print(f"Sending prompt: {test_data['prompt']}")
        
        response = requests.post(url, json=test_data)
        
        if response.status_code == 200:
            result = response.json()
            print("\nResponse received successfully!")
            print(f"Status: {result['status']}")
            print(f"Response: {result['response']}")
        else:
            print(f"Error: {response.status_code}")
            print(response.text)
            
    except requests.exceptions.ConnectionError:
        print("Error: Could not connect to the server. Make sure the Flask app is running on port 5001.")
    except Exception as e:
        print(f"Error: {str(e)}")

def test_health_check():
    url = "http://localhost:5001/"
    
    try:
        print("Testing health check endpoint...")
        response = requests.get(url)
        
        if response.status_code == 200:
            result = response.json()
            print("Health check successful!")
            print(json.dumps(result, indent=2))
        else:
            print(f"Error: {response.status_code}")
            print(response.text)
            
    except requests.exceptions.ConnectionError:
        print("Error: Could not connect to the server. Make sure the Flask app is running on port 5001.")
    except Exception as e:
        print(f"Error: {str(e)}")

if __name__ == "__main__":
    print("=== Flask API Test ===")
    test_health_check()
    print("\n" + "="*50 + "\n")
    test_api()