fabricatio_novel.actions.novel

This module provides actions related to novel generation and management.

It includes classes such as GenerateNovel for creating novels based on prompts, and DumpNovel for saving generated novels to a specified file path. These actions leverage capabilities from the fabricatio_core and interact with both Python and Rust components to perform their tasks.

Classes

GenerateCharactersFromDraft

Generate character cards from a NovelDraft.

GenerateScriptsFromDraftAndCharacters

Generate chapter scripts from a draft and list of characters.

GenerateChaptersFromScripts

Generate full chapter contents from scripts and characters.

AssembleNovelFromComponents

Assemble final Novel object from draft, scripts, and chapter contents.

ValidateNovel

Validate the generated novel for compliance and structure.

GenerateNovelDraft

Generate a novel draft from a prompt.

GenerateNovel

An action that generates a novel based on a provided prompt.

DumpNovel

An action that saves a generated novel to a specified file path.

Module Contents

class fabricatio_novel.actions.novel.GenerateCharactersFromDraft(/, **data: Any)

Bases: fabricatio_novel.capabilities.novel.NovelCompose, fabricatio_core.Action

Generate character cards from a NovelDraft.

novel_draft: fabricatio_novel.models.draft.NovelDraft | None = None

The novel draft from which to generate characters.

output_key: str = 'novel_characters'

Key under which the generated list of CharacterCard will be stored in context.

ctx_override: ClassVar[bool] = True

Whether to override the instance attr by the context variable.

class fabricatio_novel.actions.novel.GenerateScriptsFromDraftAndCharacters(/, **data: Any)

Bases: fabricatio_novel.capabilities.novel.NovelCompose, fabricatio_core.Action

Generate chapter scripts from a draft and list of characters.

novel_draft: fabricatio_novel.models.draft.NovelDraft | None = None

The novel draft containing chapter synopses.

novel_characters: List[fabricatio_character.models.character.CharacterCard] | None = None

List of character cards to be used in script generation.

output_key: str = 'novel_scripts'

Key under which the generated list of Script will be stored in context.

ctx_override: ClassVar[bool] = True

Whether to override the instance attr by the context variable.

class fabricatio_novel.actions.novel.GenerateChaptersFromScripts(/, **data: Any)

Bases: fabricatio_novel.capabilities.novel.NovelCompose, fabricatio_core.Action

Generate full chapter contents from scripts and characters.

novel_draft: fabricatio_novel.models.draft.NovelDraft | None = None

The novel draft (for language, metadata).

novel_scripts: List[fabricatio_novel.models.scripting.Script] | None = None

The list of chapter scripts to expand into full text.

novel_characters: List[fabricatio_character.models.character.CharacterCard] | None = None

The list of characters to provide context.

chapter_guidance: str | None = None

Guidance for writing chapter.

output_key: str = 'novel_chapter_contents'

Key under which the generated list of chapter content strings will be stored in context.

ctx_override: ClassVar[bool] = True

Whether to override the instance attr by the context variable.

class fabricatio_novel.actions.novel.AssembleNovelFromComponents(/, **data: Any)

Bases: fabricatio_novel.capabilities.novel.NovelCompose, fabricatio_core.Action

Assemble final Novel object from draft, scripts, and chapter contents.

novel_draft: fabricatio_novel.models.draft.NovelDraft | None = None

The original draft containing title, synopsis, etc.

novel_scripts: List[fabricatio_novel.models.scripting.Script] | None = None

Scripts containing chapter titles and metadata.

novel_chapter_contents: List[str] | None = None

Generated full text for each chapter.

output_key: str = 'novel'

Key under which the assembled Novel object will be stored in context.

ctx_override: ClassVar[bool] = True

Whether to override the instance attr by the context variable.

class fabricatio_novel.actions.novel.ValidateNovel(/, **data: Any)

Bases: fabricatio_core.Action

Validate the generated novel for compliance and structure.

novel: fabricatio_novel.models.novel.Novel | None = None

The novel to validate.

output_key: str = 'novel_is_valid'

Key under which the validation result (bool) will be stored in context.

min_chapters: int = 1
min_total_words: int = 1000
min_compliance_ratio: float = 0.8
ctx_override: ClassVar[bool] = True

Whether to override the instance attr by the context variable.

class fabricatio_novel.actions.novel.GenerateNovelDraft(/, **data: Any)

Bases: fabricatio_novel.capabilities.novel.NovelCompose, fabricatio_core.Action

Generate a novel draft from a prompt.

novel_outline: str | None = None

The prompt used to generate the novel. If not provided, execution will fail.

novel_language: str | None = None

The language of the novel. If not provided, will infer from the prompt.

output_key: str = 'novel_draft'

Key under which the generated NovelDraft will be stored in context.

ctx_override: ClassVar[bool] = True

Whether to override the instance attr by the context variable.

class fabricatio_novel.actions.novel.GenerateNovel(/, **data: Any)

Bases: fabricatio_novel.capabilities.novel.NovelCompose, fabricatio_core.Action

An action that generates a novel based on a provided prompt.

This class inherits from NovelCompose and Action, and is responsible for generating a novel using the underlying novel generation capability. The generated novel is returned as a Novel object.

novel_outline: str | None = None

The prompt used to generate the novel. If not provided, execution will fail.

novel_language: str | None = None

The language of the novel. If not provided, will infer from the prompt.

chapter_guidance: str | None = None

Guidance for writing chapter.

output_key: str = 'novel'

The key under which the generated novel will be stored in the context.

ctx_override: ClassVar[bool] = True

Whether to override the instance attr by the context variable.

class fabricatio_novel.actions.novel.DumpNovel(/, **data: Any)

Bases: fabricatio_core.Action

An action that saves a generated novel to a specified file path.

This class takes a Novel object and writes its content to a file at the specified path.

output_path: pathlib.Path | None = None

The file system path where the novel should be saved. Required for execution.

novel_font_file: pathlib.Path | None = None

The file system path to the novel font file. like .ttf file.

novel: fabricatio_novel.models.novel.Novel | None = None

The novel object to be saved. Must be provided for successful execution.

cover_image: pathlib.Path | None = None

The file system path to the novel cover image.

output_key: str = 'novel_path'

The key under which the output path will be stored in the context.

ctx_override: ClassVar[bool] = True

Whether to override the instance attr by the context variable.