cryogenic22 commited on
Commit
91ee4dd
·
verified ·
1 Parent(s): 6492325

Update multi_agent_book_workflow.py

Browse files
Files changed (1) hide show
  1. multi_agent_book_workflow.py +67 -63
multi_agent_book_workflow.py CHANGED
@@ -233,68 +233,70 @@ class BookWritingOrchestrator:
233
  """
234
 
235
  def generate_book_concept(self, initial_prompt: str) -> Dict[str, Any]:
236
- """
237
- Generate a comprehensive book concept using multi-agent collaboration
238
- """
239
- try:
240
- # Concept Development Task
241
- concept_task = Task(
242
- description=f"""
243
- Develop a comprehensive book concept based on this initial idea:
244
- {initial_prompt}
245
-
246
- Provide detailed outputs including:
247
- 1. Title: A unique and compelling book title
248
- 2. Genre: Primary genre and any relevant subgenres
249
- 3. Target Audience: Specific demographic and reader profile
250
- 4. Core Premise: The central concept or hook
251
- 5. Chapter Outline: Brief outline of proposed chapters
252
- 6. Narrative Approach: Point of view and stylistic elements
253
- 7. Key Themes: Major themes to be explored
254
-
255
- Format the output as a structured JSON object.
256
- """,
257
- agent=self.concept_agent
258
- )
259
-
260
- # Research Validation Task
261
- research_task = Task(
262
- description="""
263
- Review and enhance the generated book concept with:
264
- 1. Market analysis and genre conventions
265
- 2. Comparable successful titles
266
- 3. Unique selling points
267
- 4. Potential areas for deeper exploration
268
-
269
- Add these insights to the concept structure.
270
- """,
271
- agent=self.research_agent
272
- )
273
-
274
- # Create Crew for Collaborative Processing
275
- book_concept_crew = Crew(
276
- agents=[self.concept_agent, self.research_agent],
277
- tasks=[concept_task, research_task],
278
- verbose=True
279
- )
280
-
281
- # Execute Collaborative Workflow
282
- result = book_concept_crew.kickoff()
283
-
284
- # Parse and structure the result
285
- parsed_concept = self._parse_concept(result)
286
-
287
- # Store Context
288
- self._store_context('book_concept', str(parsed_concept))
289
-
290
- return parsed_concept
291
-
292
- except Exception as e:
293
- st.error(f"Book concept generation failed: {e}")
294
- return self._fallback_book_concept(initial_prompt)
 
 
295
 
296
  def generate_chapter_content(self, book_concept: Dict[str, Any], chapter_number: int) -> str:
297
- """Generate content for a specific chapter"""
298
  try:
299
  # Get previous context
300
  previous_context = self._retrieve_context(chapter_number - 1) if chapter_number > 1 else ""
@@ -316,6 +318,7 @@ class BookWritingOrchestrator:
316
 
317
  Generate a complete, polished chapter.
318
  """,
 
319
  agent=self.writing_agent
320
  )
321
 
@@ -330,6 +333,7 @@ class BookWritingOrchestrator:
330
 
331
  Provide a final, edited version.
332
  """,
 
333
  agent=self.editing_agent
334
  )
335
 
@@ -353,9 +357,9 @@ class BookWritingOrchestrator:
353
 
354
  return chapter_content
355
 
356
- except Exception as e:
357
- st.error(f"Chapter generation failed: {e}")
358
- return self._fallback_chapter_content(book_concept, chapter_number)
359
 
360
  def _parse_concept(self, raw_concept: str) -> Dict[str, Any]:
361
  """Parse the raw concept output into a structured format"""
 
233
  """
234
 
235
  def generate_book_concept(self, initial_prompt: str) -> Dict[str, Any]:
236
+ """
237
+ Generate a comprehensive book concept using multi-agent collaboration
238
+ """
239
+ try:
240
+ # Concept Development Task
241
+ concept_task = Task(
242
+ description=f"""
243
+ Develop a comprehensive book concept based on this initial idea:
244
+ {initial_prompt}
245
+
246
+ Provide detailed outputs including:
247
+ 1. Title: A unique and compelling book title
248
+ 2. Genre: Primary genre and any relevant subgenres
249
+ 3. Target Audience: Specific demographic and reader profile
250
+ 4. Core Premise: The central concept or hook
251
+ 5. Chapter Outline: Brief outline of proposed chapters
252
+ 6. Narrative Approach: Point of view and stylistic elements
253
+ 7. Key Themes: Major themes to be explored
254
+
255
+ Format the output as a structured JSON object.
256
+ """,
257
+ expected_output="A detailed JSON-formatted book concept with title, genre, target audience, and other key elements",
258
+ agent=self.concept_agent
259
+ )
260
+
261
+ # Research Validation Task
262
+ research_task = Task(
263
+ description="""
264
+ Review and enhance the generated book concept with:
265
+ 1. Market analysis and genre conventions
266
+ 2. Comparable successful titles
267
+ 3. Unique selling points
268
+ 4. Potential areas for deeper exploration
269
+
270
+ Add these insights to the concept structure.
271
+ """,
272
+ expected_output="A detailed analysis and enhancement of the book concept with market insights and comparative analysis",
273
+ agent=self.research_agent
274
+ )
275
+
276
+ # Create Crew for Collaborative Processing
277
+ book_concept_crew = Crew(
278
+ agents=[self.concept_agent, self.research_agent],
279
+ tasks=[concept_task, research_task],
280
+ verbose=True
281
+ )
282
+
283
+ # Execute Collaborative Workflow
284
+ result = book_concept_crew.kickoff()
285
+
286
+ # Parse and structure the result
287
+ parsed_concept = self._parse_concept(result)
288
+
289
+ # Store Context
290
+ self._store_context('book_concept', str(parsed_concept))
291
+
292
+ return parsed_concept
293
+
294
+ except Exception as e:
295
+ st.error(f"Book concept generation failed: {e}")
296
+ return self._fallback_book_concept(initial_prompt)
297
 
298
  def generate_chapter_content(self, book_concept: Dict[str, Any], chapter_number: int) -> str:
299
+ """Generate content for a specific chapter"""
300
  try:
301
  # Get previous context
302
  previous_context = self._retrieve_context(chapter_number - 1) if chapter_number > 1 else ""
 
318
 
319
  Generate a complete, polished chapter.
320
  """,
321
+ expected_output="A complete, polished chapter with narrative continuity and character development",
322
  agent=self.writing_agent
323
  )
324
 
 
333
 
334
  Provide a final, edited version.
335
  """,
336
+ expected_output="A refined and polished version of the chapter with improved narrative quality",
337
  agent=self.editing_agent
338
  )
339
 
 
357
 
358
  return chapter_content
359
 
360
+ except Exception as e:
361
+ st.error(f"Chapter generation failed: {e}")
362
+ return self._fallback_chapter_content(book_concept, chapter_number)
363
 
364
  def _parse_concept(self, raw_concept: str) -> Dict[str, Any]:
365
  """Parse the raw concept output into a structured format"""