feedback history and prompt work better
This commit is contained in:
@@ -31,6 +31,7 @@ class JournalPromptGenerator:
|
||||
self.historic_prompts = []
|
||||
self.pool_prompts = []
|
||||
self.feedback_words = []
|
||||
self.feedback_historic = []
|
||||
self.prompt_template = ""
|
||||
self.settings = {}
|
||||
|
||||
@@ -43,6 +44,7 @@ class JournalPromptGenerator:
|
||||
self._load_historic_prompts()
|
||||
self._load_pool_prompts()
|
||||
self._load_feedback_words()
|
||||
self._load_feedback_historic()
|
||||
|
||||
def _load_config(self):
|
||||
"""Load configuration from environment file."""
|
||||
@@ -164,11 +166,32 @@ class JournalPromptGenerator:
|
||||
self.console.print("[yellow]Warning: feedback_words.json is corrupted, starting with empty feedback words[/yellow]")
|
||||
self.feedback_words = []
|
||||
|
||||
def _load_feedback_historic(self):
|
||||
"""Load historic feedback words from JSON file."""
|
||||
try:
|
||||
with open("feedback_historic.json", "r") as f:
|
||||
self.feedback_historic = json.load(f)
|
||||
except FileNotFoundError:
|
||||
self.console.print("[yellow]Warning: feedback_historic.json not found, starting with empty feedback history[/yellow]")
|
||||
self.feedback_historic = []
|
||||
except json.JSONDecodeError:
|
||||
self.console.print("[yellow]Warning: feedback_historic.json is corrupted, starting with empty feedback history[/yellow]")
|
||||
self.feedback_historic = []
|
||||
|
||||
def _save_feedback_words(self):
|
||||
"""Save feedback words to JSON file."""
|
||||
with open("feedback_words.json", "w") as f:
|
||||
json.dump(self.feedback_words, f, indent=2)
|
||||
|
||||
def _save_feedback_historic(self):
|
||||
"""Save historic feedback words to JSON file (keeping only first 30)."""
|
||||
# Keep only the first 30 feedback words (newest are at the beginning)
|
||||
if len(self.feedback_historic) > 30:
|
||||
self.feedback_historic = self.feedback_historic[:30]
|
||||
|
||||
with open("feedback_historic.json", "w") as f:
|
||||
json.dump(self.feedback_historic, f, indent=2)
|
||||
|
||||
def _save_pool_prompts(self):
|
||||
"""Save pool prompts to JSON file."""
|
||||
with open("prompts_pool.json", "w") as f:
|
||||
@@ -237,6 +260,54 @@ class JournalPromptGenerator:
|
||||
self.historic_prompts = updated_prompts
|
||||
self._save_historic_prompts()
|
||||
|
||||
def add_feedback_words_to_history(self):
|
||||
"""
|
||||
Add current feedback words to the historic feedback words cyclic buffer.
|
||||
The 6 new feedback words become feedback00-feedback05, all others shift down,
|
||||
and feedback29 is discarded (keeping only 30 items total).
|
||||
"""
|
||||
# Extract just the words from the current feedback words
|
||||
# Current feedback_words structure: [{"feedback00": "word", "weight": 3}, ...]
|
||||
new_feedback_words = []
|
||||
|
||||
for i, feedback_item in enumerate(self.feedback_words):
|
||||
# Get the word from the feedback item (key is feedback00, feedback01, etc.)
|
||||
feedback_key = f"feedback{i:02d}"
|
||||
if feedback_key in feedback_item:
|
||||
word = feedback_item[feedback_key]
|
||||
# Create new feedback word object with just the word (no weight)
|
||||
new_feedback_words.append({
|
||||
feedback_key: word
|
||||
})
|
||||
|
||||
# If we don't have 6 feedback words, we can't add them to history
|
||||
if len(new_feedback_words) != 6:
|
||||
self.console.print(f"[yellow]Warning: Expected 6 feedback words, got {len(new_feedback_words)}. Not adding to history.[/yellow]")
|
||||
return
|
||||
|
||||
# Shift all existing feedback words down by 6 positions
|
||||
# We'll create a new list starting with the 6 new feedback words
|
||||
updated_feedback_historic = new_feedback_words
|
||||
|
||||
# Add all existing feedback words, shifting their numbers down by 6
|
||||
for i, feedback_dict in enumerate(self.feedback_historic):
|
||||
if i >= 24: # We only keep 30 feedback words total (00-29), and we've already added 6
|
||||
break
|
||||
|
||||
# Get the feedback word
|
||||
feedback_key = list(feedback_dict.keys())[0]
|
||||
word = feedback_dict[feedback_key]
|
||||
|
||||
# Create feedback word with new number (shifted down by 6)
|
||||
new_feedback_key = f"feedback{i+6:02d}"
|
||||
updated_feedback_historic.append({
|
||||
new_feedback_key: word
|
||||
})
|
||||
|
||||
self.feedback_historic = updated_feedback_historic
|
||||
self._save_feedback_historic()
|
||||
self.console.print("[green]Added 6 feedback words to history[/green]")
|
||||
|
||||
def _parse_ai_response(self, response_content: str) -> List[str]:
|
||||
"""
|
||||
Parse the AI response to extract new prompts.
|
||||
@@ -534,10 +605,15 @@ class JournalPromptGenerator:
|
||||
historic_context = json.dumps(self.historic_prompts, indent=2)
|
||||
full_prompt = f"{feedback_template}\n\nPrevious prompts:\n{historic_context}"
|
||||
|
||||
# Add feedback words if available
|
||||
# Add current feedback words if available (with weights)
|
||||
if self.feedback_words:
|
||||
feedback_context = json.dumps(self.feedback_words, indent=2)
|
||||
full_prompt = f"{full_prompt}\n\nPrevious feedback themes:\n{feedback_context}"
|
||||
full_prompt = f"{full_prompt}\n\nCurrent feedback themes (with weights):\n{feedback_context}"
|
||||
|
||||
# Add historic feedback words if available (just words, no weights)
|
||||
if self.feedback_historic:
|
||||
feedback_historic_context = json.dumps(self.feedback_historic, indent=2)
|
||||
full_prompt = f"{full_prompt}\n\nHistoric feedback themes (just words):\n{feedback_historic_context}"
|
||||
else:
|
||||
self.console.print("[yellow]Warning: No historic prompts available for feedback analysis[/yellow]")
|
||||
return []
|
||||
@@ -665,6 +741,9 @@ class JournalPromptGenerator:
|
||||
self._save_feedback_words()
|
||||
self.console.print(f"[green]Updated feedback words with {len(new_feedback_items)} items[/green]")
|
||||
|
||||
# Also add the new feedback words to the historic buffer
|
||||
self.add_feedback_words_to_history()
|
||||
|
||||
def display_prompts(self, prompts: List[str]):
|
||||
"""Display generated prompts in a nice format."""
|
||||
self.console.print("\n" + "="*60)
|
||||
|
||||
Reference in New Issue
Block a user