Built an AI-powered eBook generator - looking for feedback on long-form LLM workflows #1209
Sam-May-Futurelab
started this conversation in
Show and tell
Replies: 1 comment
|
Great project! Long-form LLM workflows for eBooks require careful orchestration. Here is feedback and patterns: Key Challenges for Long-Form Generation
Recommended Architecturefrom dataclasses import dataclass, field
from typing import List, Dict
@dataclass
class BookState:
# Structure
outline: List[Dict] = field(default_factory=list)
chapters: Dict[str, str] = field(default_factory=dict)
# Consistency tracking
characters: Dict[str, Dict] = field(default_factory=dict)
plot_points: List[str] = field(default_factory=list)
world_facts: Dict[str, str] = field(default_factory=dict)
# Style guide
tone: str = ""
pov: str = ""
tense: str = ""
class EBookGenerator:
def __init__(self, llm_client):
self.llm = llm_client
self.state = BookState()
async def generate_book(self, premise: str) -> str:
# Phase 1: Planning
self.state.outline = await self.generate_outline(premise)
# Phase 2: World building
self.state.characters = await self.develop_characters()
self.state.world_facts = await self.build_world()
# Phase 3: Chapter generation
for chapter in self.state.outline:
content = await self.generate_chapter(
chapter,
context=self.get_relevant_context(chapter)
)
self.state.chapters[chapter["id"]] = content
# Validate consistency
await self.validate_chapter(content)
# Phase 4: Assembly
return self.assemble_book()
def get_relevant_context(self, chapter: Dict) -> str:
"""Build context from state - key for consistency"""
relevant_chars = [c for c in self.state.characters.values()
if c["name"] in chapter.get("characters", [])]
return f"""
Characters in this chapter:
{json.dumps(relevant_chars, indent=2)}
Established facts:
{json.dumps(self.state.world_facts, indent=2)}
Previous chapter summary:
{self.get_previous_summary(chapter)}
Style guide: {self.state.tone}, {self.state.pov}, {self.state.tense}
"""Token Optimizationdef compress_context(context: str, max_tokens: int) -> str:
"""Summarize context to fit token budget"""
if count_tokens(context) <= max_tokens:
return context
# Summarize older content, keep recent verbatim
return llm.summarize(context, target_tokens=max_tokens)Consistency Validationasync def validate_chapter(self, content: str):
# Check character consistency
# Check plot continuity
# Check factual consistency with world state
passThe key is treating state as the source of truth and always providing relevant context. More patterns: https://github.com/KeepALifeUS/autonomous-agents |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi everyone 👋
I’ve been experimenting a lot with long-form LLM workflows recently and ended up building Inkfluence AI - a tool that generates full eBooks, guides, and workbooks using AI (with chapter structure, long-form content, and custom cover design).
Since LLMware focuses heavily on structured workflows, context handling, and model orchestration, I thought this community might have some valuable insights.
🔗 Inkfluence AI
Would love feedback on:
Thanks for taking a look, any thoughts or suggestions are appreciated!
All reactions