@@ -36,18 +36,18 @@ class TextReplaceBlock(Block):
3636 name = "text_replace_block"
3737 inputs = {
3838 "text" : Input ("text" , "原始文本" , str , "原始文本" ),
39- "variable " : Input ("variable " , "被替换的文本 " , Any , "被替换的文本 " ),
39+ "new_text " : Input ("new_text " , "新文本 " , Any , "新文本 " ),
4040 }
4141 outputs = {"text" : Output ("text" , "替换后的文本" , str , "替换后的文本" )}
4242
4343 def __init__ (
44- self , name : Annotated [str , ParamMeta (label = "变量名称 " , description = "变量名称 " )]
44+ self , variable : Annotated [str , ParamMeta (label = "被替换的文本 " , description = "被替换的文本 " )]
4545 ):
46- self .name = name
46+ self .variable = variable
4747
48- def execute (self ) -> Dict [str , Any ]:
48+ def execute (self , text : str , new_text : Any ) -> Dict [str , Any ]:
4949 return {
50- "text" : self . text .value . replace (self .variable . value , str (self . variable ))
50+ "text" : text .replace (self .variable , str (new_text ))
5151 }
5252
5353
@@ -56,6 +56,10 @@ class TextExtractByRegexBlock(Block):
5656 name = "text_extract_by_regex_block"
5757 inputs = {"text" : Input ("text" , "原始文本" , str , "原始文本" )}
5858 outputs = {"text" : Output ("text" , "提取后的文本" , str , "提取后的文本" )}
59+ def __init__ (
60+ self , regex : Annotated [str , ParamMeta (label = "正则表达式" , description = "正则表达式" )]
61+ ):
62+ self .regex = regex
5963
6064 def execute (self ) -> Dict [str , Any ]:
6165 # 使用正则表达式提取文本
@@ -65,3 +69,4 @@ def execute(self) -> Dict[str, Any]:
6569 return {"text" : match .group (0 )}
6670 else :
6771 return {"text" : "" }
72+
0 commit comments