File size: 6,415 Bytes
486eff6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
#!/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() |