File size: 2,760 Bytes
4ecf54e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python3
"""
Monitor the Mistral Nemo service startup and run tests when ready.
"""
import time
import requests
import json
import sys

def check_service_health():
    """Check if the service is healthy and ready."""
    try:
        response = requests.get("http://localhost:8001/health", timeout=5)
        if response.status_code == 200:
            data = response.json()
            return data.get("status") == "healthy"
    except requests.exceptions.RequestException:
        pass
    return False

def test_chat_completion():
    """Test the chat completion endpoint."""
    try:
        response = requests.post(
            "http://localhost:8001/v1/chat/completions",
            headers={"Content-Type": "application/json"},
            json={
                "model": "unsloth/Mistral-Nemo-Instruct-2407",
                "messages": [
                    {"role": "user", "content": "Hello! Please say 'Service is working correctly' if you can read this."}
                ],
                "max_tokens": 50,
                "temperature": 0.7
            },
            timeout=30
        )
        
        if response.status_code == 200:
            data = response.json()
            content = data["choices"][0]["message"]["content"]
            print(f"βœ… Chat completion successful: {content}")
            return True
        else:
            print(f"❌ Chat completion failed: {response.status_code} - {response.text}")
            return False
    except requests.exceptions.RequestException as e:
        print(f"❌ Chat completion error: {e}")
        return False

def monitor_service():
    """Monitor service startup and test when ready."""
    print("πŸ” Monitoring Mistral Nemo service startup...")
    print("πŸ“₯ Waiting for model download and loading to complete...")
    
    check_count = 0
    max_checks = 300  # 25 minutes max wait
    
    while check_count < max_checks:
        if check_service_health():
            print("\nπŸŽ‰ Service is healthy! Running tests...")
            
            # Test chat completion
            if test_chat_completion():
                print("\nβœ… All tests passed! Mistral Nemo service is fully operational.")
                return True
            else:
                print("\n⚠️ Service health check passed but chat completion failed.")
                return False
        
        check_count += 1
        dots = "." * (check_count % 4)
        print(f"\r⏳ Waiting for service to be ready{dots:<3} ({check_count}/300)", end="")
        time.sleep(5)
    
    print(f"\n❌ Service didn't become ready after {max_checks * 5} seconds")
    return False

if __name__ == "__main__":
    success = monitor_service()
    sys.exit(0 if success else 1)