working checkpoint before caching attempt
This commit is contained in:
@@ -4,5 +4,6 @@ Topics can be diverse.
|
|||||||
The prompts should be between 500 and 1000 characters.
|
The prompts should be between 500 and 1000 characters.
|
||||||
The previous 60 prompts have been provided as a JSON array for reference. Attempt minimal repetition, but some thematic overlap is acceptable. Newly generated prompts should try extra hard to avoid repetition in previous prompts with the lowest indices.
|
The previous 60 prompts have been provided as a JSON array for reference. Attempt minimal repetition, but some thematic overlap is acceptable. Newly generated prompts should try extra hard to avoid repetition in previous prompts with the lowest indices.
|
||||||
|
|
||||||
Output as a JSON array with key names from "newprompt0" to "newprompt5".
|
Output as a JSON array with key names from "newprompt0" to "newpromptN" where N is the number of prompts minus one.
|
||||||
|
Respond ONLY with valid JSON. No explanations, no markdown, no backticks.
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import os
|
|||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
|
import configparser
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import List, Dict, Any, Optional
|
from typing import List, Dict, Any, Optional
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -31,9 +32,11 @@ class JournalPromptGenerator:
|
|||||||
self.client = None
|
self.client = None
|
||||||
self.historic_prompts = []
|
self.historic_prompts = []
|
||||||
self.prompt_template = ""
|
self.prompt_template = ""
|
||||||
|
self.settings = {}
|
||||||
|
|
||||||
# Load configuration
|
# Load configuration
|
||||||
self._load_config()
|
self._load_config()
|
||||||
|
self._load_settings()
|
||||||
|
|
||||||
# Load data files
|
# Load data files
|
||||||
self._load_prompt_template()
|
self._load_prompt_template()
|
||||||
@@ -62,11 +65,61 @@ class JournalPromptGenerator:
|
|||||||
base_url=self.base_url
|
base_url=self.base_url
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _load_settings(self):
|
||||||
|
"""Load settings from settings.cfg configuration file."""
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
|
||||||
|
# Set default values
|
||||||
|
self.settings = {
|
||||||
|
'min_length': 500,
|
||||||
|
'max_length': 1000,
|
||||||
|
'num_prompts': 6
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
config.read('settings.cfg')
|
||||||
|
|
||||||
|
if 'prompts' in config:
|
||||||
|
prompts_section = config['prompts']
|
||||||
|
|
||||||
|
# Load min_length
|
||||||
|
if 'min_length' in prompts_section:
|
||||||
|
self.settings['min_length'] = int(prompts_section['min_length'])
|
||||||
|
|
||||||
|
# Load max_length
|
||||||
|
if 'max_length' in prompts_section:
|
||||||
|
self.settings['max_length'] = int(prompts_section['max_length'])
|
||||||
|
|
||||||
|
# Load num_prompts
|
||||||
|
if 'num_prompts' in prompts_section:
|
||||||
|
self.settings['num_prompts'] = int(prompts_section['num_prompts'])
|
||||||
|
|
||||||
|
except FileNotFoundError:
|
||||||
|
self.console.print("[yellow]Warning: settings.cfg not found, using default values[/yellow]")
|
||||||
|
except ValueError as e:
|
||||||
|
self.console.print(f"[yellow]Warning: Invalid value in settings.cfg: {e}, using default values[/yellow]")
|
||||||
|
except Exception as e:
|
||||||
|
self.console.print(f"[yellow]Warning: Error reading settings.cfg: {e}, using default values[/yellow]")
|
||||||
|
|
||||||
def _load_prompt_template(self):
|
def _load_prompt_template(self):
|
||||||
"""Load the prompt template from ds_prompt.txt."""
|
"""Load the prompt template from ds_prompt.txt and update with config values."""
|
||||||
try:
|
try:
|
||||||
with open("ds_prompt.txt", "r") as f:
|
with open("ds_prompt.txt", "r") as f:
|
||||||
self.prompt_template = f.read()
|
template = f.read()
|
||||||
|
|
||||||
|
# Replace hardcoded values with config values
|
||||||
|
template = template.replace(
|
||||||
|
"between 500 and 1000 characters",
|
||||||
|
f"between {self.settings['min_length']} and {self.settings['max_length']} characters"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Replace the number of prompts (6) with config value
|
||||||
|
template = template.replace(
|
||||||
|
"Please generate 6 writing prompts",
|
||||||
|
f"Please generate {self.settings['num_prompts']} writing prompts"
|
||||||
|
)
|
||||||
|
|
||||||
|
self.prompt_template = template
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
self.console.print("[red]Error: ds_prompt.txt not found[/red]")
|
self.console.print("[red]Error: ds_prompt.txt not found[/red]")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@@ -154,7 +207,7 @@ class JournalPromptGenerator:
|
|||||||
def _parse_ai_response(self, response_content: str) -> List[Dict[str, str]]:
|
def _parse_ai_response(self, response_content: str) -> List[Dict[str, str]]:
|
||||||
"""
|
"""
|
||||||
Parse the AI response to extract new prompts.
|
Parse the AI response to extract new prompts.
|
||||||
Expected format: JSON array with keys "newprompt0" to "newprompt5"
|
Expected format: JSON array with keys "newprompt0" to "newpromptN" where N = num_prompts-1
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# Try to parse as JSON
|
# Try to parse as JSON
|
||||||
@@ -162,7 +215,7 @@ class JournalPromptGenerator:
|
|||||||
|
|
||||||
# Convert to list of prompt dictionaries
|
# Convert to list of prompt dictionaries
|
||||||
new_prompts = []
|
new_prompts = []
|
||||||
for i in range(6):
|
for i in range(self.settings['num_prompts']):
|
||||||
key = f"newprompt{i}"
|
key = f"newprompt{i}"
|
||||||
if key in data:
|
if key in data:
|
||||||
prompt_text = data[key]
|
prompt_text = data[key]
|
||||||
@@ -176,12 +229,14 @@ class JournalPromptGenerator:
|
|||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
# If not valid JSON, try to extract prompts from text
|
# If not valid JSON, try to extract prompts from text
|
||||||
self.console.print("[yellow]Warning: AI response is not valid JSON, attempting to extract prompts...[/yellow]")
|
self.console.print("[yellow]Warning: AI response is not valid JSON, attempting to extract prompts...[/yellow]")
|
||||||
|
self.console.print(f"[yellow]Full response content for debugging:[/yellow]")
|
||||||
|
self.console.print(f"[yellow]{response_content}[/yellow]")
|
||||||
|
|
||||||
# Look for patterns in the text
|
# Look for patterns in the text
|
||||||
lines = response_content.strip().split('\n')
|
lines = response_content.strip().split('\n')
|
||||||
new_prompts = []
|
new_prompts = []
|
||||||
|
|
||||||
for i, line in enumerate(lines[:6]): # Take first 6 non-empty lines
|
for i, line in enumerate(lines[:self.settings['num_prompts']]): # Take first N non-empty lines
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line and len(line) > 50: # Reasonable minimum length for a prompt
|
if line and len(line) > 50: # Reasonable minimum length for a prompt
|
||||||
prompt_obj = {
|
prompt_obj = {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
[prompts]
|
[prompts]
|
||||||
min_length = 500
|
min_length = 500
|
||||||
max_length = 1000
|
max_length = 1000
|
||||||
num_prompts = 3
|
num_prompts = 8
|
||||||
|
|
||||||
# Prefetch not yet implmented
|
# Prefetch not yet implmented
|
||||||
[prefetch]
|
[prefetch]
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import os
|
|||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
|
import configparser
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import List, Dict, Any
|
from typing import List, Dict, Any
|
||||||
|
|
||||||
@@ -24,9 +25,11 @@ class SimplePromptGenerator:
|
|||||||
self.client = None
|
self.client = None
|
||||||
self.historic_prompts = []
|
self.historic_prompts = []
|
||||||
self.prompt_template = ""
|
self.prompt_template = ""
|
||||||
|
self.settings = {}
|
||||||
|
|
||||||
# Load configuration
|
# Load configuration
|
||||||
self._load_config()
|
self._load_config()
|
||||||
|
self._load_settings()
|
||||||
|
|
||||||
# Load data files
|
# Load data files
|
||||||
self._load_prompt_template()
|
self._load_prompt_template()
|
||||||
@@ -55,11 +58,61 @@ class SimplePromptGenerator:
|
|||||||
base_url=self.base_url
|
base_url=self.base_url
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _load_settings(self):
|
||||||
|
"""Load settings from settings.cfg configuration file."""
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
|
||||||
|
# Set default values
|
||||||
|
self.settings = {
|
||||||
|
'min_length': 500,
|
||||||
|
'max_length': 1000,
|
||||||
|
'num_prompts': 6
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
config.read('settings.cfg')
|
||||||
|
|
||||||
|
if 'prompts' in config:
|
||||||
|
prompts_section = config['prompts']
|
||||||
|
|
||||||
|
# Load min_length
|
||||||
|
if 'min_length' in prompts_section:
|
||||||
|
self.settings['min_length'] = int(prompts_section['min_length'])
|
||||||
|
|
||||||
|
# Load max_length
|
||||||
|
if 'max_length' in prompts_section:
|
||||||
|
self.settings['max_length'] = int(prompts_section['max_length'])
|
||||||
|
|
||||||
|
# Load num_prompts
|
||||||
|
if 'num_prompts' in prompts_section:
|
||||||
|
self.settings['num_prompts'] = int(prompts_section['num_prompts'])
|
||||||
|
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("Warning: settings.cfg not found, using default values")
|
||||||
|
except ValueError as e:
|
||||||
|
print(f"Warning: Invalid value in settings.cfg: {e}, using default values")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Warning: Error reading settings.cfg: {e}, using default values")
|
||||||
|
|
||||||
def _load_prompt_template(self):
|
def _load_prompt_template(self):
|
||||||
"""Load the prompt template from ds_prompt.txt."""
|
"""Load the prompt template from ds_prompt.txt and update with config values."""
|
||||||
try:
|
try:
|
||||||
with open("ds_prompt.txt", "r") as f:
|
with open("ds_prompt.txt", "r") as f:
|
||||||
self.prompt_template = f.read()
|
template = f.read()
|
||||||
|
|
||||||
|
# Replace hardcoded values with config values
|
||||||
|
template = template.replace(
|
||||||
|
"between 500 and 1000 characters",
|
||||||
|
f"between {self.settings['min_length']} and {self.settings['max_length']} characters"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Replace the number of prompts (6) with config value
|
||||||
|
template = template.replace(
|
||||||
|
"Please generate 6 writing prompts",
|
||||||
|
f"Please generate {self.settings['num_prompts']} writing prompts"
|
||||||
|
)
|
||||||
|
|
||||||
|
self.prompt_template = template
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print("Error: ds_prompt.txt not found")
|
print("Error: ds_prompt.txt not found")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@@ -100,7 +153,7 @@ class SimplePromptGenerator:
|
|||||||
|
|
||||||
# Convert to list of prompt dictionaries
|
# Convert to list of prompt dictionaries
|
||||||
new_prompts = []
|
new_prompts = []
|
||||||
for i in range(6):
|
for i in range(self.settings['num_prompts']):
|
||||||
key = f"newprompt{i}"
|
key = f"newprompt{i}"
|
||||||
if key in data:
|
if key in data:
|
||||||
prompt_text = data[key]
|
prompt_text = data[key]
|
||||||
@@ -119,7 +172,7 @@ class SimplePromptGenerator:
|
|||||||
lines = response_content.strip().split('\n')
|
lines = response_content.strip().split('\n')
|
||||||
new_prompts = []
|
new_prompts = []
|
||||||
|
|
||||||
for i, line in enumerate(lines[:6]):
|
for i, line in enumerate(lines[:self.settings['num_prompts']]):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line and len(line) > 50:
|
if line and len(line) > 50:
|
||||||
prompt_obj = {
|
prompt_obj = {
|
||||||
@@ -226,7 +279,7 @@ def main():
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--save", "-S",
|
"--save", "-S",
|
||||||
type=int,
|
type=int,
|
||||||
help="Save a specific prompt number to file (1-6)"
|
help="Save a specific prompt number to file"
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--config", "-c",
|
"--config", "-c",
|
||||||
|
|||||||
@@ -80,8 +80,8 @@ def test_prompt_template():
|
|||||||
if len(content) > 0:
|
if len(content) > 0:
|
||||||
print(f" ✓ ds_prompt.txt is readable ({len(content)} characters)")
|
print(f" ✓ ds_prompt.txt is readable ({len(content)} characters)")
|
||||||
|
|
||||||
# Check for key phrases
|
# Check for key phrases (now configurable, so just check for basic structure)
|
||||||
key_phrases = ["6 writing prompts", "500 and 1000 characters", "JSON array"]
|
key_phrases = ["writing prompts", "characters", "JSON array"]
|
||||||
found_phrases = []
|
found_phrases = []
|
||||||
for phrase in key_phrases:
|
for phrase in key_phrases:
|
||||||
if phrase.lower() in content.lower():
|
if phrase.lower() in content.lower():
|
||||||
|
|||||||
@@ -4,11 +4,29 @@ Test script to verify the prompt numbering logic.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import configparser
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
def get_num_prompts():
|
||||||
|
"""Get the number of prompts from settings.cfg or default."""
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
num_prompts = 6 # Default value
|
||||||
|
|
||||||
|
try:
|
||||||
|
config.read('settings.cfg')
|
||||||
|
if 'prompts' in config and 'num_prompts' in config['prompts']:
|
||||||
|
num_prompts = int(config['prompts']['num_prompts'])
|
||||||
|
except (FileNotFoundError, ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
return num_prompts
|
||||||
|
|
||||||
def test_renumbering():
|
def test_renumbering():
|
||||||
"""Test the renumbering logic."""
|
"""Test the renumbering logic."""
|
||||||
|
|
||||||
|
# Get number of prompts from config
|
||||||
|
num_prompts = get_num_prompts()
|
||||||
|
|
||||||
# Create a sample historic prompts list
|
# Create a sample historic prompts list
|
||||||
historic_prompts = []
|
historic_prompts = []
|
||||||
for i in range(60):
|
for i in range(60):
|
||||||
@@ -19,10 +37,11 @@ def test_renumbering():
|
|||||||
print(f"Original prompts: {len(historic_prompts)}")
|
print(f"Original prompts: {len(historic_prompts)}")
|
||||||
print(f"First prompt key: {list(historic_prompts[0].keys())[0]}")
|
print(f"First prompt key: {list(historic_prompts[0].keys())[0]}")
|
||||||
print(f"Last prompt key: {list(historic_prompts[-1].keys())[0]}")
|
print(f"Last prompt key: {list(historic_prompts[-1].keys())[0]}")
|
||||||
|
print(f"Number of prompts from config: {num_prompts}")
|
||||||
|
|
||||||
# Simulate adding 6 new prompts (as the current code would create them)
|
# Simulate adding new prompts (as the current code would create them)
|
||||||
new_prompts = []
|
new_prompts = []
|
||||||
for i in range(6):
|
for i in range(num_prompts):
|
||||||
new_prompts.append({
|
new_prompts.append({
|
||||||
f"prompt{len(historic_prompts) + i:02d}": f"New prompt {i}"
|
f"prompt{len(historic_prompts) + i:02d}": f"New prompt {i}"
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user