Repository navigation
Expand file tree
/
Copy pathseed.py
More file actions
147 lines (123 loc) · 5.23 KB
/
Copy pathseed.py
File metadata and controls
147 lines (123 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env python3
"""
seed.py -- Generate fantasy novel seed concepts.
Usage:
uv run python seed.py # Generate 10 concepts, pick one
uv run python seed.py --count=5 # Generate 5 concepts
uv run python seed.py --riff "magic costs memories" # Riff on an idea
"""
import argparse
import json
import os
import sys
from pathlib import Path
from dotenv import load_dotenv
BASE_DIR = Path(__file__).parent
load_dotenv(BASE_DIR / ".env")
WRITER_MODEL = os.environ.get("AUTONOVEL_WRITER_MODEL", "claude-sonnet-4-6-20250217")
ANTHROPIC_API_KEY = os.environ.get("ANTHROPIC_API_KEY", "")
API_BASE_URL = os.environ.get("AUTONOVEL_API_BASE_URL", "https://api.anthropic.com")
ANTHROPIC_BETA = "context-1m-2025-08-07"
def call_writer(prompt, max_tokens=4000):
import httpx
headers = {
"x-api-key": ANTHROPIC_API_KEY,
"anthropic-version": "2023-06-01",
"anthropic-beta": ANTHROPIC_BETA,
"content-type": "application/json",
}
payload = {
"model": WRITER_MODEL,
"max_tokens": max_tokens,
"temperature": 1.0, # high temp for creative diversity
"system": (
"You are a fantasy novelist with deep knowledge of the genre's "
"best works -- Tolkien, Le Guin, Rothfuss, Wolfe, Jemisin, Peake, "
"Susanna Clarke, Andrew Peterson, Sofia Samatar. You generate "
"novel concepts that are SPECIFIC, SURPRISING, and STRUCTURALLY "
"SOUND. You never propose generic medieval Europe + elves. Each "
"concept should make a reader think 'I've never seen THAT before.'"
),
"messages": [{"role": "user", "content": prompt}],
}
resp = httpx.post(
f"{API_BASE_URL}/v1/messages",
headers=headers,
json=payload,
timeout=120,
)
resp.raise_for_status()
return resp.json()["content"][0]["text"]
GENERATE_PROMPT = """Generate {count} fantasy novel seed concepts. Each should be
a complete premise you could build a novel from.
For EACH concept, provide:
NUMBER. TITLE (a working title, evocative, not generic)
HOOK: One sentence that would make someone pick up the book. Specific
and surprising, not "In a world where..."
WORLD: What makes this world different? Not just "there's magic" but
what specific, unusual thing defines this place? Be concrete --
salt flats, inverted towers, cities that migrate, a sea that
remembers, whatever. Make it SENSORY.
MAGIC/COST: What is the core speculative element and what does it
COST? Per Sanderson's Second Law, limitations > powers. The cost
should create interesting dilemmas.
TENSION: What's the central conflict? It must be both PERSONAL (one
character's specific problem) and COSMIC (affects the world).
These two must be in tension with each other.
THEME: What question does this story explore? Not a message -- a
genuine question with no easy answer.
WHY IT'S NOT GENERIC: One sentence on what makes this different from
standard fantasy fare.
Aim for DIVERSITY across the {count} concepts:
- At least one with a non-human-centric world
- At least one that's more literary/quiet than epic
- At least one with an unusual narrative structure idea
- At least one set outside the typical European-inspired setting
- Mix of tones: dark, warm, weird, melancholy, whimsical
DO NOT generate:
- Chosen one prophecies (unless subverted in an interesting way)
- Dark lord / ultimate evil as the main antagonist
- Medieval Europe + elves/dwarves/orcs
- "Academy" or "school for magic" settings
- Love triangles as the central plot
"""
RIFF_PROMPT = """I have a seed idea for a fantasy novel:
"{idea}"
Generate 5 variations on this concept. Keep what's interesting about
the core idea but push it in different directions. For each variation:
NUMBER. TITLE
HOOK: One sentence.
HOW IT DIFFERS: What did you change from the original seed and why?
WORLD: Concrete, sensory world details.
MAGIC/COST: The speculative element and its cost.
TENSION: Personal + cosmic conflict.
THEME: The question it explores.
Make the variations genuinely different from each other -- don't just
tweak surface details. Change the protagonist, the setting, the tone,
the structure, the thematic focus.
"""
def main():
parser = argparse.ArgumentParser(description="Generate novel seed concepts")
parser.add_argument("--count", type=int, default=10,
help="Number of concepts to generate (default: 10)")
parser.add_argument("--riff", type=str, default=None,
help="Riff on an existing idea")
args = parser.parse_args()
if not ANTHROPIC_API_KEY:
print("ERROR: Set ANTHROPIC_API_KEY in .env first")
sys.exit(1)
if args.riff:
print(f"Riffing on: {args.riff}\n")
prompt = RIFF_PROMPT.format(idea=args.riff)
else:
print(f"Generating {args.count} seed concepts...\n")
prompt = GENERATE_PROMPT.format(count=args.count)
result = call_writer(prompt, max_tokens=8000)
print(result)
print("\n" + "=" * 60)
print("To pick a seed, copy the concept you like into seed.txt:")
print(" nano seed.txt")
print("Or remix several concepts into your own seed.")
print("Then proceed to Step 2 in WORKFLOW.md.")
if __name__ == "__main__":
main()