pre feedback checkpoint
This commit is contained in:
@@ -30,6 +30,7 @@ class JournalPromptGenerator:
|
||||
self.client = None
|
||||
self.historic_prompts = []
|
||||
self.pool_prompts = []
|
||||
self.feedback_words = []
|
||||
self.prompt_template = ""
|
||||
self.settings = {}
|
||||
|
||||
@@ -41,6 +42,7 @@ class JournalPromptGenerator:
|
||||
self._load_prompt_template()
|
||||
self._load_historic_prompts()
|
||||
self._load_pool_prompts()
|
||||
self._load_feedback_words()
|
||||
|
||||
def _load_config(self):
|
||||
"""Load configuration from environment file."""
|
||||
@@ -150,6 +152,18 @@ class JournalPromptGenerator:
|
||||
self.console.print("[yellow]Warning: pool_prompts.json is corrupted, starting with empty pool[/yellow]")
|
||||
self.pool_prompts = []
|
||||
|
||||
def _load_feedback_words(self):
|
||||
"""Load feedback words from JSON file."""
|
||||
try:
|
||||
with open("feedback_words.json", "r") as f:
|
||||
self.feedback_words = json.load(f)
|
||||
except FileNotFoundError:
|
||||
self.console.print("[yellow]Warning: feedback_words.json not found, starting with empty feedback words[/yellow]")
|
||||
self.feedback_words = []
|
||||
except json.JSONDecodeError:
|
||||
self.console.print("[yellow]Warning: feedback_words.json is corrupted, starting with empty feedback words[/yellow]")
|
||||
self.feedback_words = []
|
||||
|
||||
def _save_pool_prompts(self):
|
||||
"""Save pool prompts to JSON file."""
|
||||
with open("pool_prompts.json", "w") as f:
|
||||
@@ -186,22 +200,6 @@ class JournalPromptGenerator:
|
||||
return drawn_prompts
|
||||
|
||||
|
||||
def show_pool_stats(self):
|
||||
"""Show statistics about the prompt pool."""
|
||||
total_prompts = len(self.pool_prompts)
|
||||
|
||||
table = Table(title="Prompt Pool Statistics")
|
||||
table.add_column("Metric", style="cyan")
|
||||
table.add_column("Value", style="green")
|
||||
|
||||
table.add_row("Prompts in pool", str(total_prompts))
|
||||
table.add_row("Prompts per session", str(self.settings['num_prompts']))
|
||||
table.add_row("Target pool size", str(self.settings['cached_pool_volume']))
|
||||
table.add_row("Available sessions", str(total_prompts // self.settings['num_prompts']))
|
||||
|
||||
self.console.print(table)
|
||||
|
||||
|
||||
def add_prompt_to_history(self, prompt_text: str):
|
||||
"""
|
||||
Add a single prompt to the historic prompts cyclic buffer.
|
||||
@@ -243,6 +241,11 @@ class JournalPromptGenerator:
|
||||
else:
|
||||
full_prompt = self.prompt_template
|
||||
|
||||
# Add feedback words if available
|
||||
if self.feedback_words:
|
||||
feedback_context = json.dumps(self.feedback_words, indent=2)
|
||||
full_prompt = f"{full_prompt}\n\nFeedback words:\n{feedback_context}"
|
||||
|
||||
return full_prompt
|
||||
|
||||
def _parse_ai_response(self, response_content: str) -> List[str]:
|
||||
@@ -439,6 +442,11 @@ class JournalPromptGenerator:
|
||||
else:
|
||||
full_prompt = f"{template}\n\n{prompt_instruction}"
|
||||
|
||||
# Add feedback words if available
|
||||
if self.feedback_words:
|
||||
feedback_context = json.dumps(self.feedback_words, indent=2)
|
||||
full_prompt = f"{full_prompt}\n\nFeedback words:\n{feedback_context}"
|
||||
|
||||
return full_prompt
|
||||
|
||||
def _parse_ai_response_with_count(self, response_content: str, expected_count: int) -> List[str]:
|
||||
@@ -537,19 +545,33 @@ class JournalPromptGenerator:
|
||||
self.console.print(panel)
|
||||
self.console.print() # Empty line between prompts
|
||||
|
||||
def show_history_stats(self):
|
||||
"""Show statistics about prompt history."""
|
||||
total_prompts = len(self.historic_prompts)
|
||||
def show_combined_stats(self):
|
||||
"""Show combined statistics about both prompt pool and history."""
|
||||
# Pool statistics
|
||||
total_pool_prompts = len(self.pool_prompts)
|
||||
pool_table = Table(title="Prompt Pool Statistics")
|
||||
pool_table.add_column("Metric", style="cyan")
|
||||
pool_table.add_column("Value", style="green")
|
||||
|
||||
table = Table(title="Prompt History Statistics")
|
||||
table.add_column("Metric", style="cyan")
|
||||
table.add_column("Value", style="green")
|
||||
pool_table.add_row("Prompts in pool", str(total_pool_prompts))
|
||||
pool_table.add_row("Prompts per session", str(self.settings['num_prompts']))
|
||||
pool_table.add_row("Target pool size", str(self.settings['cached_pool_volume']))
|
||||
pool_table.add_row("Available sessions", str(total_pool_prompts // self.settings['num_prompts']))
|
||||
|
||||
table.add_row("Total prompts in history", str(total_prompts))
|
||||
table.add_row("History capacity", "60 prompts")
|
||||
table.add_row("Available slots", str(max(0, 60 - total_prompts)))
|
||||
# History statistics
|
||||
total_history_prompts = len(self.historic_prompts)
|
||||
history_table = Table(title="Prompt History Statistics")
|
||||
history_table.add_column("Metric", style="cyan")
|
||||
history_table.add_column("Value", style="green")
|
||||
|
||||
self.console.print(table)
|
||||
history_table.add_row("Total prompts in history", str(total_history_prompts))
|
||||
history_table.add_row("History capacity", "60 prompts")
|
||||
history_table.add_row("Available slots", str(max(0, 60 - total_history_prompts)))
|
||||
|
||||
# Display both tables
|
||||
self.console.print(pool_table)
|
||||
self.console.print() # Empty line between tables
|
||||
self.console.print(history_table)
|
||||
|
||||
def interactive_mode(self):
|
||||
"""Run in interactive mode with user prompts."""
|
||||
@@ -575,11 +597,10 @@ class JournalPromptGenerator:
|
||||
self.console.print("\n[bold]Options:[/bold]")
|
||||
self.console.print("1. Draw prompts from pool (no API call)")
|
||||
self.console.print("2. Fill prompt pool using API")
|
||||
self.console.print("3. View pool statistics")
|
||||
self.console.print("4. View history statistics")
|
||||
self.console.print("5. Exit")
|
||||
self.console.print("3. View combined statistics")
|
||||
self.console.print("4. Exit")
|
||||
|
||||
choice = Prompt.ask("\nEnter your choice", choices=["1", "2", "3", "4", "5"], default="1")
|
||||
choice = Prompt.ask("\nEnter your choice", choices=["1", "2", "3", "4"], default="1")
|
||||
|
||||
if choice == "1":
|
||||
# Draw prompts from pool
|
||||
@@ -610,12 +631,9 @@ class JournalPromptGenerator:
|
||||
self.console.print("[yellow]No prompts were added to pool[/yellow]")
|
||||
|
||||
elif choice == "3":
|
||||
self.show_pool_stats()
|
||||
self.show_combined_stats()
|
||||
|
||||
elif choice == "4":
|
||||
self.show_history_stats()
|
||||
|
||||
elif choice == "5":
|
||||
self.console.print("[green]Goodbye! Happy journaling! 📓[/green]")
|
||||
break
|
||||
|
||||
@@ -636,12 +654,7 @@ def main():
|
||||
parser.add_argument(
|
||||
"--stats", "-s",
|
||||
action="store_true",
|
||||
help="Show history statistics"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--pool-stats", "-p",
|
||||
action="store_true",
|
||||
help="Show pool statistics"
|
||||
help="Show combined statistics (pool and history)"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--fill-pool", "-f",
|
||||
@@ -655,9 +668,7 @@ def main():
|
||||
generator = JournalPromptGenerator(config_path=args.config)
|
||||
|
||||
if args.stats:
|
||||
generator.show_history_stats()
|
||||
elif args.pool_stats:
|
||||
generator.show_pool_stats()
|
||||
generator.show_combined_stats()
|
||||
elif args.fill_pool:
|
||||
# Fill prompt pool to target volume using API
|
||||
total_added = generator.fill_pool_to_target()
|
||||
|
||||
Reference in New Issue
Block a user