working checkpoint before caching attempt

This commit is contained in:
2026-01-02 16:13:06 -07:00
parent 5cea0ba44c
commit 6dc8672dd8
6 changed files with 144 additions and 16 deletions

View File

@@ -8,6 +8,7 @@ import os
import json
import sys
import argparse
import configparser
from datetime import datetime
from typing import List, Dict, Any
@@ -24,9 +25,11 @@ class SimplePromptGenerator:
self.client = None
self.historic_prompts = []
self.prompt_template = ""
self.settings = {}
# Load configuration
self._load_config()
self._load_settings()
# Load data files
self._load_prompt_template()
@@ -55,11 +58,61 @@ class SimplePromptGenerator:
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):
"""Load the prompt template from ds_prompt.txt."""
"""Load the prompt template from ds_prompt.txt and update with config values."""
try:
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:
print("Error: ds_prompt.txt not found")
sys.exit(1)
@@ -100,7 +153,7 @@ class SimplePromptGenerator:
# Convert to list of prompt dictionaries
new_prompts = []
for i in range(6):
for i in range(self.settings['num_prompts']):
key = f"newprompt{i}"
if key in data:
prompt_text = data[key]
@@ -119,7 +172,7 @@ class SimplePromptGenerator:
lines = response_content.strip().split('\n')
new_prompts = []
for i, line in enumerate(lines[:6]):
for i, line in enumerate(lines[:self.settings['num_prompts']]):
line = line.strip()
if line and len(line) > 50:
prompt_obj = {
@@ -226,7 +279,7 @@ def main():
parser.add_argument(
"--save", "-S",
type=int,
help="Save a specific prompt number to file (1-6)"
help="Save a specific prompt number to file"
)
parser.add_argument(
"--config", "-c",