Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sampler.py #42

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions nodes/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ def INPUT_TYPES(s):
"text": ("STRING", {"multiline": True, "dynamicPrompts": False}),
"seed": ("INT", {"default": 0, "display": "number"}),
"autorefresh": (["Yes", "No"], {"default": "No"}),
"weight": ("FLOAT", {"default": 1.000, "display": "number", "min": 1.000, "max": 2.000, "step": 0.001}),
},
}

@classmethod
def IS_CHANGED(cls, text: str, seed: int, autorefresh: str):
def IS_CHANGED(cls, text: str, seed: int, autorefresh: str, weight: float ):
# Force re-evaluation of the node
return float("NaN")

Expand All @@ -36,6 +37,7 @@ def __init__(self, *args, **kwargs):
wildcards_folder = self._find_wildcards_folder()
self._wildcard_manager = WildcardManager(path=wildcards_folder)
self._current_prompt = None
self._current_weight = 1.000

def _find_wildcards_folder(self) -> Path | None:
"""
Expand Down Expand Up @@ -77,8 +79,16 @@ def has_prompt_changed(self, text: str) -> bool:
Check if the prompt has changed.
"""
return self._current_prompt != text
"""
weight mod
"""
def has_weight_changed(self, weight: float) -> bool:
"""
Check if the weight has changed.
"""
return self._current_weight != weight

def get_prompt(self, text: str, seed: int, autorefresh: str) -> tuple[str]:
def get_prompt(self, text: str, seed: int, autorefresh: str, weight: float) -> tuple[str]:
"""
Main entrypoint for this node.
Using the sampling context, generate a new prompt.
Expand All @@ -89,11 +99,21 @@ def get_prompt(self, text: str, seed: int, autorefresh: str) -> tuple[str]:

if text.strip() == "":
return ("",)

if self.has_weight_changed(weight):
self._current_weight = weight

if self.has_prompt_changed(text):

self._current_prompt = text
self._prompts = self.context.sample_prompts(self._current_prompt)



if self._current_weight > 1.000:

self._current_prompt = ("((" + text + "):" + str(weight) + ")")

self._prompts = self.context.sample_prompts(self._current_prompt)

if self._prompts is None:
logger.exception("Something went wrong. Prompts is None!")
return ("",)
Expand Down