52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script for the Grok client implementation.
|
|
"""
|
|
|
|
import asyncio
|
|
import logging
|
|
from config import Config
|
|
from grok_client import GrokClient
|
|
|
|
# Set up logging
|
|
logging.basicConfig(level=logging.INFO)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
async def test_grok_client():
|
|
"""Test the Grok client functionality."""
|
|
|
|
# Load configuration
|
|
config = Config()
|
|
|
|
# Check if API key is configured
|
|
if not config.openrouter_api_key:
|
|
logger.error("Please set your OpenRouter API key in the configuration")
|
|
logger.info("You can set it in config/config.json or modify the default in config.py")
|
|
return
|
|
|
|
# Create and test the client
|
|
async with GrokClient(config) as client:
|
|
# Test health check
|
|
logger.info("Testing health check...")
|
|
is_healthy = await client.check_health()
|
|
if is_healthy:
|
|
logger.info("✅ Grok client is healthy")
|
|
else:
|
|
logger.error("❌ Grok client health check failed")
|
|
return
|
|
|
|
# Test response generation
|
|
logger.info("Testing response generation...")
|
|
test_prompt = "What is the meaning of life?"
|
|
response = await client.generate_response(test_prompt)
|
|
|
|
if response:
|
|
logger.info("✅ Response generated successfully")
|
|
logger.info(f"Prompt: {test_prompt}")
|
|
logger.info(f"Response: {response}")
|
|
else:
|
|
logger.error("❌ Failed to generate response")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(test_grok_client())
|