cddb07a176
docs / deploy (push) Has been cancelled
docs / changes (push) Has been cancelled
docs / check-and-build (push) Has been cancelled
build container image / cpu (push) Has been cancelled
build container image / cuda (push) Has been cancelled
build container image / rocm (push) Has been cancelled
frontend checks / frontend-checks (push) Has been cancelled
frontend tests / frontend-tests (push) Has been cancelled
lfs checks / lfs-check (push) Has been cancelled
python checks / python-checks (push) Has been cancelled
python tests / py3.12: macos-default (push) Has been cancelled
python tests / py3.11: windows-cpu (push) Has been cancelled
python tests / py3.12: windows-cpu (push) Has been cancelled
python tests / py3.11: linux-cpu (push) Has been cancelled
typegen checks / typegen-checks (push) Has been cancelled
uv lock checks / uv-lock-checks (push) Has been cancelled
openapi checks / openapi-checks (push) Has been cancelled
python tests / py3.11: macos-default (push) Has been cancelled
python tests / py3.12: linux-cpu (push) Has been cancelled
58 lines
2.3 KiB
Python
58 lines
2.3 KiB
Python
from invokeai.app.invocations.baseinvocation import BaseInvocation, BaseInvocationOutput, invocation, invocation_output
|
|
from invokeai.app.invocations.fields import InputField, OutputField, StylePresetField, UIComponent
|
|
from invokeai.app.services.shared.invocation_context import InvocationContext
|
|
|
|
|
|
@invocation_output("prompt_template_output")
|
|
class PromptTemplateOutput(BaseInvocationOutput):
|
|
"""Output for the Prompt Template node"""
|
|
|
|
positive_prompt: str = OutputField(description="The positive prompt with the template applied")
|
|
negative_prompt: str = OutputField(description="The negative prompt with the template applied")
|
|
|
|
|
|
@invocation(
|
|
"prompt_template",
|
|
title="Prompt Template",
|
|
tags=["prompt", "template", "style", "preset"],
|
|
category="prompt",
|
|
version="1.0.0",
|
|
)
|
|
class PromptTemplateInvocation(BaseInvocation):
|
|
"""Applies a Style Preset template to positive and negative prompts.
|
|
|
|
Select a Style Preset and provide positive/negative prompts. The node replaces
|
|
{prompt} placeholders in the template with your input prompts.
|
|
"""
|
|
|
|
style_preset: StylePresetField = InputField(
|
|
description="The Style Preset to use as a template",
|
|
)
|
|
positive_prompt: str = InputField(
|
|
default="",
|
|
description="The positive prompt to insert into the template's {prompt} placeholder",
|
|
ui_component=UIComponent.Textarea,
|
|
)
|
|
negative_prompt: str = InputField(
|
|
default="",
|
|
description="The negative prompt to insert into the template's {prompt} placeholder",
|
|
ui_component=UIComponent.Textarea,
|
|
)
|
|
|
|
def invoke(self, context: InvocationContext) -> PromptTemplateOutput:
|
|
# Fetch the style preset from the database
|
|
style_preset = context._services.style_preset_records.get(self.style_preset.style_preset_id)
|
|
|
|
# Get the template prompts
|
|
positive_template = style_preset.preset_data.positive_prompt
|
|
negative_template = style_preset.preset_data.negative_prompt
|
|
|
|
# Replace {prompt} placeholder with the input prompts
|
|
rendered_positive = positive_template.replace("{prompt}", self.positive_prompt)
|
|
rendered_negative = negative_template.replace("{prompt}", self.negative_prompt)
|
|
|
|
return PromptTemplateOutput(
|
|
positive_prompt=rendered_positive,
|
|
negative_prompt=rendered_negative,
|
|
)
|