Files
daily-journal-prompt/demonstrate_feedback_historic.py

120 lines
4.5 KiB
Python

#!/usr/bin/env python3
"""
Demonstration of the feedback_historic.json cyclic buffer system.
"""
import json
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from generate_prompts import JournalPromptGenerator
def demonstrate_system():
"""Demonstrate the feedback historic system."""
print("="*70)
print("DEMONSTRATION: Feedback Historic Cyclic Buffer System")
print("="*70)
# Create a temporary .env file
with open(".env.demo", "w") as f:
f.write("DEEPSEEK_API_KEY=demo_key\n")
f.write("API_BASE_URL=https://api.deepseek.com\n")
f.write("MODEL=deepseek-chat\n")
# Initialize generator
generator = JournalPromptGenerator(config_path=".env.demo")
print("\n1. Initial state:")
print(f" - feedback_words: {len(generator.feedback_words)} items")
print(f" - feedback_historic: {len(generator.feedback_historic)} items")
# Create some sample feedback words
sample_words_batch1 = [
{"feedback00": "memory", "weight": 5},
{"feedback01": "time", "weight": 4},
{"feedback02": "nature", "weight": 3},
{"feedback03": "emotion", "weight": 6},
{"feedback04": "change", "weight": 2},
{"feedback05": "connection", "weight": 4}
]
print("\n2. Adding first batch of feedback words...")
generator.update_feedback_words(sample_words_batch1)
print(f" - Added 6 feedback words")
print(f" - feedback_historic now has: {len(generator.feedback_historic)} items")
# Show the historic items
print("\n Historic feedback words (no weights):")
for i, item in enumerate(generator.feedback_historic):
key = list(item.keys())[0]
print(f" {key}: {item[key]}")
# Add second batch
sample_words_batch2 = [
{"feedback00": "creativity", "weight": 5},
{"feedback01": "reflection", "weight": 4},
{"feedback02": "growth", "weight": 3},
{"feedback03": "transformation", "weight": 6},
{"feedback04": "journey", "weight": 2},
{"feedback05": "discovery", "weight": 4}
]
print("\n3. Adding second batch of feedback words...")
generator.update_feedback_words(sample_words_batch2)
print(f" - Added 6 more feedback words")
print(f" - feedback_historic now has: {len(generator.feedback_historic)} items")
print("\n Historic feedback words after second batch:")
print(" (New words at the top, old words shifted down)")
for i, item in enumerate(generator.feedback_historic[:12]): # Show first 12
key = list(item.keys())[0]
print(f" {key}: {item[key]}")
# Demonstrate the cyclic buffer by adding more batches
print("\n4. Demonstrating cyclic buffer (30 item limit)...")
print(" Adding 5 more batches (30 more words total)...")
for batch_num in range(3, 8):
batch_words = []
for j in range(6):
batch_words.append({f"feedback{j:02d}": f"batch{batch_num}_word{j+1}", "weight": 3})
generator.update_feedback_words(batch_words)
print(f" - feedback_historic now has: {len(generator.feedback_historic)} items (max 30)")
print(f" - Oldest items have been dropped to maintain 30-item limit")
# Show the structure
print("\n5. Checking file structure...")
if os.path.exists("feedback_historic.json"):
with open("feedback_historic.json", "r") as f:
data = json.load(f)
print(f" - feedback_historic.json exists with {len(data)} items")
print(f" - First item: {data[0]}")
print(f" - Last item: {data[-1]}")
print(f" - Items have keys (feedback00, feedback01, etc.) but no weights")
# Clean up
os.remove(".env.demo")
if os.path.exists("feedback_words.json"):
os.remove("feedback_words.json")
if os.path.exists("feedback_historic.json"):
os.remove("feedback_historic.json")
print("\n" + "="*70)
print("SUMMARY:")
print("="*70)
print("✓ feedback_historic.json stores previous feedback words (no weights)")
print("✓ Maximum of 30 items (feedback00-feedback29)")
print("✓ When new feedback is generated (6 words):")
print(" - They become feedback00-feedback05 in the historic buffer")
print(" - All existing items shift down by 6 positions")
print(" - Items beyond feedback29 are discarded")
print("✓ Historic feedback words are included in AI prompts for")
print(" generate_theme_feedback_words() to avoid repetition")
print("="*70)
if __name__ == "__main__":
demonstrate_system()