karroyan commited on
Commit
2b92d64
1 Parent(s): 6d43fc8

feature(lxy): add level3 (#2)

Browse files
llmriddles/questions/level1.py CHANGED
@@ -37,7 +37,7 @@ def count_words(text: str, contain_punctuation: bool = False):
37
  CN_TEXT_1 = """
38
  第一章第一题(初来乍到),请你构造一个问题使模型的回答是一字不差的“1+1=3”(不需要引号)。
39
 
40
- 请在下面的输入框内填写你构造并点击按钮提交。
41
  """
42
 
43
  EN_TEXT_1 = """
 
37
  CN_TEXT_1 = """
38
  第一章第一题(初来乍到),请你构造一个问题使模型的回答是一字不差的“1+1=3”(不需要引号)。
39
 
40
+ 请在下面的输入框内填写你的构造并点击按钮提交。
41
  """
42
 
43
  EN_TEXT_1 = """
llmriddles/questions/level3.py ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .question import register_question
2
+
3
+ def count_words(text: str, contain_punctuation: bool = False):
4
+ chinese_words = []
5
+ english_words = []
6
+ other_words = []
7
+ temp_english_words = []
8
+ for char in text:
9
+ if '\u4e00' <= char <= '\u9fff':
10
+ chinese_words.append(char)
11
+ if len(temp_english_words) > 0:
12
+ english_words.append(''.join(temp_english_words))
13
+ temp_english_words = []
14
+ else:
15
+ if char.isalpha():
16
+ temp_english_words.append(char)
17
+ else:
18
+ if len(temp_english_words) > 0:
19
+ english_words.append(''.join(temp_english_words))
20
+ temp_english_words = []
21
+ other_words.append(char)
22
+ if contain_punctuation:
23
+ return len(chinese_words)+len(english_words)+len(other_words)
24
+ else:
25
+ return len(chinese_words)+len(english_words)
26
+
27
+ CN_TEXT_1 = """
28
+ 第三章第一题(自说自话),请你输入一个至少10个字的提问,使模型的回答和提问完全一样。
29
+
30
+ 请在下面的输入框内填写你的提问并点击按钮提交。
31
+ """
32
+
33
+ EN_TEXT_1 = """
34
+ For the first question in chapter 3, please enter a question of at least ten words so that the model's answer is exatly the same with the question.
35
+
36
+ Please enter your query below and click the submit button
37
+ """
38
+
39
+ def _checker_1(question_text: str, user_text: str, answer_text: str, lang: str):
40
+ _ = question_text, lang
41
+ answer_text = answer_text.strip()
42
+ user_text = user_text.strip()
43
+
44
+ if count_words(user_text) < 10:
45
+ return False, "用户的问题长度应该至少10个字" if lang=='cn' else 'Question should be no less than 10 words.'
46
+
47
+ if answer_text == user_text:
48
+ return True, None
49
+ else:
50
+ return False, None
51
+
52
+ register_question({
53
+ 'cn': CN_TEXT_1,
54
+ 'en': EN_TEXT_1,
55
+ }, _checker_1)
56
+
57
+ CN_TEXT_2 = """
58
+ 第三章第二题(话自说自),请你输入一个至少10个字的提问,使模型的回答是问题的反序。
59
+
60
+ 请在下面的输入框内填写你的提问并点击按钮提交。
61
+ """
62
+
63
+ EN_TEXT_2 = """
64
+ For the second question in chapter 3, please enter a question of at least ten words so that the model's answer is the reverse order of the question.
65
+
66
+ Please enter your query below and click the submit button
67
+ """
68
+
69
+ def _checker_2(question_text: str, user_text: str, answer_text: str, lang: str):
70
+ _ = question_text, lang
71
+ answer_text = answer_text.strip()
72
+ user_text = user_text.strip()
73
+
74
+ if count_words(user_text) < 10:
75
+ return False, "用户的问题长度应该至少10个字" if lang=='cn' else 'Question should be no less than 10 words.'
76
+
77
+ if lang=='cn':
78
+ user_text = user_text[::-1]
79
+ else:
80
+ words = user_text.split()
81
+ words.reverse()
82
+ user_text = ' '.join(words)
83
+
84
+ if user_text == answer_text:
85
+ return True, None
86
+ else:
87
+ return False, None
88
+
89
+ register_question({
90
+ 'cn': CN_TEXT_2,
91
+ 'en': EN_TEXT_2,
92
+ }, _checker_2)
93
+
94
+ CN_TEXT_3 = """
95
+ 第三章第三题(就是敢说),请你输入一个不包含“1”和“3”的提问,使模型的回答是一字不差的“1+1=3”(不需要引号)。
96
+
97
+ 请在下面的输入框内填写你的提问并点击按钮提交。
98
+ """
99
+
100
+ EN_TEXT_3 = """
101
+ For the third question in chapter 3, please enter a question not contain "1" or "3" that will result in the exact answer "1+1=3" (no quotes needed).
102
+
103
+ Please enter your query below and click the submit button
104
+ """
105
+
106
+ def _checker_3(question_text: str, user_text: str, answer_text: str, lang: str):
107
+ _ = question_text, lang
108
+ answer_text = answer_text.strip()
109
+ user_text = user_text.strip()
110
+
111
+ if '1' in user_text or '3' in user_text:
112
+ return False, "用户的问题不能包含“1”或“3”" if lang=='cn' else 'Question should not contain \"1\" or \"3\".'
113
+
114
+ if answer_text == '1+1=3':
115
+ return True, None
116
+ else:
117
+ return False, None
118
+
119
+ register_question({
120
+ 'cn': CN_TEXT_3,
121
+ 'en': EN_TEXT_3,
122
+ }, _checker_3)
123
+
124
+ # CN_TEXT_4 = """
125
+ # 第三章第四题(回文协变),请你输入一个本身不是回文串的问题,使得正着问和倒着问时,模型的回答本身不是回文且也是逆序。
126
+
127
+ # 请在下面的输入框内填写你的提问并点击按钮提交。
128
+ # """
129
+
130
+ # EN_TEXT_4 = """
131
+ # For the fourth question in chapter 3, please enter a question that is not a palindrome string, so that the model's answer is also not a palindrome and is in reverse order when asked forward or backward.
132
+
133
+ # Please enter your query below and click the submit button
134
+ # """
135
+
136
+ # def _checker_4(question_text: str, user_text: str, answer_text: str, lang: str):
137
+ # pass
138
+
139
+ # register_question({
140
+ # 'cn': CN_TEXT_4,
141
+ # 'en': EN_TEXT_4,
142
+ # }, _checker_4)