Repository navigation
Expand file tree
/
Copy pathgen_world.py
More file actions
126 lines (105 loc) · 4.99 KB
/
Copy pathgen_world.py
File metadata and controls
126 lines (105 loc) · 4.99 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
#!/usr/bin/env python3
"""
One-shot world.md generator for foundation phase.
Reads seed.txt + voice.md, calls the writer model, outputs world.md content.
"""
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")
API_KEY = os.environ.get("ANTHROPIC_API_KEY", "")
API_BASE = os.environ.get("AUTONOVEL_API_BASE_URL", "https://api.anthropic.com")
def call_writer(prompt, max_tokens=16000):
import httpx
headers = {
"x-api-key": API_KEY,
"anthropic-version": "2023-06-01",
"content-type": "application/json",
}
payload = {
"model": WRITER_MODEL,
"max_tokens": max_tokens,
"temperature": 0.7,
"system": (
"You are a fantasy worldbuilder with deep knowledge of Sanderson's Laws, "
"Le Guin's prose philosophy, and TTRPG-quality lore design. "
"You write world bibles that are specific, interconnected, and imply depth "
"beyond what's stated. You never use AI slop words (delve, tapestry, myriad, etc). "
"You write in clean, direct prose. Every rule has a cost. Every cultural detail "
"implies a history. Every location has a sensory signature."
),
"messages": [{"role": "user", "content": prompt}],
}
resp = httpx.post(f"{API_BASE}/v1/messages", headers=headers, json=payload, timeout=300)
resp.raise_for_status()
return resp.json()["content"][0]["text"]
seed = (BASE_DIR / "seed.txt").read_text()
voice = (BASE_DIR / "voice.md").read_text()
craft = (BASE_DIR / "CRAFT.md").read_text()
# Extract voice Part 2 only (the novel-specific voice)
voice_lines = voice.split('\n')
part2_start = next(i for i, l in enumerate(voice_lines) if 'Part 2' in l)
voice_part2 = '\n'.join(voice_lines[part2_start:])
prompt = f"""Build a complete world bible for this fantasy novel. This is the WORLD.MD file --
the definitive reference for everything that EXISTS in this world. A writer should be able
to resolve any worldbuilding question from this document alone.
SEED CONCEPT:
{seed}
VOICE IDENTITY (the tone and register of this novel):
{voice_part2}
CRAFT REQUIREMENTS (from CRAFT.md -- follow these):
- Magic system needs HARD RULES with COSTS and LIMITATIONS per Sanderson's Second Law
- Limitations >= powers in narrative prominence
- Trace implications of magic through society, economy, law, religion
- At least 2-3 societal implications of magic explored in depth
- History must create PRESENT-DAY TENSIONS that drive the plot (not just backdrop)
- Geography must be specific and sensory (not generic fantasy)
- Iceberg principle: imply more than you state
- Interconnection: pulling one thread should move everything
STRUCTURE THE DOCUMENT WITH THESE SECTIONS:
## Cosmology & History
A timeline of major events. Focus on events that create PRESENT-DAY tensions.
Include the founding myth, key turning points, and recent events that matter to the plot.
## Magic System
### Hard Rules (Tonal Law)
Specific, testable rules. What intervals do what. What progressions bind.
What happens when you break the rules. Include COSTS and LIMITATIONS prominently.
### Soft Magic (Cass's Gift)
What he perceives, how it works, what it costs HIM specifically.
This should be mysterious but have consistent internal logic.
### Societal Implications
How does tonal law shape: governance, commerce, education, class structure,
crime, family life, childhood, aging, disability?
## Geography
Cantamura's physical layout, districts, the natural amphitheater's acoustic properties.
Neighboring places (at least 2-3). Sensory signatures for each location.
## Factions & Politics
Who holds power, who wants it, who's being crushed by it.
At least 3-4 factions with opposing interests.
## Bestiary / Flora / Natural World
What's unique about the natural world in and around Cantamura?
## Cultural Details
Customs, taboos, festivals, food, clothing, coming-of-age rituals.
Things that make daily life feel SPECIFIC.
## Internal Consistency Rules
Hard constraints a writer must not violate. The physics of sound in this world.
What's possible and what's not.
IMPORTANT:
- Be SPECIFIC. Not "the city has districts" but name them, describe them,
give them sensory signatures.
- Every rule should have a COST or LIMITATION stated alongside it.
- Include 2-3 facts per section that are unexplained, hinting at deeper systems
(iceberg depth).
- Facts should INTERCONNECT: the magic should shape the politics, the geography
should shape the culture, the history should explain current faction conflicts.
- Write in clean, direct prose. No AI slop. No "rich tapestry." No "delving."
- The world should feel grounded and LIVED-IN, not imagined. Think: what does
breakfast smell like? What do children play? How do old people complain?
- Target ~3000-4000 words. Dense, not padded.
"""
print("Calling writer model...", file=sys.stderr)
result = call_writer(prompt)
print(result)