Cave is an AI-driven interactive storytelling system that creates dynamic, character-driven narratives. Watch as AI characters interact, develop relationships, and advance plots in real-time through natural dialogue generation.
- 🤖 AI Character Interactions: Characters speak naturally and respond to each other
- 🎭 Dynamic Storytelling: Plots evolve through character conversations
- 💬 Natural Dialogue: No repetitive introductions - real plot-driven conversations
- 💰 Cost Control: Choose between GPT-3.5-turbo (cheap) and GPT-4 (premium)
- 📊 Scene Management: Create scenes, add characters, and watch stories unfold
- 🔄 Continue Conversations: Add more dialogue rounds to develop plots
- 📝 Plot Export: Export your story as a markdown file
- 🎯 Relationship Tracking: Characters remember and react to each other
- Python 3.9+
- OpenAI API key
-
Clone the repository
git clone https://github.com/yourusername/cave.git cd cave -
Set up virtual environment
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Set up your OpenAI API key
cp env_example.txt .env # Edit .env and add your OpenAI API key -
Initialize the database
make db-init
-
Launch the backend
make run-backend
-
In a new terminal, start the interactive session
python test_interactive.py
-
Follow the prompts to:
- Create characters with personalities
- Set up scenes with context
- Generate conversations
- Continue dialogue
- Export your story
🤖 Current AI Model: gpt-3.5-turbo
📋 Available Actions:
1. Create new characters
2. Create new scene
3. View existing characters
4. View existing scenes
5. Start fresh conversation in a scene
6. Continue unified conversation (add more dialogue)
7. Individual character interaction
8. View scene timeline
9. Summarize scene
10. Change AI model
11. Export story to markdown
12. Exit
-
Create Characters (Option 1)
- Give them distinct personalities, backgrounds, goals, and fears
- Example: A curious journalist, a cautious local, a mysterious stranger
-
Create a Scene (Option 2)
- Set the environment, context, and mood
- Add 2-4 characters to the scene
- Example: "Mysterious Meeting at the Diner" with investigation context
-
Start Fresh Conversation (Option 5)
- Watch AI generate natural dialogue between characters
- No repetitive introductions - real plot development
-
Continue Conversation (Option 6)
- Add more dialogue rounds to develop the story
- Characters build on previous interactions
-
Summarize Scene (Option 9)
- Get AI analysis of character developments and plot points
-
Export Story (Option 11)
- Save your complete story as a markdown file
From Interactive Mode:
- Use Option 11 to export any scene as a markdown file
- Includes character details, scene summary, and complete dialogue
From Command Line:
python export_story.pyExport includes:
- Scene details and context
- Character profiles and backgrounds
- AI-generated scene summary
- Key events and character developments
- Complete dialogue with emotional states
- Plot advancement analysis
- GPT-3.5-turbo: ~$0.01-0.02 per conversation (recommended for testing)
- GPT-4: ~$0.10-0.15 per conversation (for important scenes)
- Switch models anytime with Option 10
🎭 Cave - Interactive Story Creation
==================================================
✅ Server is running!
🤖 Current AI Model: gpt-3.5-turbo
📋 Available Actions:
1. Create new characters
2. Create new scene
...
Choose an action (1-12): 1
👥 Creating New Characters
--------------------------
Enter character details:
Character name: Emma Chen
Personality: Curious journalist, determined investigator
Background: Recently arrived in town to investigate mysterious disappearances
Goals: Uncover the truth about the missing hiker
Fears: Getting too close to dangerous secrets
✅ Created character: Emma Chen
Choose an action (1-12): 2
🎬 Creating New Scene
---------------------
Scene title: First Meeting at the Diner
Environment: Cozy local diner with worn booths
Context: Emma meets locals to learn about town's mysterious history
Characters: Emma Chen, Sarah Martinez, Marcus Thompson
✅ Created scene: First Meeting at the Diner
Choose an action (1-12): 5
🎬 Starting fresh conversation in: First Meeting at the Diner
⚠️ This will clear any existing conversations in this scene.
Continue? (y/n): y
✅ Generated 4 interactions:
👤 Emma Chen (dialogue):
So, what can you tell me about the old mansion on the outskirts of town?
Emotional state: curious
👤 Sarah Martinez (dialogue):
Oh, you mean the Sinclair Manor? There are so many legends surrounding that place.
Emotional state: intrigued
👤 Marcus Thompson (dialogue):
The Sinclair family's history is shrouded in mystery. Tragedy seemed to follow them.
Emotional state: thoughtful
👤 Emma Chen (dialogue):
Do you think there's any truth to the rumors of ghosts haunting the mansion?
Emotional state: skeptical
Cave/
├── backend/ # FastAPI backend
│ ├── main.py # API endpoints
│ ├── ai_engine.py # AI conversation generation
│ ├── models.py # Database models
│ └── database.py # Database setup
├── test_interactive.py # Interactive terminal interface
├── export_story.py # Standalone story exporter
├── requirements.txt # Python dependencies
├── Makefile # Development commands
└── README.md # This file
make run-backend # Start the backend server
make db-init # Initialize the database
make install # Install dependencies
make test # Run testsPOST /characters/- Create charactersPOST /scenes/- Create scenesPOST /scenes/{id}/conversation/start- Start fresh conversationPOST /scenes/{id}/conversation/continue- Continue conversationPOST /scenes/{id}/summarize- Summarize sceneGET /ai/model- Get current AI modelPOST /ai/model- Change AI model
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with FastAPI, SQLAlchemy, and OpenAI API
- Inspired by interactive fiction and AI storytelling
- Designed for writers, storytellers, and AI enthusiasts
Ready to create your own AI-driven story? Start with the terminal interface and watch your characters come to life! 🎭✨