|
|
|
""" |
|
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 |
|
|
|
|
|
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 |
|
|
|
|
|
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") |
|
|
|
|
|
generator = APIClueGenerator() |
|
|
|
print(f"\nπ€ Available models: {len(generator.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 |
|
|
|
|
|
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: |
|
|
|
print(f"Using best model: {best_model}") |
|
|
|
results = generator.generate_clue(word, topic) |
|
|
|
results = {best_model: results.get(best_model)} |
|
else: |
|
|
|
results = generator.generate_clue(word, topic) |
|
|
|
|
|
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)) |
|
|
|
|
|
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") |
|
|
|
|
|
if valid_results: |
|
|
|
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})") |
|
|
|
|
|
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() |