abc123 / hack /interactive_clue_tester.py
vimalk78's picture
feat(crossword): generated crosswords with clues
486eff6
raw
history blame
6.42 kB
#!/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()