story-toolkit 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- story_toolkit-2.0.0/LICENSE +21 -0
- story_toolkit-2.0.0/PKG-INFO +511 -0
- story_toolkit-2.0.0/README.md +453 -0
- story_toolkit-2.0.0/examples/__init__.py +13 -0
- story_toolkit-2.0.0/examples/advanced_example.py +484 -0
- story_toolkit-2.0.0/examples/example.py +515 -0
- story_toolkit-2.0.0/examples/simple_example.py +92 -0
- story_toolkit-2.0.0/llm/__init__.py +14 -0
- story_toolkit-2.0.0/llm/backends/__init__.py +6 -0
- story_toolkit-2.0.0/llm/backends/anthropic_backend.py +66 -0
- story_toolkit-2.0.0/llm/backends/local_backend.py +120 -0
- story_toolkit-2.0.0/llm/backends/mock_backend.py +103 -0
- story_toolkit-2.0.0/llm/backends/openai_backend.py +101 -0
- story_toolkit-2.0.0/llm/base.py +97 -0
- story_toolkit-2.0.0/llm/factory.py +130 -0
- story_toolkit-2.0.0/llm/prompts/__init__.py +1 -0
- story_toolkit-2.0.0/llm/prompts/dialogue_prompts.py +1 -0
- story_toolkit-2.0.0/pyproject.toml +99 -0
- story_toolkit-2.0.0/setup.cfg +4 -0
- story_toolkit-2.0.0/setup.py +124 -0
- story_toolkit-2.0.0/story_toolkit/__init__.py +223 -0
- story_toolkit-2.0.0/story_toolkit/__main__.py +38 -0
- story_toolkit-2.0.0/story_toolkit/core/__init__.py +14 -0
- story_toolkit-2.0.0/story_toolkit/core/character.py +189 -0
- story_toolkit-2.0.0/story_toolkit/core/plot.py +165 -0
- story_toolkit-2.0.0/story_toolkit/core/story_engine.py +249 -0
- story_toolkit-2.0.0/story_toolkit/core/world_builder.py +222 -0
- story_toolkit-2.0.0/story_toolkit/generators/__init__.py +13 -0
- story_toolkit-2.0.0/story_toolkit/generators/character_generator.py +187 -0
- story_toolkit-2.0.0/story_toolkit/generators/dialogue_generator.py +394 -0
- story_toolkit-2.0.0/story_toolkit/generators/plot_generator.py +192 -0
- story_toolkit-2.0.0/story_toolkit/llm/__init__.py +18 -0
- story_toolkit-2.0.0/story_toolkit/llm/backends/__init__.py +10 -0
- story_toolkit-2.0.0/story_toolkit/llm/backends/mock_backend.py +67 -0
- story_toolkit-2.0.0/story_toolkit/llm/base.py +85 -0
- story_toolkit-2.0.0/story_toolkit/llm/factory.py +62 -0
- story_toolkit-2.0.0/story_toolkit/nlp/__init__.py +11 -0
- story_toolkit-2.0.0/story_toolkit/nlp/coherence_checker.py +452 -0
- story_toolkit-2.0.0/story_toolkit/nlp/text_analyzer.py +275 -0
- story_toolkit-2.0.0/story_toolkit/utils/__init__.py +10 -0
- story_toolkit-2.0.0/story_toolkit/utils/helpers.py +181 -0
- story_toolkit-2.0.0/story_toolkit.egg-info/PKG-INFO +511 -0
- story_toolkit-2.0.0/story_toolkit.egg-info/SOURCES.txt +51 -0
- story_toolkit-2.0.0/story_toolkit.egg-info/dependency_links.txt +1 -0
- story_toolkit-2.0.0/story_toolkit.egg-info/entry_points.txt +2 -0
- story_toolkit-2.0.0/story_toolkit.egg-info/not-zip-safe +1 -0
- story_toolkit-2.0.0/story_toolkit.egg-info/requires.txt +32 -0
- story_toolkit-2.0.0/story_toolkit.egg-info/top_level.txt +4 -0
- story_toolkit-2.0.0/tests/__init__.py +12 -0
- story_toolkit-2.0.0/tests/test_core.py +222 -0
- story_toolkit-2.0.0/tests/test_full_comprehensive.py +628 -0
- story_toolkit-2.0.0/tests/test_generators.py +142 -0
- story_toolkit-2.0.0/tests/test_nlp.py +150 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Milad Rezanezhad
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: story-toolkit
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: A comprehensive toolkit for generating engaging and coherent stories with optional LLM support
|
|
5
|
+
Home-page: https://github.com/miladrezanezhad/story-toolkit
|
|
6
|
+
Author: Milad Rezanezhad
|
|
7
|
+
Author-email: Milad Rezanezhad <milad.rezanezhad@example.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/miladrezanezhad/story-toolkit
|
|
10
|
+
Project-URL: Bug Reports, https://github.com/miladrezanezhad/story-toolkit/issues
|
|
11
|
+
Project-URL: Source, https://github.com/miladrezanezhad/story-toolkit
|
|
12
|
+
Project-URL: Documentation, https://miladrezanezhad.github.io/story-toolkit/
|
|
13
|
+
Keywords: story,writing,narrative,dialogue,character,plot,world-building,nlp,creative-writing,fiction,story-generator,llm,openai,claude
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
18
|
+
Classifier: Topic :: Artistic Software
|
|
19
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Operating System :: OS Independent
|
|
25
|
+
Requires-Python: >=3.8
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: nltk>=3.8.1
|
|
29
|
+
Requires-Dist: spacy>=3.7.0
|
|
30
|
+
Requires-Dist: textblob>=0.17.1
|
|
31
|
+
Requires-Dist: pydantic>=2.5.0
|
|
32
|
+
Requires-Dist: pyyaml>=6.0
|
|
33
|
+
Provides-Extra: openai
|
|
34
|
+
Requires-Dist: openai>=1.0.0; extra == "openai"
|
|
35
|
+
Provides-Extra: anthropic
|
|
36
|
+
Requires-Dist: anthropic>=0.18.0; extra == "anthropic"
|
|
37
|
+
Provides-Extra: local
|
|
38
|
+
Requires-Dist: ollama>=0.1.0; extra == "local"
|
|
39
|
+
Provides-Extra: llm
|
|
40
|
+
Requires-Dist: openai>=1.0.0; extra == "llm"
|
|
41
|
+
Requires-Dist: anthropic>=0.18.0; extra == "llm"
|
|
42
|
+
Requires-Dist: ollama>=0.1.0; extra == "llm"
|
|
43
|
+
Provides-Extra: dev
|
|
44
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
45
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
46
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
47
|
+
Requires-Dist: pytest-mock>=3.11.0; extra == "dev"
|
|
48
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
49
|
+
Requires-Dist: isort>=5.12.0; extra == "dev"
|
|
50
|
+
Requires-Dist: flake8>=6.0.0; extra == "dev"
|
|
51
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
52
|
+
Provides-Extra: all
|
|
53
|
+
Requires-Dist: story-toolkit[anthropic,dev,local,openai]; extra == "all"
|
|
54
|
+
Dynamic: author
|
|
55
|
+
Dynamic: home-page
|
|
56
|
+
Dynamic: license-file
|
|
57
|
+
Dynamic: requires-python
|
|
58
|
+
|
|
59
|
+
# 📚 Story Development Toolkit
|
|
60
|
+
|
|
61
|
+
[](https://github.com/miladrezanezhad/story-toolkit/actions/workflows/tests.yml)
|
|
62
|
+
[](https://www.python.org/)
|
|
63
|
+
[](LICENSE)
|
|
64
|
+
[](https://github.com/miladrezanezhad/story-toolkit/releases)
|
|
65
|
+
[](https://github.com/miladrezanezhad)
|
|
66
|
+
|
|
67
|
+
**A comprehensive Python toolkit for generating engaging and coherent stories with optional LLM support.**
|
|
68
|
+
|
|
69
|
+
Story Development Toolkit provides tools for character creation, plot generation, dialogue writing, world building, and story coherence analysis — all in one package. **NEW in v2.0.0:** Optional integration with OpenAI, Anthropic, and local LLMs!
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## 🌐 Language
|
|
74
|
+
|
|
75
|
+
This README is also available in:
|
|
76
|
+
|
|
77
|
+
| Language | File |
|
|
78
|
+
|----------|------|
|
|
79
|
+
| 🇮🇷 **Persian (فارسی)** | [README_FA.md](README_FA.md) |
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## ✨ Features
|
|
84
|
+
|
|
85
|
+
| Feature | Description |
|
|
86
|
+
|---------|-------------|
|
|
87
|
+
| 🎭 **Character Creation** | Build complex characters with traits, goals, skills, fears, relationships |
|
|
88
|
+
| 📚 **Plot Generation** | Generate story structures for fantasy, mystery, romance, adventure, sci-fi |
|
|
89
|
+
| 💬 **Dialogue Writing** | Create natural dialogues with context-aware templates |
|
|
90
|
+
| 🌍 **World Building** | Design detailed fictional worlds with locations, cultures, rules, factions |
|
|
91
|
+
| 🔍 **Coherence Checking** | Identify plot holes, character inconsistencies, timeline issues |
|
|
92
|
+
| 📊 **Text Analysis** | Analyze readability, pacing, dialogue balance, vocabulary richness |
|
|
93
|
+
| 🤖 **LLM Support** | Optional integration with OpenAI, Anthropic, and local models (NEW in v2.0.0) |
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## 📦 Installation
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# Basic installation (no LLM)
|
|
101
|
+
pip install story-toolkit
|
|
102
|
+
|
|
103
|
+
# With OpenAI support (GPT-4, GPT-3.5)
|
|
104
|
+
pip install story-toolkit[openai]
|
|
105
|
+
|
|
106
|
+
# With Anthropic support (Claude)
|
|
107
|
+
pip install story-toolkit[anthropic]
|
|
108
|
+
|
|
109
|
+
# With local LLM support (Ollama, llama.cpp)
|
|
110
|
+
pip install story-toolkit[local]
|
|
111
|
+
|
|
112
|
+
# Full installation (all LLM backends)
|
|
113
|
+
pip install story-toolkit[all]
|
|
114
|
+
|
|
115
|
+
# Or install from source
|
|
116
|
+
git clone https://github.com/miladrezanezhad/story-toolkit.git
|
|
117
|
+
cd story-toolkit
|
|
118
|
+
pip install -e .
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## 🚀 Quick Start
|
|
124
|
+
|
|
125
|
+
### Basic Usage (No LLM - v1 compatible)
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
from story_toolkit import StoryToolkit
|
|
129
|
+
|
|
130
|
+
# Create toolkit instance
|
|
131
|
+
toolkit = StoryToolkit()
|
|
132
|
+
|
|
133
|
+
# Create a story
|
|
134
|
+
story = toolkit.create_story(genre="fantasy", theme="courage")
|
|
135
|
+
|
|
136
|
+
# Add a hero
|
|
137
|
+
hero = toolkit.add_character_to_story(story, "Kai", "protagonist")
|
|
138
|
+
hero.add_trait("brave")
|
|
139
|
+
hero.add_goal("Save the kingdom")
|
|
140
|
+
|
|
141
|
+
# Generate dialogue (template-based)
|
|
142
|
+
dialogue = toolkit.dialogue_gen.generate_dialogue(
|
|
143
|
+
"Kai", "Villain", context="conflict"
|
|
144
|
+
)
|
|
145
|
+
for line in dialogue:
|
|
146
|
+
print(line)
|
|
147
|
+
|
|
148
|
+
# Check coherence
|
|
149
|
+
report = toolkit.check_story_coherence(story)
|
|
150
|
+
print(f"Coherence Score: {report['overall_score']:.0%}")
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
**Output:**
|
|
154
|
+
```
|
|
155
|
+
Kai: I can't believe you would do this!
|
|
156
|
+
Villain: You left me no choice.
|
|
157
|
+
Kai: There's always a choice. You just chose wrong.
|
|
158
|
+
Coherence Score: 100%
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Advanced Usage (With LLM - NEW in v2.0.0)
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
from story_toolkit import StoryToolkit
|
|
165
|
+
from story_toolkit.llm import LLMFactory, LLMProvider
|
|
166
|
+
|
|
167
|
+
# Create LLM backend (Mock for testing, no API key needed)
|
|
168
|
+
llm = LLMFactory.create_backend(provider=LLMProvider.MOCK)
|
|
169
|
+
toolkit = StoryToolkit(llm_backend=llm)
|
|
170
|
+
|
|
171
|
+
# Generate advanced dialogue with LLM
|
|
172
|
+
dialogue = toolkit.dialogue_gen.generate_dialogue(
|
|
173
|
+
"Kai", "Villain",
|
|
174
|
+
context="final_battle",
|
|
175
|
+
use_advanced=True, # Enable LLM
|
|
176
|
+
style="dramatic",
|
|
177
|
+
num_lines=8
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
for line in dialogue:
|
|
181
|
+
print(line)
|
|
182
|
+
|
|
183
|
+
# Check LLM status
|
|
184
|
+
print(f"LLM Status: {toolkit.get_llm_status()}")
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
**Output:**
|
|
188
|
+
```
|
|
189
|
+
Kai: I can't believe what you've done!
|
|
190
|
+
Villain: You left me no choice, Kai.
|
|
191
|
+
Kai: There's always a choice. You chose wrong.
|
|
192
|
+
Villain: We'll see who was wrong in the end.
|
|
193
|
+
Kai: This isn't over.
|
|
194
|
+
LLM Status: {'available': True, 'provider': 'mock', 'model': 'mock'}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## 🤖 LLM Backends
|
|
200
|
+
|
|
201
|
+
v2.0.0 supports multiple LLM providers:
|
|
202
|
+
|
|
203
|
+
| Provider | Installation | API Key Required |
|
|
204
|
+
|----------|--------------|------------------|
|
|
205
|
+
| **Mock** | Included | ❌ No (for testing) |
|
|
206
|
+
| **OpenAI** | `pip install story-toolkit[openai]` | ✅ Yes |
|
|
207
|
+
| **Anthropic** | `pip install story-toolkit[anthropic]` | ✅ Yes |
|
|
208
|
+
| **Local (Ollama)** | `pip install story-toolkit[local]` | ❌ No (free) |
|
|
209
|
+
|
|
210
|
+
### Example with OpenAI
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
import os
|
|
214
|
+
from story_toolkit import StoryToolkit
|
|
215
|
+
from story_toolkit.llm import LLMFactory, LLMProvider
|
|
216
|
+
|
|
217
|
+
# Set your API key
|
|
218
|
+
os.environ["OPENAI_API_KEY"] = "sk-..."
|
|
219
|
+
|
|
220
|
+
# Create OpenAI backend
|
|
221
|
+
llm = LLMFactory.create_backend(
|
|
222
|
+
provider=LLMProvider.OPENAI,
|
|
223
|
+
model="gpt-3.5-turbo",
|
|
224
|
+
temperature=0.8
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
toolkit = StoryToolkit(llm_backend=llm)
|
|
228
|
+
|
|
229
|
+
# Generate advanced dialogue
|
|
230
|
+
dialogue = toolkit.generate_advanced_dialogue(
|
|
231
|
+
"Knight", "Dragon",
|
|
232
|
+
context="final_battle",
|
|
233
|
+
style="epic",
|
|
234
|
+
num_lines=6
|
|
235
|
+
)
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Example with Local LLM (Ollama)
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
# First, install and run Ollama
|
|
242
|
+
ollama pull llama2
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
```python
|
|
246
|
+
from story_toolkit import StoryToolkit
|
|
247
|
+
from story_toolkit.llm import LLMFactory, LLMProvider
|
|
248
|
+
|
|
249
|
+
# Create local backend (free, no API key)
|
|
250
|
+
llm = LLMFactory.create_backend(
|
|
251
|
+
provider=LLMProvider.LOCAL,
|
|
252
|
+
model="llama2",
|
|
253
|
+
temperature=0.7
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
toolkit = StoryToolkit(llm_backend=llm)
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## 📁 Project Structure
|
|
262
|
+
|
|
263
|
+
```
|
|
264
|
+
story_toolkit/
|
|
265
|
+
├── story_toolkit/ # Main Python package
|
|
266
|
+
│ ├── core/ # Story engine, Character, Plot, WorldBuilder
|
|
267
|
+
│ ├── generators/ # Character, Plot, and Dialogue generators
|
|
268
|
+
│ ├── nlp/ # Coherence checker and Text analyzer
|
|
269
|
+
│ ├── llm/ # LLM layer (NEW in v2.0.0)
|
|
270
|
+
│ │ ├── base.py # Base classes
|
|
271
|
+
│ │ ├── factory.py # Backend factory
|
|
272
|
+
│ │ └── backends/ # Mock, OpenAI, Anthropic, Local
|
|
273
|
+
│ └── utils/ # Helper functions
|
|
274
|
+
├── docs/ # Documentation (English & Persian)
|
|
275
|
+
│ ├── eng/ # English documentation
|
|
276
|
+
│ └── fa-ir/ # Persian documentation (مستندات فارسی)
|
|
277
|
+
├── examples/ # Usage examples
|
|
278
|
+
├── tests/ # Unit tests
|
|
279
|
+
├── requirements.txt # Dependencies
|
|
280
|
+
└── setup.py # Package setup
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## 📖 Documentation
|
|
286
|
+
|
|
287
|
+
Full documentation is available in two languages:
|
|
288
|
+
|
|
289
|
+
| Language | Link |
|
|
290
|
+
|----------|------|
|
|
291
|
+
| 🇬🇧 English | [docs/eng/index.html](docs/eng/index.html) |
|
|
292
|
+
| 🇮🇷 فارسی | [docs/fa-ir/index.html](docs/fa-ir/index.html) |
|
|
293
|
+
|
|
294
|
+
### Documentation Pages
|
|
295
|
+
|
|
296
|
+
- **Quick Start Guide** — Build your first story in 5 minutes
|
|
297
|
+
- **API Reference** — Complete documentation for all classes and methods
|
|
298
|
+
- **LLM Integration Guide** — How to use OpenAI, Anthropic, and local models
|
|
299
|
+
- **Examples** — Simple, complete, and advanced usage examples
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## 🧪 Running Tests
|
|
304
|
+
|
|
305
|
+
```bash
|
|
306
|
+
# Run all tests
|
|
307
|
+
pytest tests/ -v
|
|
308
|
+
|
|
309
|
+
# Core module tests
|
|
310
|
+
python -m tests.test_core
|
|
311
|
+
|
|
312
|
+
# Generator tests
|
|
313
|
+
python -m tests.test_generators
|
|
314
|
+
|
|
315
|
+
# NLP tool tests
|
|
316
|
+
python -m tests.test_nlp
|
|
317
|
+
|
|
318
|
+
# LLM layer tests
|
|
319
|
+
python -m tests.test_llm_quick.test_quick_verify
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
All tests should pass:
|
|
323
|
+
```
|
|
324
|
+
✅ StoryEngine tests passed!
|
|
325
|
+
✅ Character tests passed!
|
|
326
|
+
✅ Plot tests passed!
|
|
327
|
+
✅ WorldBuilder tests passed!
|
|
328
|
+
✅ LLM layer tests passed!
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
## 🎮 Usage Examples
|
|
334
|
+
|
|
335
|
+
### Simple Example
|
|
336
|
+
```bash
|
|
337
|
+
python -m examples.simple_example
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### Complete Demo
|
|
341
|
+
```bash
|
|
342
|
+
python -m examples.example
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### Advanced Features (with LLM)
|
|
346
|
+
```bash
|
|
347
|
+
python -m examples.advanced_example
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
## 🛠️ Core Components
|
|
353
|
+
|
|
354
|
+
### Character Development
|
|
355
|
+
```python
|
|
356
|
+
from story_toolkit.core.character import Character
|
|
357
|
+
|
|
358
|
+
hero = Character(name="Elena", age=32, role="protagonist")
|
|
359
|
+
hero.add_trait("brave")
|
|
360
|
+
hero.add_skill("sword_mastery")
|
|
361
|
+
hero.add_relationship("Villain", "enemy", strength=9)
|
|
362
|
+
hero.advance_arc() # initial → challenged → transformation → new_equilibrium
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### World Building
|
|
366
|
+
```python
|
|
367
|
+
from story_toolkit.core.world_builder import WorldBuilder
|
|
368
|
+
|
|
369
|
+
world = WorldBuilder()
|
|
370
|
+
world.create_world("Eldoria", "fantasy")
|
|
371
|
+
world.add_location("Crystal City", "Ancient metropolis", "city")
|
|
372
|
+
world.add_rule("magical", "Only eclipse-born can wield magic")
|
|
373
|
+
world.add_faction("Shadow Guild", "Secret organization", goals=["control_magic"])
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### Plot Generation
|
|
377
|
+
```python
|
|
378
|
+
from story_toolkit.generators.plot_generator import PlotGenerator
|
|
379
|
+
|
|
380
|
+
gen = PlotGenerator()
|
|
381
|
+
plot = gen.generate_plot("mystery", complexity=4)
|
|
382
|
+
print(f"Estimated chapters: {plot['estimated_length']['estimated_chapters']}")
|
|
383
|
+
print(f"Estimated words: {plot['estimated_length']['estimated_words']:,}")
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
### Coherence Checking
|
|
387
|
+
```python
|
|
388
|
+
from story_toolkit.nlp.coherence_checker import CoherenceChecker
|
|
389
|
+
|
|
390
|
+
checker = CoherenceChecker()
|
|
391
|
+
report = checker.generate_coherence_report(story_data)
|
|
392
|
+
|
|
393
|
+
if report['plot_holes']:
|
|
394
|
+
print("Plot holes found:")
|
|
395
|
+
for hole in report['plot_holes']:
|
|
396
|
+
print(f" - {hole}")
|
|
397
|
+
|
|
398
|
+
for rec in report['recommendations']:
|
|
399
|
+
print(f"💡 {rec}")
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### LLM-Powered Dialogue (NEW)
|
|
403
|
+
```python
|
|
404
|
+
from story_toolkit import StoryToolkit
|
|
405
|
+
from story_toolkit.llm import LLMFactory, LLMProvider
|
|
406
|
+
|
|
407
|
+
# Setup LLM
|
|
408
|
+
llm = LLMFactory.create_backend(provider=LLMProvider.MOCK)
|
|
409
|
+
toolkit = StoryToolkit(llm_backend=llm)
|
|
410
|
+
|
|
411
|
+
# Generate advanced dialogue
|
|
412
|
+
dialogue = toolkit.generate_advanced_dialogue(
|
|
413
|
+
"Hero", "Villain",
|
|
414
|
+
context="conflict",
|
|
415
|
+
style="dramatic",
|
|
416
|
+
num_lines=10
|
|
417
|
+
)
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
---
|
|
421
|
+
|
|
422
|
+
## 🔧 Requirements
|
|
423
|
+
|
|
424
|
+
- Python 3.8 or higher
|
|
425
|
+
- Dependencies listed in `requirements.txt`:
|
|
426
|
+
- `nltk>=3.8.1`
|
|
427
|
+
- `spacy>=3.7.0`
|
|
428
|
+
- `textblob>=0.17.1`
|
|
429
|
+
- `pydantic>=2.5.0`
|
|
430
|
+
- `pyyaml>=6.0`
|
|
431
|
+
|
|
432
|
+
### Optional LLM Dependencies
|
|
433
|
+
|
|
434
|
+
| Backend | Package |
|
|
435
|
+
|---------|---------|
|
|
436
|
+
| OpenAI | `openai>=1.0.0` |
|
|
437
|
+
| Anthropic | `anthropic>=0.18.0` |
|
|
438
|
+
| Local (Ollama) | `ollama>=0.1.0` |
|
|
439
|
+
| Local (llama.cpp) | `llama-cpp-python>=0.2.0` |
|
|
440
|
+
|
|
441
|
+
---
|
|
442
|
+
|
|
443
|
+
## 🔄 Upgrading from v1.0.0 to v2.0.0
|
|
444
|
+
|
|
445
|
+
**No breaking changes!** All v1.0.0 code continues to work unchanged.
|
|
446
|
+
|
|
447
|
+
```python
|
|
448
|
+
# This v1.0.0 code still works perfectly in v2.0.0
|
|
449
|
+
from story_toolkit import StoryToolkit
|
|
450
|
+
|
|
451
|
+
toolkit = StoryToolkit() # No LLM by default
|
|
452
|
+
story = toolkit.create_story("fantasy", "courage")
|
|
453
|
+
# ... everything works as before
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
To use new LLM features:
|
|
457
|
+
```python
|
|
458
|
+
# Optional: Add LLM for enhanced capabilities
|
|
459
|
+
llm = LLMFactory.create_backend(provider=LLMProvider.MOCK)
|
|
460
|
+
toolkit = StoryToolkit(llm_backend=llm)
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
---
|
|
464
|
+
|
|
465
|
+
## 📄 License
|
|
466
|
+
|
|
467
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
468
|
+
|
|
469
|
+
---
|
|
470
|
+
|
|
471
|
+
## 👤 Author
|
|
472
|
+
|
|
473
|
+
**Milad Rezanezhad**
|
|
474
|
+
|
|
475
|
+
- GitHub: [https://github.com/miladrezanezhad](https://github.com/miladrezanezhad)
|
|
476
|
+
- Project: [https://github.com/miladrezanezhad/story-toolkit](https://github.com/miladrezanezhad/story-toolkit)
|
|
477
|
+
|
|
478
|
+
---
|
|
479
|
+
|
|
480
|
+
## 🤝 Contributing
|
|
481
|
+
|
|
482
|
+
Contributions are welcome! Feel free to:
|
|
483
|
+
|
|
484
|
+
1. Fork the repository
|
|
485
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
486
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
487
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
488
|
+
5. Open a Pull Request
|
|
489
|
+
|
|
490
|
+
---
|
|
491
|
+
|
|
492
|
+
## 🌟 Support
|
|
493
|
+
|
|
494
|
+
If you find this project useful, please consider giving it a ⭐️ on GitHub!
|
|
495
|
+
|
|
496
|
+
---
|
|
497
|
+
|
|
498
|
+
*Built with ❤️ for writers and developers*
|
|
499
|
+
|
|
500
|
+
## ✨ **Version 2.0.0 Highlights**
|
|
501
|
+
|
|
502
|
+
| Feature | Description |
|
|
503
|
+
|---------|-------------|
|
|
504
|
+
| 🎯 **Badges** | Python, License, Version, Author shields |
|
|
505
|
+
| ⚡ **Quick Start** | Ready-to-run code with sample output |
|
|
506
|
+
| 🤖 **LLM Support** | OpenAI, Anthropic, and local models |
|
|
507
|
+
| 📁 **Structure** | Project directory layout with new llm/ module |
|
|
508
|
+
| 📖 **Docs** | Links to English and Persian documentation |
|
|
509
|
+
| 🧪 **Tests** | How to run unit tests including LLM tests |
|
|
510
|
+
| 🛠️ **Examples** | Code snippets for each component |
|
|
511
|
+
| 🔄 **Upgrade Guide** | How to upgrade from v1 to v2 |
|