#!/usr/bin/env python3 """ Interactive Crossword Clue Tester Allows user to test custom word-topic combinations with the best performing API model. """ import sys import logging from pathlib import Path # Add hack directory to path for imports sys.path.insert(0, str(Path(__file__).parent)) try: from api_clue_generator import APIClueGenerator API_AVAILABLE = True except ImportError as e: print(f"โŒ Import error: {e}") API_AVAILABLE = False # Set up logging (quieter for interactive use) logging.basicConfig( level=logging.WARNING, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' ) def interactive_clue_tester(): """Interactive mode for testing crossword clue generation.""" if not API_AVAILABLE: print("โŒ Cannot run interactive tester - API generator not available") return print("๐Ÿงช Interactive Crossword Clue Tester") print("=" * 50) print("Test custom word-topic combinations using multiple AI models via API") # Initialize generator generator = APIClueGenerator() print(f"\n๐Ÿค– Available models: {len(generator.models)}") # Show available models print("\nModels being tested:") for i, (key, model) in enumerate(generator.models.items(), 1): print(f" {i}. {key}") print("\n" + "=" * 50) print("๐ŸŽฏ INTERACTIVE MODE") print("=" * 50) print("Enter word-topic pairs to test AI clue generation.") print("Format: word,topic (e.g., 'elephant,animals')") print("") print("Commands:") print(" quit/exit/q - Exit the program") print(" help - Show this help") print(" models - List all models") print(" best - Use only the best performing model") print("-" * 50) use_best_only = False best_model = None while True: try: user_input = input("\n๐Ÿ“ Enter word,topic (or command): ").strip() if user_input.lower() in ['quit', 'exit', 'q']: print("๐Ÿ‘‹ Thanks for testing! Goodbye!") break elif user_input.lower() == 'help': print("\nCommands:") print(" word,topic - Generate clues (e.g., 'guitar,music')") print(" models - List all available models") print(" best - Toggle best-model-only mode") print(" quit - Exit") continue elif user_input.lower() == 'models': print(f"\nAvailable models ({len(generator.models)}):") for i, (key, model) in enumerate(generator.models.items(), 1): print(f" {i}. {key} - {model}") continue elif user_input.lower() == 'best': use_best_only = not use_best_only if use_best_only: print("๐Ÿ† Best-model-only mode ENABLED") print(" Will test with highest-rated model only for faster results") else: print("๐Ÿค– All-models mode ENABLED") print(" Will test with all available models") continue elif not user_input or ',' not in user_input: print("โŒ Invalid format. Use: word,topic (e.g., 'cat,animals')") print(" Or type 'help' for commands") continue # Parse input parts = user_input.split(',', 1) word = parts[0].strip().upper() topic = parts[1].strip().lower() if not word or not topic: print("โŒ Both word and topic are required") continue print(f"\n๐ŸŽฏ Generating clues for: '{word}' + '{topic}'") print("-" * 40) if use_best_only and best_model: # Use only the best model (faster) print(f"Using best model: {best_model}") # TODO: Implement single model query results = generator.generate_clue(word, topic) # Filter to best model only results = {best_model: results.get(best_model)} else: # Use all models results = generator.generate_clue(word, topic) # Display results valid_results = [] for model_key, clue in results.items(): if clue: quality, score = generator.evaluate_clue_quality(word, clue) valid_results.append((model_key, clue, quality, score)) # Color coding for terminal if quality == "EXCELLENT": quality_icon = "โœ…" elif quality == "GOOD": quality_icon = "๐Ÿ”„" elif quality == "ACCEPTABLE": quality_icon = "โš ๏ธ " else: quality_icon = "โŒ" print(f"{quality_icon} {model_key:20} | {quality:10} | {clue}") else: print(f"โŒ {model_key:20} | FAILED | No response") # Show summary if valid_results: # Sort by quality score valid_results.sort(key=lambda x: x[3], reverse=True) best_result = valid_results[0] print(f"\n๐Ÿ† Best result: {best_result[1]}") print(f" Model: {best_result[0]}") print(f" Quality: {best_result[2]} (score: {best_result[3]:.2f})") # Update best model for future use if not best_model or best_result[3] > 0.7: best_model = best_result[0] else: print("โŒ No valid clues generated by any model") except KeyboardInterrupt: print("\n๐Ÿ‘‹ Interrupted. Goodbye!") break except Exception as e: print(f"โŒ Error: {e}") print("Please try again or type 'quit' to exit") def main(): """Run the interactive clue tester.""" interactive_clue_tester() if __name__ == "__main__": main()