#!/usr/bin/env python3 """ Simple script untuk test koneksi Novita AI """ import os import requests import json def test_novita_connection(): """Test koneksi ke Novita AI dengan berbagai cara""" api_key = os.getenv('NOVITA_API_KEY') if not api_key: print("āŒ NOVITA_API_KEY tidak ditemukan") return print(f"šŸ”‘ API Key: {api_key[:10]}...{api_key[-10:]}") print("šŸ” Testing koneksi ke Novita AI...") # Test different possible endpoints endpoints_to_test = [ "https://api.novita.ai", "https://api.novita.com", "https://novita.ai/api", "https://novita.com/api", "https://api.novita.ai/v1", "https://api.novita.com/v1", "https://novita.ai/api/v1", "https://novita.com/api/v1" ] headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" } working_endpoints = [] for endpoint in endpoints_to_test: print(f"\nšŸ” Testing: {endpoint}") # Test basic connectivity try: # Test GET request response = requests.get(f"{endpoint}/models", headers=headers, timeout=10) print(f" GET /models: {response.status_code}") if response.status_code == 200: print(f" āœ… Success! Response: {response.text[:200]}...") working_endpoints.append(endpoint) elif response.status_code == 401: print(f" āš ļø Unauthorized - API key mungkin salah") elif response.status_code == 404: print(f" āš ļø Not Found - Endpoint tidak ada") else: print(f" āš ļø Status: {response.status_code}") except requests.exceptions.ConnectionError as e: print(f" āŒ Connection Error: {e}") except requests.exceptions.Timeout as e: print(f" ā° Timeout: {e}") except Exception as e: print(f" āŒ Error: {e}") # Test POST request try: test_data = {"test": "connection"} response = requests.post(f"{endpoint}/test", headers=headers, json=test_data, timeout=10) print(f" POST /test: {response.status_code}") except Exception as e: print(f" āŒ POST Error: {e}") print(f"\nšŸ“Š Summary:") if working_endpoints: print(f"āœ… Working endpoints: {len(working_endpoints)}") for endpoint in working_endpoints: print(f" - {endpoint}") else: print("āŒ No working endpoints found") print("\nšŸ’” Suggestions:") print("1. Check if the API key is correct") print("2. Check Novita AI documentation for correct endpoints") print("3. Try using a different API key") print("4. Check if there are any IP restrictions") return working_endpoints def test_openai_compatible(): """Test if Novita AI is OpenAI compatible""" print("\nšŸ¤– Testing OpenAI compatibility...") api_key = os.getenv('NOVITA_API_KEY') if not api_key: print("āŒ NOVITA_API_KEY tidak ditemukan") return # Try OpenAI-compatible endpoints openai_endpoints = [ "https://api.novita.ai/v1", "https://api.novita.com/v1", "https://novita.ai/api/v1", "https://novita.com/api/v1" ] headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" } for endpoint in openai_endpoints: print(f"\nšŸ” Testing OpenAI endpoint: {endpoint}") try: # Test models endpoint response = requests.get(f"{endpoint}/models", headers=headers, timeout=10) print(f" GET /models: {response.status_code}") if response.status_code == 200: print(f" āœ… Success!") try: models = response.json() print(f" šŸ“‹ Models: {json.dumps(models, indent=2)[:300]}...") except: print(f" šŸ“‹ Response: {response.text[:200]}...") elif response.status_code == 401: print(f" āš ļø Unauthorized") elif response.status_code == 404: print(f" āš ļø Not Found") else: print(f" āš ļø Status: {response.status_code}") except Exception as e: print(f" āŒ Error: {e}") def main(): print("šŸ” Novita AI Connection Tester") print("=" * 40) # Test basic connection working_endpoints = test_novita_connection() # Test OpenAI compatibility test_openai_compatible() print(f"\nšŸŽÆ Next Steps:") if working_endpoints: print("āœ… Koneksi berhasil! Anda bisa melanjutkan dengan fine-tuning") print("šŸ’” Gunakan endpoint yang berfungsi untuk setup selanjutnya") else: print("āŒ Koneksi gagal. Cek dokumentasi Novita AI") print("šŸ’” Atau gunakan alternatif lain seperti local models") if __name__ == "__main__": main()