Files

95 lines
2.9 KiB
Python
Raw Permalink Normal View History

2025-09-11 23:13:58 +01:00
#!/usr/bin/env python3
"""
Simple test script for LLM clients using config.py
"""
import asyncio
import sys
import os
# Add the src directory to the path so we can import our modules
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))
from config import Config
from llm_client.client_factory import AIClientFactory
async def test_openai_client():
"""Test OpenAI client with config.py"""
print("Testing OpenAI client with config.py...")
if not Config.OPENAI_API_KEY:
print("⚠️ OPENAI_API_KEY not found in environment variables")
return
try:
# Create OpenAI client using the factory (API key automatically loaded from config)
client = AIClientFactory.create_openai_client(
model_name="gpt-3.5-turbo" # Use cheaper model for testing
)
# Test basic chat completion
messages = [{"role": "user", "content": "Hello! Please respond with just 'Hello from OpenAI!'"}]
response = await client.chat_completion(messages)
print("✅ OpenAI client test successful!")
print(f"Response: {response['choices'][0]['message']['content']}")
await client.cleanup()
except Exception as e:
print(f"❌ OpenAI client test failed: {e}")
async def test_client_factory():
"""Test client factory functionality"""
print("\nTesting client factory...")
# Test available providers
providers = AIClientFactory.get_available_providers()
print(f"Available providers: {providers}")
# Test provider validation
print(f"OpenAI valid: {AIClientFactory.validate_provider('openai')}")
print(f"Invalid provider valid: {AIClientFactory.validate_provider('invalid')}")
# Test creating client by provider (API key loaded automatically)
if Config.OPENAI_API_KEY:
try:
client = AIClientFactory.create_client("openai", "gpt-3.5-turbo")
print("✅ Client creation by provider successful!")
await client.cleanup()
except Exception as e:
print(f"❌ Client creation by provider failed: {e}")
else:
print("⚠️ Skipping client creation test - no OpenAI API key")
print("✅ Client factory test completed!")
async def test_config_loading():
"""Test config.py loading"""
print("\nTesting config.py loading...")
print(f"OpenAI API Key loaded: {'Yes' if Config.OPENAI_API_KEY else 'No'}")
print(f"Claude API Key loaded: {'Yes' if Config.CLAUDE_API_KEY else 'No'}")
print(f"Grok API Key loaded: {'Yes' if Config.GROK_API_KEY else 'No'}")
print("✅ Config loading test completed!")
async def main():
"""Run all tests"""
print("🚀 Starting LLM Client Tests with config.py")
print("=" * 50)
await test_config_loading()
await test_client_factory()
await test_openai_client()
print("\n" + "=" * 50)
print("🏁 All tests completed!")
if __name__ == "__main__":
asyncio.run(main())