Quick Start Guide

Complete guide from v1.0.0 to v2.2.2 — Build stories step by step

Version Timeline: v1.0.0 (Core) → v2.0.0 (LLM) → v2.1.0 (Memory) → v2.2.0 (Exporters) → v2.2.1 (Templates) → v2.2.2 (CLI)

v1.0.0 - Core Features

Step 1: Installation

bash
git clone https://github.com/miladrezanezhad/story-toolkit.git
cd story-toolkit
pip install -r requirements.txt

# Or install directly
pip install -e .

Step 2: Create Your First Story

python
from story_toolkit import StoryToolkit

# Create toolkit instance
toolkit = StoryToolkit()

# Create a fantasy story
story = toolkit.create_story(genre="fantasy", theme="courage")

print(story["metadata"]["genre"])   # "fantasy"
print(story["metadata"]["theme"])   # "courage"

Step 3: Add Characters

python
# Add hero
hero = toolkit.add_character_to_story(story, "Kai", "protagonist")
hero.add_trait("brave")
hero.add_trait("determined")
hero.add_goal("Save the kingdom")
hero.add_skill("sword_mastery")
hero.add_fear("darkness")

# Add villain
villain = toolkit.add_character_to_story(story, "Shadow Lord", "antagonist")
villain.add_trait("cunning")
villain.add_trait("ruthless")
villain.add_goal("Conquer the realm")

# Create relationship
hero.add_relationship("Shadow Lord", "enemy", strength=9)

print(f"Hero: {hero.name}, Traits: {hero.personality_traits}")
print(f"Villain: {villain.name}, Goal: {villain.goals[0]}")
Output:
Hero: Kai, Traits: ['brave', 'determined']
Villain: Shadow Lord, Goal: Conquer the realm

Step 4: Generate Dialogue

python
# Generate conflict dialogue
dialogue = toolkit.dialogue_gen.generate_dialogue(
    "Kai", "Shadow Lord",
    context="conflict",
    mood="tense"
)

for line in dialogue:
    print(line)
Output:
Kai: I can't believe you would do this!
Shadow Lord: You left me no choice.
Kai: There's always a choice. You just chose wrong.

Step 5: Build a World

python
from story_toolkit.core.world_builder import WorldBuilder

world = WorldBuilder()
world.create_world("Eldoria", "fantasy")

# Add locations
world.add_location("Crystal City", "Ancient metropolis", "city")
world.add_location("Shadow Forest", "Mysterious woods", "forest")
world.add_location("Dragon's Peak", "Smoking volcano", "mountain")

# Connect locations
world.connect_locations("Crystal City", "Shadow Forest")

# Add rules
world.add_rule("magical", "Only pure hearts can use magic")
world.add_rule("social", "The Council of Seven rules")

# Add faction
world.add_faction(
    "Shadow Guild",
    "Secret organization",
    goals=["control_magic", "overthrow_council"]
)

summary = world.get_world_summary()
print(f"Locations: {summary['total_locations']}")

Step 6: Check Coherence

python
report = toolkit.check_story_coherence(story)

print(f"Coherence Score: {report['overall_score']:.0%}")

if report['plot_holes']:
    print("Plot holes found:")
    for hole in report['plot_holes']:
        print(f"  - {hole}")

if report['recommendations']:
    print("Recommendations:")
    for rec in report['recommendations']:
        print(f"  💡 {rec}")
Output:
Coherence Score: 100%
Recommendations:
💡 Story appears coherent - maintain this quality throughout!

Step 7: Save & Export

python
from story_toolkit.utils.helpers import save_story, export_to_markdown

# Save as JSON
save_story(story, "my_story.json")

# Export as Markdown
export_to_markdown(story, "my_story.md")

# Or use toolkit method
toolkit.export_story(story, format="json", filename="my_story")
v1.0.0 Complete! You've built a story with characters, world, dialogue, and coherence checking!

v2.0.0 - LLM Layer (AI Integration)

Install with LLM Support

bash
pip install story-toolkit[openai]      # OpenAI support
pip install story-toolkit[anthropic]   # Anthropic support
pip install story-toolkit[local]       # Local LLM (Ollama)
pip install story-toolkit[all]         # All backends

Mock Backend (Testing - No API Key)

python
from story_toolkit.llm import LLMFactory, LLMProvider

# Create mock backend (no API key needed)
llm = LLMFactory.create_backend(provider=LLMProvider.MOCK)
toolkit = StoryToolkit(llm_backend=llm)

# Check LLM status
status = toolkit.get_llm_status()
print(status)  # {'available': True, 'provider': 'mock', 'model': 'mock'}

Advanced Dialogue Generation

python
# Generate advanced dialogue with different styles
styles = ["natural", "dramatic", "poetic", "humorous"]

for style in styles:
    dialogue = toolkit.dialogue_gen.generate_dialogue(
        "Knight", "Dragon",
        context="final_battle",
        use_advanced=True,
        style=style,
        num_lines=4
    )
    print(f"\n--- {style.upper()} ---")
    for line in dialogue:
        print(line)
Output:

--- NATURAL ---
Knight: Hello Dragon.
Dragon: Knight. I've been expecting you.
Knight: Then you know why I'm here.
Dragon: Yes. The time has come.

--- DRAMATIC ---
Knight: I can't believe what you've done!
Dragon: You left me no choice, Knight.
Knight: There's always a choice. You chose wrong.
Dragon: We'll see who was wrong in the end.

Local LLM with Ollama (Free)

bash
# First install Ollama
ollama pull llama2

# Then use in Python
llm = LLMFactory.create_backend(
    provider=LLMProvider.LOCAL,
    model="llama2",
    temperature=0.7
)
toolkit = StoryToolkit(llm_backend=llm)

OpenAI Integration (Real AI)

python
import os
os.environ["OPENAI_API_KEY"] = "sk-..."

llm = LLMFactory.create_backend(
    provider=LLMProvider.OPENAI,
    model="gpt-3.5-turbo",
    temperature=0.8
)
toolkit = StoryToolkit(llm_backend=llm)

dialogue = toolkit.generate_advanced_dialogue(
    "Hero", "Villain",
    context="betrayal",
    style="dramatic"
)
v2.0.0 Complete! You can now generate AI-powered dialogues with multiple styles!

v2.1.0 - Memory Layer (SQLite)

Enable SQLite Memory

python
# Create toolkit with memory
toolkit = StoryToolkit(memory_backend="sqlite", db_path="stories.db")

# Create story and auto-save to memory
story = toolkit.create_story(
    genre="fantasy",
    theme="courage",
    name="My Epic Story",
    save_to_memory=True
)

Add Events to Timeline

python
# Add events to story timeline
toolkit.add_event(chapter=1, description="Kai finds the ancient map", importance=9)
toolkit.add_event(chapter=2, description="Shadow Lord attacks the village", importance=10)
toolkit.add_event(chapter=3, description="Kai meets the mysterious mentor", importance=7)
toolkit.add_event(chapter=4, description="Training montage begins", importance=6)
toolkit.add_event(chapter=5, description="Final battle approaches", importance=10)

# View timeline
timeline = toolkit.get_timeline()
for event in timeline:
    stars = "⭐" * event.importance + "☆" * (10 - event.importance)
    print(f"Ch.{event.chapter:2d} [{stars}] {event.description}")
Output:
Ch. 1 [⭐⭐⭐⭐⭐⭐⭐⭐⭐☆] Kai finds the ancient map
Ch. 2 [⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐] Shadow Lord attacks the village
Ch. 3 [⭐⭐⭐⭐⭐⭐⭐☆☆☆] Kai meets the mysterious mentor
Ch. 4 [⭐⭐⭐⭐⭐⭐☆☆☆☆] Training montage begins
Ch. 5 [⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐] Final battle approaches

Manage Stories in Database

python
# List all stored stories
stories = toolkit.list_stored_stories()
for s in stories:
    print(f"📖 {s.name} (ID: {s.id}) - {s.genre}/{s.theme}")

# Load a story from memory
loaded = toolkit.load_story_from_memory(story_id)

# Add character to loaded story
new_hero = toolkit.add_character_to_story(loaded, "New Hero", "protagonist")

# Close connection when done
toolkit.close_memory()
v2.1.0 Complete! Your stories are now permanently stored in a SQLite database!

v2.2.0 - Exporters (PDF, EPUB, HTML, Bionic)

Install Export Dependencies

bash
pip install story-toolkit[export]
# Or individually:
pip install reportlab   # PDF export
pip install ebooklib    # EPUB export

Export to PDF (3 Styles)

python
from story_toolkit.exporters import PDFExporter, ExportConfig, PDFStyle

# Print style (for books)
config = ExportConfig(title="The Crystal Saga", author="Kai", pdf_style=PDFStyle.PRINT)
exporter = PDFExporter(config)
exporter.export(story, "story_print.pdf")

# Manuscript style (for publishers)
config.pdf_style = PDFStyle.MANUSCRIPT
exporter.export(story, "story_manuscript.pdf")

# eBook style (for screen reading)
config.pdf_style = PDFStyle.EBOOK
exporter.export(story, "story_ebook.pdf")

Export to EPUB (eBook)

python
from story_toolkit.exporters import EPUBExporter

config = ExportConfig(title="The Crystal Saga", author="Kai")
exporter = EPUBExporter(config)
exporter.export(story, "story.epub")

Export to HTML (4 Templates)

python
from story_toolkit.exporters import HTMLExporter, HTMLTemplate

templates = [
    (HTMLTemplate.MODERN, "story_modern.html"),
    (HTMLTemplate.CLASSIC, "story_classic.html"),
    (HTMLTemplate.DARK, "story_dark.html"),
    (HTMLTemplate.MINIMAL, "story_minimal.html")
]

for template, filename in templates:
    config = ExportConfig(title="My Story", author="Me", html_template=template)
    exporter = HTMLExporter(config)
    exporter.export(story, filename)
    print(f"✅ Created: {filename}")

Bionic Reading (Faster Reading)

python
from story_toolkit.exporters import to_bionic

text = "This is a normal sentence that can be read faster with Bionic Reading."

# Strength 1: bold first letter
bionic1 = to_bionic(text, strength=1)
print(bionic1)

# Strength 2: bold first two letters
bionic2 = to_bionic(text, strength=2)
print(bionic2)

# HTML output with <strong> tags
bionic_html = to_bionic(text, as_html=True)
print(bionic_html)
Output:
This is a normal sentence...
This is a normal sentence...
<strong>T</strong>his <strong>i</strong>s...
v2.2.0 Complete! Export your stories to PDF, EPUB, HTML, or use Bionic Reading!

v2.2.1 - Pre-built Story Templates

Available Templates

python
from story_toolkit import StoryToolkit

toolkit = StoryToolkit()

# List all templates
templates = toolkit.list_templates()
for t in templates:
    print(f"📋 {t['name']}: {t['stage_count']} stages - {t['genre']}")
Output:
📋 hero_journey: 12 stages - fantasy, adventure
📋 three_act: 3 stages - general
📋 mystery_clues: 5 stages - mystery
📋 romance_beat: 15 stages - romance
📋 horror_cycle: 6 stages - horror

Hero's Journey (12 Stages)

python
# Create epic fantasy story
story = toolkit.use_template("hero_journey", genre="fantasy", theme="redemption")

# View all 12 stages
for i, stage in enumerate(story['plot']['main_plot'], 1):
    print(f"{i}. {stage['name']}")
Output:
1. The Ordinary World
2. The Call to Adventure
3. Refusal of the Call
4. Meeting the Mentor
5. Crossing the Threshold
6. Tests, Allies, and Enemies
7. Approach to the Inmost Cave
8. The Ordeal
9. The Reward
10. The Road Back
11. The Resurrection
12. Return with the Elixir

Three Act Structure

python
story = toolkit.use_template("three_act", theme="revenge")

for stage in story['plot']['main_plot']:
    print(f"📍 {stage['name']}: {stage['description'][:60]}...")
Output:
📍 Act I: Setup: Introduction of characters, setting, and the initial situation...
📍 Act II: Confrontation: The protagonist faces obstacles, meets allies...
📍 Act III: Resolution: The climax occurs, loose ends are tied...

Mystery Structure

python
story = toolkit.use_template("mystery_clues", theme="whodunnit")

stages = story['plot']['main_plot']
print(f"📖 {len(stages)} stages for your mystery story:")
for stage in stages:
    print(f"   - {stage['name']}")
Output:
📖 5 stages for your mystery story:
- The Crime
- The Investigation Begins
- The False Trail
- The Breakthrough
- The Resolution
v2.2.1 Complete! Start writing instantly with 5 pre-built story templates!

v2.2.2 - CLI Tool (Command Line Interface)

Basic CLI Commands

bash
# Create a new story
story-toolkit story new --genre fantasy --theme courage

# Create story with specific complexity
story-toolkit story new --genre sci_fi --theme survival --complexity 5

# Save story to JSON file
story-toolkit story new --genre fantasy --theme courage --output my_story.json

# List all stories in database
story-toolkit story list

# List all available templates
story-toolkit template list

# Use a template
story-toolkit template use hero_journey

# Use template with custom theme
story-toolkit template use three_act --theme redemption --output three_act.json

Complete CLI Workflow Example

bash
# Step 1: Create a story using hero_journey template
story-toolkit template use hero_journey --genre fantasy --theme courage --output epic.json

# Step 2: Check what's in the story
# (Open epic.json or use Python to inspect)

# Step 3: List all your stories
story-toolkit story list

# Step 4: Load a story from database (if saved with memory)
story-toolkit story load --id abc123
v2.2.2 Complete! Use the command line for quick story generation without writing Python code!

Complete Integration Example (All Versions)

python
from story_toolkit import StoryToolkit
from story_toolkit.llm import LLMFactory, LLMProvider
from story_toolkit.exporters import PDFExporter, ExportConfig, PDFStyle

# 1. Create toolkit with LLM and Memory (v2.0.0 + v2.1.0)
llm = LLMFactory.create_backend(provider=LLMProvider.MOCK)
toolkit = StoryToolkit(llm_backend=llm, memory_backend="sqlite", db_path="my_stories.db")

# 2. Create story using template (v2.2.1)
story = toolkit.use_template("hero_journey", genre="fantasy", theme="redemption")

# 3. Add custom characters (v1.0.0)
hero = toolkit.add_character_to_story(story, "Kai", "protagonist")
hero.add_trait("brave")
hero.add_goal("Save the kingdom")

villain = toolkit.add_character_to_story(story, "Shadow Lord", "antagonist")
villain.add_trait("cunning")

# 4. Generate advanced dialogue (v2.0.0)
dialogue = toolkit.dialogue_gen.generate_dialogue(
    "Kai", "Shadow Lord",
    context="final_battle",
    use_advanced=True,
    style="dramatic",
    num_lines=8
)

# 5. Add to timeline (v2.1.0)
toolkit.add_event(1, "Hero discovers ancient map", "plot", 9)
toolkit.add_event(2, "Villain attacks village", "conflict", 10)
toolkit.add_event(3, "Hero meets mentor", "character_development", 7)

# 6. Check coherence (v1.0.0)
report = toolkit.check_story_coherence(story)
print(f"Coherence Score: {report['overall_score']:.0%}")

# 7. Export to PDF (v2.2.0)
config = ExportConfig(title="The Crystal Saga", author="Kai", pdf_style=PDFStyle.PRINT)
exporter = PDFExporter(config)
exporter.export(story, "crystal_saga.pdf")

# 8. View timeline
print("\n📅 Story Timeline:")
for event in toolkit.get_timeline():
    print(f"   Ch.{event.chapter}: {event.description}")

# 9. Close memory connection
toolkit.close_memory()

print("\n✅ Complete story created with all features!")
Output:
Coherence Score: 100%

📅 Story Timeline:
Ch.1: Hero discovers ancient map
Ch.2: Villain attacks village
Ch.3: Hero meets mentor

✅ Complete story created with all features!

📖 Next Steps

Easy Upgrade - No Breaking Changes!
All code written for v1.0.0 works perfectly in v2.2.2. Just upgrade with:
pip install --upgrade story-toolkit

Version Summary:
• v1.0.0: Core features (Character, Plot, World, Dialogue, Coherence)
• v2.0.0: LLM layer (AI-powered dialogue)
• v2.1.0: Memory layer (SQLite database)
• v2.2.0: Exporters (PDF, EPUB, HTML, Bionic)
• v2.2.1: Pre-built templates (5 structures)
• v2.2.2: CLI tool (Command line interface)