From d8826735cd9be160439761e3a2a155133be292cb Mon Sep 17 00:00:00 2001 From: Gambitnl <147505131+Gambitnl@users.noreply.github.com> Date: Fri, 21 Nov 2025 12:32:42 +0100 Subject: [PATCH 1/2] fix: normalize api key test script logging --- test_api_keys.py | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/test_api_keys.py b/test_api_keys.py index 73717d6..5870181 100644 --- a/test_api_keys.py +++ b/test_api_keys.py @@ -18,16 +18,16 @@ def test_groq_api(): print("=" * 80) if not Config.GROQ_API_KEY: - print("❌ GROQ_API_KEY not found in environment") + print("[ERROR] GROQ_API_KEY not found in environment") print(" Set it in your .env file or via Settings & Tools in the UI") return False - print(f"✓ API Key found: {Config.GROQ_API_KEY[:10]}...") + print(f"[OK] API Key found: {Config.GROQ_API_KEY[:10]}...") try: from groq import Groq client = Groq(api_key=Config.GROQ_API_KEY) - print("✓ Groq client initialized") + print("[OK] Groq client initialized") # Test with a simple completion (cheaper than transcription) print("\nTesting API connection with a simple request...") @@ -38,18 +38,18 @@ def test_groq_api(): ) result = response.choices[0].message.content - print(f"✓ API Response: {result}") + print(f"[OK] API Response: {result}") - print("\n✅ Groq API is working correctly!") + print("\n[SUCCESS] Groq API is working correctly!") print(" You can use 'groq' for transcription and classification backends") return True except ImportError: - print("❌ Groq package not installed") + print("[ERROR] Groq package not installed") print(" Install with: pip install groq") return False except Exception as e: - print(f"❌ Error testing Groq API: {e}") + print(f"[ERROR] Error testing Groq API: {e}") print(" Check that your API key is valid") return False @@ -61,11 +61,11 @@ def test_huggingface_api(): print("=" * 80) if not Config.HUGGING_FACE_API_KEY: - print("❌ HUGGING_FACE_API_KEY not found in environment") + print("[ERROR] HUGGING_FACE_API_KEY not found in environment") print(" Set it in your .env file or via Settings & Tools in the UI") return False - print(f"✓ API Key found: {Config.HUGGING_FACE_API_KEY[:10]}...") + print(f"[OK] API Key found: {Config.HUGGING_FACE_API_KEY[:10]}...") try: # Use the huggingface_hub library for authentication test @@ -78,25 +78,25 @@ def test_huggingface_api(): user_info = api.whoami() username = user_info.get("name", "unknown") - print(f"✓ Authenticated as: {username}") - print("\n✅ Hugging Face API is working correctly!") + print(f"[OK] Authenticated as: {username}") + print("\n[SUCCESS] Hugging Face API is working correctly!") print(" You can use 'hf_api' for the diarization backend") return True except ImportError: - print("❌ 'huggingface_hub' package not installed") + print("[ERROR] 'huggingface_hub' package not installed") print(" Install with: pip install huggingface-hub") return False except Exception as e: error_msg = str(e) if "401" in error_msg or "Invalid token" in error_msg: - print(f"❌ Authentication failed: Invalid API key") + print("[ERROR] Authentication failed: Invalid API key") print(" Check that your HF token is correct") elif "403" in error_msg: - print(f"❌ Authorization failed: Token lacks required permissions") + print("[ERROR] Authorization failed: Token lacks required permissions") print(" Ensure your token has 'Make calls to Inference Providers' permission") else: - print(f"❌ Error testing Hugging Face API: {error_msg}") + print(f"[ERROR] Error testing Hugging Face API: {error_msg}") print(" Check your internet connection and API key") return False @@ -115,20 +115,20 @@ def main(): print("\n" + "=" * 80) print("Test Summary") print("=" * 80) - print(f"Groq API: {'✅ PASS' if groq_ok else '❌ FAIL'}") - print(f"Hugging Face API: {'✅ PASS' if hf_ok else '❌ FAIL'}") + print(f"Groq API: {'[PASS]' if groq_ok else '[FAIL]'}") + print(f"Hugging Face API: {'[PASS]' if hf_ok else '[FAIL]'}") if groq_ok and hf_ok: - print("\n🎉 All APIs are configured correctly!") + print("\n[SUCCESS] All APIs are configured correctly!") print("\nYou can now use cloud backends in the UI:") print(" - Transcription: Select 'groq' backend") print(" - Diarization: Select 'hf_api' backend") print(" - Classification: Select 'groq' backend") elif groq_ok or hf_ok: - print("\n⚠ Some APIs are working, but not all") + print("\n[WARNING] Some APIs are working, but not all") print(" Set the missing API keys to enable all cloud features") else: - print("\n❌ No APIs are configured") + print("\n[ERROR] No APIs are configured") print(" Add your API keys to .env or via Settings & Tools in the UI") print("=" * 80) @@ -140,6 +140,6 @@ def main(): except KeyboardInterrupt: print("\n\nTest interrupted by user") except Exception as e: - print(f"\n\n❌ Unexpected error: {e}") + print(f"\n\n[ERROR] Unexpected error: {e}") import traceback traceback.print_exc() From d7f6cf987ae4486d15b6ac8204a87ebf3afdb7ab Mon Sep 17 00:00:00 2001 From: Gambitnl <147505131+Gambitnl@users.noreply.github.com> Date: Fri, 21 Nov 2025 12:41:07 +0100 Subject: [PATCH 2/2] refactor: use logger for api key tests --- test_api_keys.py | 112 +++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 57 deletions(-) diff --git a/test_api_keys.py b/test_api_keys.py index 5870181..3f1648a 100644 --- a/test_api_keys.py +++ b/test_api_keys.py @@ -13,24 +13,24 @@ def test_groq_api(): """Test Groq API connection and basic transcription.""" - print("\n" + "=" * 80) - print("Testing Groq API") - print("=" * 80) + logger.info("\n%s", "=" * 80) + logger.info("Testing Groq API") + logger.info("%s", "=" * 80) if not Config.GROQ_API_KEY: - print("[ERROR] GROQ_API_KEY not found in environment") - print(" Set it in your .env file or via Settings & Tools in the UI") + logger.error("GROQ_API_KEY not found in environment") + logger.info(" Set it in your .env file or via Settings & Tools in the UI") return False - print(f"[OK] API Key found: {Config.GROQ_API_KEY[:10]}...") + logger.info("API Key found: %s...", Config.GROQ_API_KEY[:10]) try: from groq import Groq client = Groq(api_key=Config.GROQ_API_KEY) - print("[OK] Groq client initialized") + logger.info("Groq client initialized") # Test with a simple completion (cheaper than transcription) - print("\nTesting API connection with a simple request...") + logger.info("\nTesting API connection with a simple request...") response = client.chat.completions.create( messages=[{"role": "user", "content": "Say 'API test successful' and nothing else."}], model="llama-3.3-70b-versatile", # Updated to current model @@ -38,108 +38,106 @@ def test_groq_api(): ) result = response.choices[0].message.content - print(f"[OK] API Response: {result}") + logger.info("API Response: %s", result) - print("\n[SUCCESS] Groq API is working correctly!") - print(" You can use 'groq' for transcription and classification backends") + logger.info("\n[SUCCESS] Groq API is working correctly!") + logger.info(" You can use 'groq' for transcription and classification backends") return True except ImportError: - print("[ERROR] Groq package not installed") - print(" Install with: pip install groq") + logger.error("Groq package not installed") + logger.info(" Install with: pip install groq") return False except Exception as e: - print(f"[ERROR] Error testing Groq API: {e}") - print(" Check that your API key is valid") + logger.exception("Error testing Groq API: %s", e) + logger.info(" Check that your API key is valid") return False def test_huggingface_api(): """Test Hugging Face API connection.""" - print("\n" + "=" * 80) - print("Testing Hugging Face API") - print("=" * 80) + logger.info("\n%s", "=" * 80) + logger.info("Testing Hugging Face API") + logger.info("%s", "=" * 80) if not Config.HUGGING_FACE_API_KEY: - print("[ERROR] HUGGING_FACE_API_KEY not found in environment") - print(" Set it in your .env file or via Settings & Tools in the UI") + logger.error("HUGGING_FACE_API_KEY not found in environment") + logger.info(" Set it in your .env file or via Settings & Tools in the UI") return False - print(f"[OK] API Key found: {Config.HUGGING_FACE_API_KEY[:10]}...") + logger.info("API Key found: %s...", Config.HUGGING_FACE_API_KEY[:10]) try: # Use the huggingface_hub library for authentication test from huggingface_hub import HfApi - print("\nTesting API authentication...") + logger.info("\nTesting API authentication...") api = HfApi(token=Config.HUGGING_FACE_API_KEY) # Try to get user info - this validates the token user_info = api.whoami() username = user_info.get("name", "unknown") - print(f"[OK] Authenticated as: {username}") - print("\n[SUCCESS] Hugging Face API is working correctly!") - print(" You can use 'hf_api' for the diarization backend") + logger.info("Authenticated as: %s", username) + logger.info("\n[SUCCESS] Hugging Face API is working correctly!") + logger.info(" You can use 'hf_api' for the diarization backend") return True except ImportError: - print("[ERROR] 'huggingface_hub' package not installed") - print(" Install with: pip install huggingface-hub") + logger.error("'huggingface_hub' package not installed") + logger.info(" Install with: pip install huggingface-hub") return False except Exception as e: error_msg = str(e) if "401" in error_msg or "Invalid token" in error_msg: - print("[ERROR] Authentication failed: Invalid API key") - print(" Check that your HF token is correct") + logger.error("Authentication failed: Invalid API key") + logger.info(" Check that your HF token is correct") elif "403" in error_msg: - print("[ERROR] Authorization failed: Token lacks required permissions") - print(" Ensure your token has 'Make calls to Inference Providers' permission") + logger.error("Authorization failed: Token lacks required permissions") + logger.info(" Ensure your token has 'Make calls to Inference Providers' permission") else: - print(f"[ERROR] Error testing Hugging Face API: {error_msg}") - print(" Check your internet connection and API key") + logger.exception("Error testing Hugging Face API: %s", error_msg) + logger.info(" Check your internet connection and API key") return False def main(): """Run all API tests.""" - print("=" * 80) - print("API Key Validation Test Suite") - print("=" * 80) - print("\nThis script tests your cloud API configurations.") - print("Make sure you've set your API keys in .env or via the UI.") + logger.info("%s", "=" * 80) + logger.info("API Key Validation Test Suite") + logger.info("%s", "=" * 80) + logger.info("\nThis script tests your cloud API configurations.") + logger.info("Make sure you've set your API keys in .env or via the UI.") groq_ok = test_groq_api() hf_ok = test_huggingface_api() - print("\n" + "=" * 80) - print("Test Summary") - print("=" * 80) - print(f"Groq API: {'[PASS]' if groq_ok else '[FAIL]'}") - print(f"Hugging Face API: {'[PASS]' if hf_ok else '[FAIL]'}") + logger.info("\n%s", "=" * 80) + logger.info("Test Summary") + logger.info("%s", "=" * 80) + logger.info("Groq API: %s", "[PASS]" if groq_ok else "[FAIL]") + logger.info("Hugging Face API: %s", "[PASS]" if hf_ok else "[FAIL]") if groq_ok and hf_ok: - print("\n[SUCCESS] All APIs are configured correctly!") - print("\nYou can now use cloud backends in the UI:") - print(" - Transcription: Select 'groq' backend") - print(" - Diarization: Select 'hf_api' backend") - print(" - Classification: Select 'groq' backend") + logger.info("\n[SUCCESS] All APIs are configured correctly!") + logger.info("\nYou can now use cloud backends in the UI:") + logger.info(" - Transcription: Select 'groq' backend") + logger.info(" - Diarization: Select 'hf_api' backend") + logger.info(" - Classification: Select 'groq' backend") elif groq_ok or hf_ok: - print("\n[WARNING] Some APIs are working, but not all") - print(" Set the missing API keys to enable all cloud features") + logger.warning("\n[WARNING] Some APIs are working, but not all") + logger.info(" Set the missing API keys to enable all cloud features") else: - print("\n[ERROR] No APIs are configured") - print(" Add your API keys to .env or via Settings & Tools in the UI") + logger.error("\n[ERROR] No APIs are configured") + logger.info(" Add your API keys to .env or via Settings & Tools in the UI") - print("=" * 80) + logger.info("%s", "=" * 80) if __name__ == "__main__": try: main() except KeyboardInterrupt: - print("\n\nTest interrupted by user") + logger.warning("\n\nTest interrupted by user") except Exception as e: - print(f"\n\n[ERROR] Unexpected error: {e}") - import traceback - traceback.print_exc() + logger.exception("\n\nUnexpected error: %s", e)