Skip to content

Commit e4866f0

Browse files
committed
Add RemoveTextBetween node to remove text between specified strings; update version to 1.0.2
1 parent 637bc18 commit e4866f0

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

mikey_nodes.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4178,6 +4178,25 @@ def concat(self, delimiter, text1, text2, text3, text4, text5):
41784178
text = delimiter.join(texts)
41794179
return (text,)
41804180

4181+
class RemoveTextBetween:
4182+
# removes text between two strings
4183+
# default start is <think> and end is </think>
4184+
@classmethod
4185+
def INPUT_TYPES(cls):
4186+
return {'required': {'text': ('STRING', {'multiline': True, 'default': 'Input Text Here', 'dynamicPrompts': False})},
4187+
'optional': {'start': ('STRING', {'default': '<think>'}),
4188+
'end': ('STRING', {'default': '</think>'})}}
4189+
4190+
RETURN_TYPES = ('STRING',)
4191+
FUNCTION = 'remove'
4192+
CATEGORY = 'Mikey/Text'
4193+
4194+
def remove(self, text, start, end):
4195+
# search and replace
4196+
# remove text between start and end
4197+
text = re.sub(re.escape(start) + '.*?' + re.escape(end), '', text, flags=re.DOTALL).lstrip().rstrip()
4198+
return (text,)
4199+
41814200
class OobaPrompt:
41824201
@classmethod
41834202
def INPUT_TYPES(s):
@@ -5390,6 +5409,7 @@ def save(self, model, vae, filename_prefix, clip=None, prompt=None, extra_pnginf
53905409
'SRFloatPromptInput': SRFloatPromptInput,
53915410
'TextPreserve': TextPreserve,
53925411
'TextConcat': TextConcat,
5412+
'RemoveTextBetween': RemoveTextBetween,
53935413
'OobaPrompt': OobaPrompt,
53945414
'WildcardOobaPrompt': WildcardOobaPrompt,
53955415
'LMStudioPrompt': LMStudioPrompt,
@@ -5465,6 +5485,7 @@ def save(self, model, vae, filename_prefix, clip=None, prompt=None, extra_pnginf
54655485
'SRFloatPromptInput': 'SR Float Prompt Input (Mikey)',
54665486
'TextPreserve': 'Text Preserve (Mikey)',
54675487
'TextConcat': 'Text Concat (Mikey)',
5488+
'RemoveTextBetween': 'Remove Text Between (Mikey)',
54685489
'OobaPrompt': 'OobaPrompt (Mikey)',
54695490
'WildcardOobaPrompt': 'Wildcard OobaPrompt (Mikey)',
54705491
'LMStudioPrompt': 'LM Studio Prompt (Mikey)',

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "mikey_nodes"
33
description = "Collection of convenient nodes. Wildcard, style, image, llm, haldclut, metadata, and more."
4-
version = "1.0.1"
4+
version = "1.0.2"
55
license = { text = "MIT License" }
66

77
[project.urls]

0 commit comments

Comments
 (0)