checkpoint before simplifying data

This commit is contained in:
2026-01-02 19:09:05 -07:00
parent 1222c4ab5a
commit d71883917c
8 changed files with 293 additions and 77 deletions

View File

@@ -147,24 +147,33 @@ class SimplePromptGenerator:
return full_prompt
def _parse_ai_response(self, response_content: str) -> List[Dict[str, str]]:
def _parse_ai_response(self, response_content: str) -> List[str]:
"""Parse the AI response to extract new prompts."""
try:
# Try to parse as JSON
data = json.loads(response_content)
# Convert to list of prompt dictionaries
new_prompts = []
for i in range(self.settings['num_prompts']):
key = f"newprompt{i}"
if key in data:
prompt_text = data[key]
prompt_obj = {
f"prompt{len(self.historic_prompts) + i:02d}": prompt_text
}
new_prompts.append(prompt_obj)
return new_prompts
# Check if data is a list (new format)
if isinstance(data, list):
# Return the list of prompt strings directly
# Ensure we have the correct number of prompts
if len(data) >= self.settings['num_prompts']:
return data[:self.settings['num_prompts']]
else:
print(f"Warning: AI returned {len(data)} prompts, expected {self.settings['num_prompts']}")
return data
elif isinstance(data, dict):
# Fallback for old format: dictionary with newprompt0, newprompt1, etc.
print("Warning: AI returned dictionary format, expected list format")
new_prompts = []
for i in range(self.settings['num_prompts']):
key = f"newprompt{i}"
if key in data:
new_prompts.append(data[key])
return new_prompts
else:
print(f"Warning: AI returned unexpected data type: {type(data)}")
return []
except json.JSONDecodeError:
# If not valid JSON, try to extract prompts from text
@@ -177,14 +186,11 @@ class SimplePromptGenerator:
for i, line in enumerate(lines[:self.settings['num_prompts']]):
line = line.strip()
if line and len(line) > 50:
prompt_obj = {
f"prompt{len(self.historic_prompts) + i:02d}": line
}
new_prompts.append(prompt_obj)
new_prompts.append(line)
return new_prompts
def generate_prompts(self) -> List[Dict[str, str]]:
def generate_prompts(self) -> List[str]:
"""Generate new journal prompts using AI."""
print("\nGenerating new journal prompts...")
@@ -217,11 +223,8 @@ class SimplePromptGenerator:
print("Error: Could not parse any prompts from AI response")
return []
# Add to historic prompts
self.historic_prompts.extend(new_prompts)
# Save updated history
self._save_historic_prompts()
# Note: Prompts are NOT added to historic_prompts here
# They will be added only when the user chooses one
return new_prompts