-
Notifications
You must be signed in to change notification settings - Fork 20
/
classify_function.py
151 lines (133 loc) · 4.19 KB
/
classify_function.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import re
class classify_function:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"is_enable": ("BOOLEAN", {"default": True}),
"text": ("STRING", {"forceInput": True}),
},
"optional": {},
}
RETURN_TYPES = (
"STRING",
"STRING",
"STRING",
)
RETURN_NAMES = (
"response1",
"response2",
"response3",
)
FUNCTION = "condition"
# OUTPUT_NODE = False
CATEGORY = "大模型派对(llm_party)/函数(function)"
def condition(self, text, is_enable=True):
if is_enable == False:
return (None,)
# 使用正则表达式分割字符串
parts = re.split(r"\*\*[0-9]:\*\* ", text)
# 移除列表中的空字符串
parts = [part for part in parts if part]
# 根据分割后的部分数量,赋值给response变量
response1, response2, response3 = (parts + ["", "", ""])[:3]
if response1.strip() == "" or response1.strip() == "empty":
response1 = None
if response2.strip() == "" or response2.strip() == "empty":
response2 = None
if response3.strip() == "" or response3.strip() == "empty":
response3 = None
return (
response1,
response2,
response3,
)
class classify_function_plus:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"is_enable": ("BOOLEAN", {"default": True}),
"text": ("STRING", {"forceInput": True}),
},
"optional": {},
}
RETURN_TYPES = (
"STRING",
"STRING",
"STRING",
"STRING",
"STRING",
"STRING",
"STRING",
"STRING",
"STRING",
"STRING",
)
RETURN_NAMES = (
"response1",
"response2",
"response3",
"response4",
"response5",
"response6",
"response7",
"response8",
"response9",
"response10",
)
FUNCTION = "condition"
# OUTPUT_NODE = False
CATEGORY = "大模型派对(llm_party)/函数(function)"
def condition(self, text, is_enable=True):
if is_enable == False:
return (None,)
# 使用正则表达式分割字符串
parts = re.split(r"\*\*[0-9]+:\*\* ", text)
# 移除列表中的空字符串
parts = [part for part in parts if part]
# 根据分割后的部分数量,赋值给response变量
(
response1,
response2,
response3,
response4,
response5,
response6,
response7,
response8,
response9,
response10,
) = (parts + ["", "", ""])[:10]
if response1.strip() == "" or response1.strip() == "empty":
response1 = None
if response2.strip() == "" or response2.strip() == "empty":
response2 = None
if response3.strip() == "" or response3.strip() == "empty":
response3 = None
if response4.strip() == "" or response4.strip() == "empty":
response4 = None
if response5.strip() == "" or response5.strip() == "empty":
response5 = None
if response6.strip() == "" or response6.strip() == "empty":
response6 = None
if response7.strip() == "" or response7.strip() == "empty":
response7 = None
if response8.strip() == "" or response8.strip() == "empty":
response8 = None
if response9.strip() == "" or response9.strip() == "empty":
response9 = None
if response10.strip() == "" or response10.strip() == "empty":
response10 = None
return (
response1,
response2,
response3,
response4,
response5,
response6,
response7,
response8,
response9,
response10,
)