File size: 5,548 Bytes
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env python3
"""
Test the updated multimodal AI backend service on port 8001
"""

import requests
import json

# Updated service configuration
BASE_URL = "http://localhost:8001"

def test_multimodal_updated():
    """Test multimodal (image + text) chat completion with working model"""
    print("πŸ–ΌοΈ Testing multimodal chat completion with Salesforce/blip-image-captioning-base...")
    
    payload = {
        "model": "Salesforce/blip-image-captioning-base",
        "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=120)
        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_models_endpoint():
    """Test updated models endpoint"""
    print("πŸ“‹ Testing models endpoint...")
    
    try:
        response = requests.get(f"{BASE_URL}/v1/models", timeout=10)
        if response.status_code == 200:
            result = response.json()
            model_ids = [model['id'] for model in result['data']]
            print(f"βœ… Available models: {model_ids}")
            
            if "Salesforce/blip-image-captioning-base" in model_ids:
                print("βœ… Vision model is available!")
                return True
            else:
                print("⚠️ Vision model not listed")
                return False
        else:
            print(f"❌ Models endpoint failed: {response.status_code}")
            return False
    except Exception as e:
        print(f"❌ Models endpoint error: {e}")
        return False

def test_text_only_updated():
    """Test text-only functionality on new port"""
    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 response: {result['choices'][0]['message']['content']}")
            return True
        else:
            print(f"❌ Text failed: {response.status_code} - {response.text}")
            return False
    except Exception as e:
        print(f"❌ Text error: {e}")
        return False

def test_image_only():
    """Test with image only (no text)"""
    print("πŸ–ΌοΈ Testing image-only analysis...")
    
    payload = {
        "model": "Salesforce/blip-image-captioning-base",
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "type": "image",
                        "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"
                    }
                ]
            }
        ],
        "max_tokens": 100,
        "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"βœ… Image-only response: {result['choices'][0]['message']['content']}")
            return True
        else:
            print(f"❌ Image-only failed: {response.status_code} - {response.text}")
            return False
    except Exception as e:
        print(f"❌ Image-only error: {e}")
        return False

def main():
    """Run all tests for updated service"""
    print("πŸš€ Testing Updated Multimodal AI Backend (Port 8001)...\n")
    
    tests = [
        ("Models Endpoint", test_models_endpoint),
        ("Text-only Chat", test_text_only_updated),
        ("Image-only Analysis", test_image_only),
        ("Multimodal Chat", test_multimodal_updated),
    ]
    
    passed = 0
    total = len(tests)
    
    for test_name, test_func in tests:
        print(f"\n--- {test_name} ---")
        if test_func():
            passed += 1
        print()
    
    print(f"🎯 Test Results: {passed}/{total} tests passed")
    
    if passed == total:
        print("πŸŽ‰ All tests passed! Multimodal AI backend is fully working!")
        print("πŸ”₯ Your backend now supports:")
        print("   βœ… Text-only chat completions")
        print("   βœ… Image analysis and captioning")
        print("   βœ… Multimodal image+text conversations")
        print("   βœ… OpenAI-compatible API format")
    else:
        print("⚠️ Some tests failed. Check the output above for details.")

if __name__ == "__main__":
    main()