File size: 3,523 Bytes
9b4ef96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Simple script untuk test koneksi Novita AI dengan endpoint yang benar
"""

import os
import requests
import json

def test_novita_connection():
    """Test koneksi ke Novita AI dengan endpoint yang benar"""
    
    api_key = os.getenv('NOVITA_API_KEY')
    if not api_key:
        print("❌ NOVITA_API_KEY tidak ditemukan")
        return False
    
    print(f"πŸ”‘ API Key: {api_key[:10]}...{api_key[-10:]}")
    print("πŸ” Testing koneksi ke Novita AI...")
    
    # Use the correct endpoint
    base_url = "https://api.novita.ai/openai"
    
    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json"
    }
    
    try:
        # Test models endpoint
        print(f"πŸ” Testing: {base_url}/models")
        response = requests.get(f"{base_url}/models", headers=headers, timeout=10)
        print(f"  Status: {response.status_code}")
        
        if response.status_code == 200:
            print("βœ… Koneksi berhasil!")
            models = response.json()
            print(f"πŸ“‹ Found {len(models.get('data', []))} models")
            return True
        else:
            print(f"❌ Error: {response.status_code} - {response.text}")
            return False
            
    except Exception as e:
        print(f"❌ Error: {e}")
        return False

def test_chat_completion():
    """Test chat completion dengan model sederhana"""
    
    api_key = os.getenv('NOVITA_API_KEY')
    if not api_key:
        print("❌ NOVITA_API_KEY tidak ditemukan")
        return False
    
    base_url = "https://api.novita.ai/openai"
    
    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json"
    }
    
    # Test dengan model yang ringan
    payload = {
        "model": "meta-llama/llama-3.2-1b-instruct",
        "messages": [
            {"role": "user", "content": "Hello! How are you today?"}
        ],
        "max_tokens": 50,
        "temperature": 0.7
    }
    
    try:
        print(f"πŸ” Testing chat completion...")
        response = requests.post(f"{base_url}/chat/completions", headers=headers, json=payload, timeout=30)
        print(f"  Status: {response.status_code}")
        
        if response.status_code == 200:
            result = response.json()
            print("βœ… Chat completion berhasil!")
            print(f"πŸ“ Response: {result.get('choices', [{}])[0].get('message', {}).get('content', 'No content')}")
            return True
        else:
            print(f"❌ Error: {response.status_code} - {response.text}")
            return False
            
    except Exception as e:
        print(f"❌ Error: {e}")
        return False

def main():
    print("πŸš€ Novita AI Simple Test")
    print("=" * 40)
    
    # Test connection
    if test_novita_connection():
        print("\nπŸŽ‰ Koneksi berhasil! Sekarang test chat completion...")
        
        # Test chat completion
        if test_chat_completion():
            print("\nπŸŽ‰ Semua test berhasil! Novita AI siap digunakan.")
            print("\nπŸ“‹ Next steps:")
            print("1. Gunakan script novita_ai_setup_v2.py untuk fine-tuning")
            print("2. Atau gunakan script test_model.py untuk testing")
            print("3. Monitor usage di dashboard Novita AI")
        else:
            print("\n⚠️  Chat completion gagal, tapi koneksi OK")
    else:
        print("\n❌ Koneksi gagal. Cek API key dan endpoint")

if __name__ == "__main__":
    main()