Nodes/ComfyUI-FunPack/FunPack Lorebook Enhancer
ComfyUI Node

FunPack Lorebook Enhancer

Bring your SillyTavern lorebook into video generation

By digital-garbage·Created about a year ago·Updated 2 days ago· 18
FunPack Lorebook Enhancer
    • enhanced_prompt
    • injected_content
    promptThe brave explorer enters an ancient forest temple at twilight, discovering glowing runes on the walls.
    lorebook_1
    lorebook_2
    lorebook_3
    lorebook_4
    entry_delimiter
    context_history
    scan_depth4

    If you've spent time in the text-generation world, you know lorebooks: keyword-triggered entries that inject worldbuilding into a prompt only when it's relevant. The FunPack Lorebook Enhancer ports that idea into ComfyUI. Give it a SillyTavern-style lorebook JSON file and it appends the matching lore entries to the end of your video prompt. Character sheets, location descriptions, magic-system rules - all available to the model when a scene mentions them, without you hand-copying lore into every prompt.

    How it works

    Lorebooks work on triggers. The node scans your prompt (plus optional context history) for the keys defined in the lorebook, and every entry whose trigger matches gets appended to the prompt's tail. The scan_depth input (default 4) controls how many trailing lines of context_history + prompt get examined - keep it small unless your context is short. It's not doing vector similarity or fuzzy matching; it's a straightforward trigger scan, which means the quality of your match is the quality of your lorebook's keys.

    The four lorebook_1..4 inputs are full file paths to .json lorebooks in the SillyTavern format. You can chain up to four of them, which is how you'd split a giant world into per-session files. context_history is for when the prompt you care about isn't the whole story - say the current shot references an earlier scene; drop that earlier text in so its triggers fire.

    The outputs that matter

    • enhanced_prompt (STRING) - your original prompt with matching lore entries appended.
    • injected_content (STRING) - a readable log of exactly which entries got injected, with the delimiter prefix applied. Wire this to a text display node and you can see whether the lore you expected actually fired.

    One clever detail: entry_delimiter. It's an optional prefix added to every injected entry, and it exists for the case where the enhanced prompt is fed to an LLM (FunPack Prompt Enhancer or Story Writer) rather than straight to a CLIP. A distinctive marker like [LORE] lets the LLM tell "this is injected lore, keep it consistent" apart from "this is the actual shot description." If you're prompting a video model directly, you can leave it empty.

    Install

    It's part of ComfyUI-FunPack, so one install gets you the whole pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/olivv-cs/ComfyUI-FunPack
    pip install -r requirements.txt
    

    or via ComfyUI Manager (search "ComfyUI-FunPack"). It's a pure string node - no model downloads, no GPU, no optional deps.

    Things to know

    This node is the front end of a pipeline, not a standalone trick. It shines right before a Prompt Enhancer or Story Writer, because those LLM nodes benefit from having the world context in the prompt string. Feed enhanced_prompt into one of those and your story gets generated with the lore baked in.

    Two gotchas. First, an empty scan or no matching triggers means injected_content comes back empty - check that output before blaming the model for missing your worldbuilding. Second, lorebook JSON format matters; if the node won't load your file, it's almost certainly a SillyTavern-format mismatch, not a FunPack bug. It's an LLM-adjacent node, so remember the pack-wide rule: it needs transformers >= 5.0, and installing the optional hpsv3 package (which pins transformers to 4.45.2) will break it.

    CategoryFunPack

    Inputs (8)

    NameTypeDefaultDescription
    promptSTRINGThe brave explorer enters an ancient forest temple at twilight, discovering glowing runes on the walls.
    lorebook_1optSTRING
    lorebook_2optSTRING
    lorebook_3optSTRING
    lorebook_4optSTRING
    entry_delimiteroptSTRING
    context_historyoptSTRING
    scan_depthoptINT41–12

    Outputs (2)

    NameTypeDescription
    enhanced_promptSTRING
    injected_contentSTRING