#!/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()