92 lines
3.4 KiB
Python
92 lines
3.4 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test the new format where AI returns a list and keys are generated locally.
|
|
"""
|
|
|
|
import json
|
|
import sys
|
|
import os
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from generate_prompts import JournalPromptGenerator
|
|
|
|
def test_new_format():
|
|
"""Test the new format where AI returns a list and keys are generated locally."""
|
|
|
|
print("Testing new format: AI returns list, keys generated locally")
|
|
print("="*60)
|
|
|
|
# Create a mock generator
|
|
generator = JournalPromptGenerator(config_path=".env")
|
|
|
|
# Create a mock AI response in the new list format
|
|
mock_ai_response = [
|
|
"Write about a childhood memory that still makes you smile.",
|
|
"Describe your perfect day from start to finish.",
|
|
"What is something you've been putting off and why?",
|
|
"Imagine you could have a conversation with any historical figure.",
|
|
"Write a letter to your future self one year from now.",
|
|
"Describe a place that feels like home to you."
|
|
]
|
|
|
|
# Convert to JSON string
|
|
json_response = json.dumps(mock_ai_response)
|
|
|
|
print("\n1. Testing _parse_ai_response with list format:")
|
|
result = generator._parse_ai_response(json_response)
|
|
print(f" Result type: {type(result)}")
|
|
print(f" Number of prompts: {len(result)}")
|
|
print(f" First prompt: {result[0][:50]}...")
|
|
|
|
# Verify it's a list of strings
|
|
assert isinstance(result, list), "Result should be a list"
|
|
assert all(isinstance(prompt, str) for prompt in result), "All items should be strings"
|
|
|
|
print("\n2. Testing add_prompts_to_pool with list of strings:")
|
|
|
|
# Get initial pool size
|
|
initial_pool_size = len(generator.pool_prompts)
|
|
print(f" Initial pool size: {initial_pool_size}")
|
|
|
|
# Add prompts to pool
|
|
generator.add_prompts_to_pool(result)
|
|
|
|
# Check new pool size
|
|
new_pool_size = len(generator.pool_prompts)
|
|
print(f" New pool size: {new_pool_size}")
|
|
print(f" Added {new_pool_size - initial_pool_size} prompts")
|
|
|
|
# Check that prompts in pool have keys
|
|
print(f"\n3. Checking that prompts in pool have generated keys:")
|
|
for i, prompt_dict in enumerate(generator.pool_prompts[-len(result):]):
|
|
prompt_key = list(prompt_dict.keys())[0]
|
|
prompt_text = prompt_dict[prompt_key]
|
|
print(f" Prompt {i+1}: Key='{prompt_key}', Text='{prompt_text[:30]}...'")
|
|
assert prompt_key.startswith("poolprompt"), f"Key should start with 'poolprompt', got '{prompt_key}'"
|
|
|
|
print("\n4. Testing draw_prompts_from_pool:")
|
|
drawn_prompts = generator.draw_prompts_from_pool(count=2)
|
|
print(f" Drawn {len(drawn_prompts)} prompts from pool")
|
|
print(f" Pool size after drawing: {len(generator.pool_prompts)}")
|
|
|
|
# Check drawn prompts have keys
|
|
for i, prompt_dict in enumerate(drawn_prompts):
|
|
prompt_key = list(prompt_dict.keys())[0]
|
|
prompt_text = prompt_dict[prompt_key]
|
|
print(f" Drawn prompt {i+1}: Key='{prompt_key}', Text='{prompt_text[:30]}...'")
|
|
|
|
print("\n" + "="*60)
|
|
print("✅ All tests passed! New format works correctly.")
|
|
print("\nSummary:")
|
|
print("- AI returns prompts as a JSON list (no keys)")
|
|
print("- _parse_ai_response returns List[str]")
|
|
print("- add_prompts_to_pool generates keys locally (poolprompt000, poolprompt001, etc.)")
|
|
print("- draw_prompts_from_pool returns List[Dict[str, str]] with generated keys")
|
|
|
|
return True
|
|
|
|
if __name__ == "__main__":
|
|
test_new_format()
|
|
|
|
|