1. editor.py — Fix rewrite_chapter_content to use model_writer (was model_logic). Chapter rewrites now use the creative writing model, not the cheaper analysis model. 2. editor.py — evaluate_chapter_quality now uses keep_head=True so the evaluator sees the chapter opening (engagement hook, sensory anchoring) as well as the ending; long chapters no longer scored on tail only. 3. editor.py — Consistency analysis sampling upgraded to head+middle+tail (was head+tail), giving the LLM a complete view of each chapter's events. 4. writer.py — max_attempts is now adaptive: climax/resolution chapters (position >= 0.75) receive 3 refinement attempts; others keep 2. 5. writer.py — Polish-skip threshold tightened from 0.012 to 0.008 (1 filter word per 125 words vs. 1 per 83 words), so more borderline drafts are cleaned. 6. style_persona.py — Persona validation sample increased from 200 to 400 words for more reliable voice quality assessment. Version bumped: 3.0 → 3.1 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
70 lines
2.8 KiB
Python
70 lines
2.8 KiB
Python
import os
|
|
from dotenv import load_dotenv
|
|
|
|
# __file__ is core/config.py; app root is one level up
|
|
_HERE = os.path.dirname(os.path.abspath(__file__))
|
|
BASE_DIR = os.path.dirname(_HERE)
|
|
|
|
# Ensure .env is loaded from the app root
|
|
load_dotenv(os.path.join(BASE_DIR, ".env"))
|
|
|
|
def get_clean_env(key, default=None):
|
|
val = os.getenv(key, default)
|
|
return val.strip() if val else None
|
|
|
|
API_KEY = get_clean_env("GEMINI_API_KEY")
|
|
GCP_PROJECT = get_clean_env("GCP_PROJECT")
|
|
GCP_LOCATION = get_clean_env("GCP_LOCATION", "us-central1")
|
|
MODEL_LOGIC_HINT = get_clean_env("MODEL_LOGIC", "AUTO")
|
|
MODEL_WRITER_HINT = get_clean_env("MODEL_WRITER", "AUTO")
|
|
MODEL_ARTIST_HINT = get_clean_env("MODEL_ARTIST", "AUTO")
|
|
MODEL_IMAGE_HINT = get_clean_env("MODEL_IMAGE", "AUTO")
|
|
DEFAULT_BLUEPRINT = "book_def.json"
|
|
|
|
# --- SECURITY & ADMIN ---
|
|
FLASK_SECRET = get_clean_env("FLASK_SECRET_KEY", "dev-secret-key-change-this")
|
|
ADMIN_USER = get_clean_env("ADMIN_USERNAME")
|
|
ADMIN_PASSWORD = get_clean_env("ADMIN_PASSWORD")
|
|
|
|
if FLASK_SECRET == "dev-secret-key-change-this":
|
|
print("WARNING: Using default FLASK_SECRET_KEY. This is insecure for production.")
|
|
|
|
if not API_KEY: raise ValueError("CRITICAL ERROR: GEMINI_API_KEY not found in environment or .env file.")
|
|
|
|
# --- DATA DIRECTORIES ---
|
|
DATA_DIR = os.path.join(BASE_DIR, "data")
|
|
PROJECTS_DIR = os.path.join(DATA_DIR, "projects")
|
|
PERSONAS_DIR = os.path.join(DATA_DIR, "personas")
|
|
# PERSONAS_FILE is deprecated — persona data is now stored in the Persona DB table.
|
|
# PERSONAS_FILE = os.path.join(PERSONAS_DIR, "personas.json")
|
|
FONTS_DIR = os.path.join(DATA_DIR, "fonts")
|
|
|
|
# --- ENSURE DIRECTORIES EXIST ---
|
|
for d in [DATA_DIR, PROJECTS_DIR, PERSONAS_DIR, FONTS_DIR]:
|
|
if not os.path.exists(d): os.makedirs(d, exist_ok=True)
|
|
|
|
# --- AUTHENTICATION ---
|
|
GOOGLE_CREDS = os.getenv("GOOGLE_APPLICATION_CREDENTIALS")
|
|
if GOOGLE_CREDS:
|
|
if not os.path.isabs(GOOGLE_CREDS):
|
|
GOOGLE_CREDS = os.path.join(BASE_DIR, GOOGLE_CREDS)
|
|
|
|
if os.path.exists(GOOGLE_CREDS):
|
|
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = GOOGLE_CREDS
|
|
else:
|
|
print(f"Warning: GOOGLE_APPLICATION_CREDENTIALS file not found at: {GOOGLE_CREDS}")
|
|
|
|
# --- DEFINITIONS ---
|
|
LENGTH_DEFINITIONS = {
|
|
"01": {"label": "Chapter Book", "words": "5,000 - 10,000", "chapters": 10, "depth": 1},
|
|
"1": {"label": "Flash Fiction", "words": "500 - 1,500", "chapters": 1, "depth": 1},
|
|
"2": {"label": "Short Story", "words": "5,000 - 10,000", "chapters": 5, "depth": 1},
|
|
"2b": {"label": "Young Adult", "words": "50,000 - 70,000", "chapters": 25, "depth": 3},
|
|
"3": {"label": "Novella", "words": "20,000 - 40,000", "chapters": 15, "depth": 2},
|
|
"4": {"label": "Novel", "words": "60,000 - 80,000", "chapters": 30, "depth": 3},
|
|
"5": {"label": "Epic", "words": "100,000+", "chapters": 50, "depth": 4}
|
|
}
|
|
|
|
# --- SYSTEM ---
|
|
VERSION = "3.1"
|