File size: 4,316 Bytes
4e10023
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c6f7b75
4e10023
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python3
"""
Test script for multimodal AI backend service
Tests both text-only and image+text functionality
"""

import requests
import json
import time

# Service configuration
BASE_URL = "http://localhost:8000"

def test_text_only():
    """Test text-only chat completion"""
    print("πŸ§ͺ Testing text-only chat completion...")
    
    payload = {
        "model": "microsoft/DialoGPT-medium",
        "messages": [
            {"role": "user", "content": "Hello! How are you today?"}
        ],
        "max_tokens": 100,
        "temperature": 0.7
    }
    
    try:
        response = requests.post(f"{BASE_URL}/v1/chat/completions", json=payload, timeout=30)
        if response.status_code == 200:
            result = response.json()
            print(f"βœ… Text-only response: {result['choices'][0]['message']['content']}")
            return True
        else:
            print(f"❌ Text-only failed: {response.status_code} - {response.text}")
            return False
    except Exception as e:
        print(f"❌ Text-only error: {e}")
        return False

def test_multimodal():
    """Test multimodal (image + text) chat completion"""
    print("πŸ–ΌοΈ Testing multimodal chat completion...")
    
    payload = {
        "model": "unsloth/DeepSeek-R1-0528-Qwen3-8B-GGUF",
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "type": "image",
                        "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"
                    },
                    {
                        "type": "text",
                        "text": "What animal is on the candy?"
                    }
                ]
            }
        ],
        "max_tokens": 150,
        "temperature": 0.7
    }
    
    try:
        response = requests.post(f"{BASE_URL}/v1/chat/completions", json=payload, timeout=60)
        if response.status_code == 200:
            result = response.json()
            print(f"βœ… Multimodal response: {result['choices'][0]['message']['content']}")
            return True
        else:
            print(f"❌ Multimodal failed: {response.status_code} - {response.text}")
            return False
    except Exception as e:
        print(f"❌ Multimodal error: {e}")
        return False

def test_service_info():
    """Test service information endpoint"""
    print("ℹ️ Testing service information...")
    
    try:
        response = requests.get(f"{BASE_URL}/", timeout=10)
        if response.status_code == 200:
            result = response.json()
            print(f"βœ… Service info: {result['message']}")
            return True
        else:
            print(f"❌ Service info failed: {response.status_code}")
            return False
    except Exception as e:
        print(f"❌ Service info error: {e}")
        return False

def test_health():
    """Test health check endpoint"""
    print("πŸ₯ Testing health check...")
    
    try:
        response = requests.get(f"{BASE_URL}/health", timeout=10)
        if response.status_code == 200:
            result = response.json()
            print(f"βœ… Health: {result['status']} - Model: {result['model']}")
            return True
        else:
            print(f"❌ Health check failed: {response.status_code}")
            return False
    except Exception as e:
        print(f"❌ Health check error: {e}")
        return False

def main():
    """Run all tests"""
    print("πŸš€ Starting multimodal AI backend tests...\n")
    
    tests = [
        ("Service Info", test_service_info),
        ("Health Check", test_health),
        ("Text-only Chat", test_text_only),
        ("Multimodal Chat", test_multimodal),
    ]
    
    passed = 0
    total = len(tests)
    
    for test_name, test_func in tests:
        print(f"\n--- {test_name} ---")
        if test_func():
            passed += 1
        time.sleep(1)
    
    print(f"\n🎯 Test Results: {passed}/{total} tests passed")
    
    if passed == total:
        print("πŸŽ‰ All tests passed! Multimodal AI backend is working correctly!")
    else:
        print("⚠️ Some tests failed. Check the output above for details.")

if __name__ == "__main__":
    main()