HansBug commited on
Commit
bacbf19
1 Parent(s): e798126

dev(hansbug): add names for questions

Browse files
llmriddles/questions/executor.py CHANGED
@@ -15,6 +15,10 @@ class QuestionExecutor:
15
  def question_text(self):
16
  return self.question.texts[self.lang]
17
 
 
 
 
 
18
  def check(self, qs_text: str) -> Tuple[str, bool, str]:
19
  answer_text = get_llm_fn(self.llm)(qs_text, **self.llm_cfgs)
20
  correct, explanation = self.check_answer(qs_text, answer_text)
 
15
  def question_text(self):
16
  return self.question.texts[self.lang]
17
 
18
+ @property
19
+ def question_name(self):
20
+ return self.question.names[self.lang]
21
+
22
  def check(self, qs_text: str) -> Tuple[str, bool, str]:
23
  answer_text = get_llm_fn(self.llm)(qs_text, **self.llm_cfgs)
24
  correct, explanation = self.check_answer(qs_text, answer_text)
llmriddles/questions/level1.py CHANGED
@@ -1,14 +1,18 @@
1
  from .question import register_question
2
 
 
3
  def count_english_words(text: str):
4
  return len(text.split(' '))
5
 
 
6
  def count_chinese_words(text: str):
7
  return len(text)
8
 
 
9
  def check_if_chinese(text: str):
10
  return all('\u4e00' <= char <= '\u9fff' for char in text)
11
 
 
12
  def count_words(text: str, contain_punctuation: bool = False):
13
  chinese_words = []
14
  english_words = []
@@ -29,9 +33,9 @@ def count_words(text: str, contain_punctuation: bool = False):
29
  temp_english_words = []
30
  other_words.append(char)
31
  if contain_punctuation:
32
- return len(chinese_words)+len(english_words)+len(other_words)
33
  else:
34
- return len(chinese_words)+len(english_words)
35
 
36
 
37
  CN_TEXT_1 = """
@@ -57,11 +61,14 @@ def _checker_1(question_text: str, user_text: str, answer_text: str, lang: str):
57
  return False, None
58
 
59
 
60
- register_question({
61
- 'cn': CN_TEXT_1,
62
- 'en': EN_TEXT_1,
63
- }, _checker_1)
64
-
 
 
 
65
 
66
  CN_TEXT_2 = """
67
  第一章第二题(小试牛刀),请你输入三个字(及)以内的问题,使模型的回答在30个字以上。
@@ -89,11 +96,14 @@ def _checker_2(question_text: str, user_text: str, answer_text: str, lang: str):
89
  return True, None
90
 
91
 
92
- register_question({
93
- 'cn': CN_TEXT_2,
94
- 'en': EN_TEXT_2,
95
- }, _checker_2)
96
-
 
 
 
97
 
98
  CN_TEXT_3 = """
99
  第一章第三题(短说长话),请你输入一个字的问题,使模型的回答在100个字以上。
@@ -107,6 +117,7 @@ For the third question in chapter 1, please enter a one-word question so that th
107
  Please enter your query below and click the submit button
108
  """
109
 
 
110
  def _checker_3(question_text: str, user_text: str, answer_text: str, lang: str):
111
  _ = question_text, lang
112
  answer_text = answer_text.strip()
@@ -119,11 +130,15 @@ def _checker_3(question_text: str, user_text: str, answer_text: str, lang: str):
119
  else:
120
  return True, None
121
 
122
- register_question({
123
- 'cn': CN_TEXT_3,
124
- 'en': EN_TEXT_3,
125
- }, _checker_3)
126
 
 
 
 
 
 
 
 
 
127
 
128
  CN_TEXT_4 = """
129
  第一章第四题(短说短话),请输入一个字的问题,使模型的回答字数小于20个字。
@@ -137,6 +152,7 @@ For the fourth question in chapter 1, please enter a one-word question so that t
137
  Please enter your query below and click the submit button
138
  """
139
 
 
140
  def _checker_4(question_text: str, user_text: str, answer_text: str, lang: str):
141
  _ = question_text, lang
142
  answer_text = answer_text.strip()
@@ -149,11 +165,15 @@ def _checker_4(question_text: str, user_text: str, answer_text: str, lang: str):
149
  else:
150
  return True, None
151
 
152
- register_question({
153
- 'cn': CN_TEXT_4,
154
- 'en': EN_TEXT_4,
155
- }, _checker_4)
156
 
 
 
 
 
 
 
 
 
157
 
158
  # CN_TEXT_5 = """
159
  # 第一章第五题(回文不变),请输入一个本身不是回文串的问题,使无论正着问还是倒着问,模型的回答是一样的。
 
1
  from .question import register_question
2
 
3
+
4
  def count_english_words(text: str):
5
  return len(text.split(' '))
6
 
7
+
8
  def count_chinese_words(text: str):
9
  return len(text)
10
 
11
+
12
  def check_if_chinese(text: str):
13
  return all('\u4e00' <= char <= '\u9fff' for char in text)
14
 
15
+
16
  def count_words(text: str, contain_punctuation: bool = False):
17
  chinese_words = []
18
  english_words = []
 
33
  temp_english_words = []
34
  other_words.append(char)
35
  if contain_punctuation:
36
+ return len(chinese_words) + len(english_words) + len(other_words)
37
  else:
38
+ return len(chinese_words) + len(english_words)
39
 
40
 
41
  CN_TEXT_1 = """
 
61
  return False, None
62
 
63
 
64
+ register_question(
65
+ {
66
+ 'cn': CN_TEXT_1,
67
+ 'en': EN_TEXT_1,
68
+ },
69
+ checkers=_checker_1,
70
+ name={'cn': '1-1 初来乍到', 'en': '1-1'},
71
+ )
72
 
73
  CN_TEXT_2 = """
74
  第一章第二题(小试牛刀),请你输入三个字(及)以内的问题,使模型的回答在30个字以上。
 
96
  return True, None
97
 
98
 
99
+ register_question(
100
+ {
101
+ 'cn': CN_TEXT_2,
102
+ 'en': EN_TEXT_2,
103
+ },
104
+ checkers=_checker_2,
105
+ name={'cn': '1-2 小试牛刀', 'en': '1-2'},
106
+ )
107
 
108
  CN_TEXT_3 = """
109
  第一章第三题(短说长话),请你输入一个字的问题,使模型的回答在100个字以上。
 
117
  Please enter your query below and click the submit button
118
  """
119
 
120
+
121
  def _checker_3(question_text: str, user_text: str, answer_text: str, lang: str):
122
  _ = question_text, lang
123
  answer_text = answer_text.strip()
 
130
  else:
131
  return True, None
132
 
 
 
 
 
133
 
134
+ register_question(
135
+ {
136
+ 'cn': CN_TEXT_3,
137
+ 'en': EN_TEXT_3,
138
+ },
139
+ checkers=_checker_3,
140
+ name={'cn': '1-3 短说长话', 'en': '1-3'}
141
+ )
142
 
143
  CN_TEXT_4 = """
144
  第一章第四题(短说短话),请输入一个字的问题,使模型的回答字数小于20个字。
 
152
  Please enter your query below and click the submit button
153
  """
154
 
155
+
156
  def _checker_4(question_text: str, user_text: str, answer_text: str, lang: str):
157
  _ = question_text, lang
158
  answer_text = answer_text.strip()
 
165
  else:
166
  return True, None
167
 
 
 
 
 
168
 
169
+ register_question(
170
+ {
171
+ 'cn': CN_TEXT_4,
172
+ 'en': EN_TEXT_4,
173
+ },
174
+ checkers=_checker_4,
175
+ name={'cn': '1-4 短说短话', 'en': '1-4'},
176
+ )
177
 
178
  # CN_TEXT_5 = """
179
  # 第一章第五题(回文不变),请输入一个本身不是回文串的问题,使无论正着问还是倒着问,模型的回答是一样的。
llmriddles/questions/level2.py CHANGED
@@ -54,13 +54,18 @@ def _en_checker_1(question_text: str, user_text: str, answer_text: str) -> Tuple
54
  return True, None
55
 
56
 
57
- register_question({
58
- 'cn': CN_TEXT_1,
59
- 'en': EN_TEXT_1,
60
- }, checkers={
61
- 'cn': _cn_checker_1,
62
- 'en': _en_checker_1,
63
- })
 
 
 
 
 
64
 
65
  CN_TEXT_2 = """
66
  第二章第二题(越说越大),请输入一个大于一的正整数作为问题,使回答里包含至少比它大一千的数。
@@ -102,13 +107,18 @@ def _en_checker_2(question_text: str, user_text: str, answer_text: str) -> Tuple
102
  return False, f'Did not detect a number of at least {value + 1000} in the output'
103
 
104
 
105
- register_question({
106
- 'cn': CN_TEXT_2,
107
- 'en': EN_TEXT_2,
108
- }, checkers={
109
- 'cn': _cn_checker_2,
110
- 'en': _en_checker_2,
111
- })
 
 
 
 
 
112
 
113
  CN_TEXT_3 = """
114
  第二章第三题(越说越小),请输入一个大于一的正整数作为问题,使回答里包含至少10个不同的至少比它小一千的自然数。
@@ -161,13 +171,18 @@ def _en_checker_3(question_text: str, user_text: str, answer_text: str) -> Tuple
161
  f'but it doesn\'t reach 10: {collected_values!r}'
162
 
163
 
164
- register_question({
165
- 'cn': CN_TEXT_3,
166
- 'en': EN_TEXT_3,
167
- }, checkers={
168
- 'cn': _cn_checker_3,
169
- 'en': _en_checker_3,
170
- })
 
 
 
 
 
171
 
172
  CN_TEXT_4 = """
173
  第二章第四题(警世名言),请在不提及1,4,5这三个字符的情况下让模型回答114514,不要有多余的字符。
@@ -191,13 +206,18 @@ def _en_checker_4(question_text: str, user_text: str, answer_text: str) -> Tuple
191
  return answer_text.strip() == '114514', None
192
 
193
 
194
- register_question({
195
- 'cn': CN_TEXT_4,
196
- 'en': EN_TEXT_4,
197
- }, checkers={
198
- 'cn': _cn_checker_4,
199
- 'en': _en_checker_4,
200
- })
 
 
 
 
 
201
 
202
  CN_TEXT_5 = """
203
  第二章第五题(开平方数),请输入一个大于一的平方数作为问题,使回答里包含它的平方根对应的数。
@@ -245,13 +265,18 @@ def _en_checker_5(question_text: str, user_text: str, answer_text: str) -> Tuple
245
  return False, f'Square root {sq} not detected'
246
 
247
 
248
- register_question({
249
- 'cn': CN_TEXT_5,
250
- 'en': EN_TEXT_5,
251
- }, checkers={
252
- 'cn': _cn_checker_5,
253
- 'en': _en_checker_5,
254
- })
 
 
 
 
 
255
 
256
  CN_TEXT_6 = """
257
  第二章第六题(得寸进狗),请提一个不包含“狗”这个字的10个字以内的问题,使回答中“狗”这个字出现的次数至少是问题字数的2倍。
@@ -290,10 +315,15 @@ def _en_checker_6(question_text: str, user_text: str, answer_text: str) -> Tuple
290
  f'which is less than {len(q_words) * 2} times.'
291
 
292
 
293
- register_question({
294
- 'cn': CN_TEXT_6,
295
- 'en': EN_TEXT_6,
296
- }, checkers={
297
- 'cn': _cn_checker_6,
298
- 'en': _en_checker_6,
299
- })
 
 
 
 
 
 
54
  return True, None
55
 
56
 
57
+ register_question(
58
+ {
59
+ 'cn': CN_TEXT_1,
60
+ 'en': EN_TEXT_1,
61
+ },
62
+ checkers={
63
+ 'cn': _cn_checker_1,
64
+ 'en': _en_checker_1,
65
+ },
66
+ name={'cn': '2-1 质数长度', 'en': '2-1'},
67
+ level=2
68
+ )
69
 
70
  CN_TEXT_2 = """
71
  第二章第二题(越说越大),请输入一个大于一的正整数作为问题,使回答里包含至少比它大一千的数。
 
107
  return False, f'Did not detect a number of at least {value + 1000} in the output'
108
 
109
 
110
+ register_question(
111
+ {
112
+ 'cn': CN_TEXT_2,
113
+ 'en': EN_TEXT_2,
114
+ },
115
+ checkers={
116
+ 'cn': _cn_checker_2,
117
+ 'en': _en_checker_2,
118
+ },
119
+ name={'cn': '2-2 越说越大', 'en': '2-2'},
120
+ level=2
121
+ )
122
 
123
  CN_TEXT_3 = """
124
  第二章第三题(越说越小),请输入一个大于一的正整数作为问题,使回答里包含至少10个不同的至少比它小一千的自然数。
 
171
  f'but it doesn\'t reach 10: {collected_values!r}'
172
 
173
 
174
+ register_question(
175
+ {
176
+ 'cn': CN_TEXT_3,
177
+ 'en': EN_TEXT_3,
178
+ },
179
+ checkers={
180
+ 'cn': _cn_checker_3,
181
+ 'en': _en_checker_3,
182
+ },
183
+ name={'cn': '2-3 越说越小', 'en': '2-3'},
184
+ level=2,
185
+ )
186
 
187
  CN_TEXT_4 = """
188
  第二章第四题(警世名言),请在不提及1,4,5这三个字符的情况下让模型回答114514,不要有多余的字符。
 
206
  return answer_text.strip() == '114514', None
207
 
208
 
209
+ register_question(
210
+ {
211
+ 'cn': CN_TEXT_4,
212
+ 'en': EN_TEXT_4,
213
+ },
214
+ checkers={
215
+ 'cn': _cn_checker_4,
216
+ 'en': _en_checker_4,
217
+ },
218
+ name={'cn': '2-4 警世名言', 'en': '2-4'},
219
+ level=2,
220
+ )
221
 
222
  CN_TEXT_5 = """
223
  第二章第五题(开平方数),请输入一个大于一的平方数作为问题,使回答里包含它的平方根对应的数。
 
265
  return False, f'Square root {sq} not detected'
266
 
267
 
268
+ register_question(
269
+ {
270
+ 'cn': CN_TEXT_5,
271
+ 'en': EN_TEXT_5,
272
+ },
273
+ checkers={
274
+ 'cn': _cn_checker_5,
275
+ 'en': _en_checker_5,
276
+ },
277
+ name={'cn': '2-5 开平方数', 'en': '2-5'},
278
+ level=2,
279
+ )
280
 
281
  CN_TEXT_6 = """
282
  第二章第六题(得寸进狗),请提一个不包含“狗”这个字的10个字以内的问题,使回答中“狗”这个字出现的次数至少是问题字数的2倍。
 
315
  f'which is less than {len(q_words) * 2} times.'
316
 
317
 
318
+ register_question(
319
+ {
320
+ 'cn': CN_TEXT_6,
321
+ 'en': EN_TEXT_6,
322
+ },
323
+ checkers={
324
+ 'cn': _cn_checker_6,
325
+ 'en': _en_checker_6,
326
+ },
327
+ name={'cn': '2-6 得寸进狗', 'en': '2-6'},
328
+ level=2
329
+ )
llmriddles/questions/level3.py CHANGED
@@ -1,5 +1,6 @@
1
  from .question import register_question
2
 
 
3
  def count_words(text: str, contain_punctuation: bool = False):
4
  chinese_words = []
5
  english_words = []
@@ -20,9 +21,10 @@ def count_words(text: str, contain_punctuation: bool = False):
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个字的提问,使模型的回答和提问完全一样。
@@ -36,23 +38,30 @@ For the first question in chapter 3, please enter a question of at least ten wor
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, level=3)
 
 
 
 
 
 
56
 
57
  CN_TEXT_2 = """
58
  第三章第二题(话自说自),请你输入一个至少10个字的提问,使模型的回答是问题的反序。
@@ -66,15 +75,16 @@ For the second question in chapter 3, please enter a question of at least ten wo
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()
@@ -86,10 +96,16 @@ def _checker_2(question_text: str, user_text: str, answer_text: str, lang: str):
86
  else:
87
  return False, None
88
 
89
- register_question({
90
- 'cn': CN_TEXT_2,
91
- 'en': EN_TEXT_2,
92
- }, _checker_2, level=3)
 
 
 
 
 
 
93
 
94
  CN_TEXT_3 = """
95
  第三章第三题(就是敢说),请你输入一个不包含“1”和“3”的提问,使模型的回答是一字不差的“1+1=3”(不需要引号)。
@@ -103,23 +119,30 @@ For the third question in chapter 3, please enter a question not contain "1" or
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, level=3)
 
 
 
 
 
 
123
 
124
  # CN_TEXT_4 = """
125
  # 第三章第四题(回文协变),请你输入一个本身不是回文串的问题,使得正着问和倒着问时,模型的回答本身不是回文且也是逆序。
 
1
  from .question import register_question
2
 
3
+
4
  def count_words(text: str, contain_punctuation: bool = False):
5
  chinese_words = []
6
  english_words = []
 
21
  temp_english_words = []
22
  other_words.append(char)
23
  if contain_punctuation:
24
+ return len(chinese_words) + len(english_words) + len(other_words)
25
  else:
26
+ return len(chinese_words) + len(english_words)
27
+
28
 
29
  CN_TEXT_1 = """
30
  第三章第一题(自说自话),请你输入一个至少10个字的提问,使模型的回答和提问完全一样。
 
38
  Please enter your query below and click the submit button
39
  """
40
 
41
+
42
  def _checker_1(question_text: str, user_text: str, answer_text: str, lang: str):
43
  _ = question_text, lang
44
  answer_text = answer_text.strip()
45
  user_text = user_text.strip()
46
 
47
  if count_words(user_text) < 10:
48
+ return False, "用户的问题长度应该至少10个字" if lang == 'cn' else 'Question should be no less than 10 words.'
49
 
50
  if answer_text == user_text:
51
  return True, None
52
  else:
53
  return False, None
54
 
55
+
56
+ register_question(
57
+ {
58
+ 'cn': CN_TEXT_1,
59
+ 'en': EN_TEXT_1,
60
+ },
61
+ checkers=_checker_1,
62
+ name={'cn': '3-1 自说自话', 'en': '3-1'},
63
+ level=3,
64
+ )
65
 
66
  CN_TEXT_2 = """
67
  第三章第二题(话自说自),请你输入一个至少10个字的提问,使模型的回答是问题的反序。
 
75
  Please enter your query below and click the submit button
76
  """
77
 
78
+
79
  def _checker_2(question_text: str, user_text: str, answer_text: str, lang: str):
80
  _ = question_text, lang
81
  answer_text = answer_text.strip()
82
  user_text = user_text.strip()
83
 
84
  if count_words(user_text) < 10:
85
+ return False, "用户的问题长度应该至少10个字" if lang == 'cn' else 'Question should be no less than 10 words.'
86
 
87
+ if lang == 'cn':
88
  user_text = user_text[::-1]
89
  else:
90
  words = user_text.split()
 
96
  else:
97
  return False, None
98
 
99
+
100
+ register_question(
101
+ {
102
+ 'cn': CN_TEXT_2,
103
+ 'en': EN_TEXT_2,
104
+ },
105
+ checkers=_checker_2,
106
+ name={'cn': '3-2 话自说自', 'en': '3-2'},
107
+ level=3,
108
+ )
109
 
110
  CN_TEXT_3 = """
111
  第三章第三题(就是敢说),请你输入一个不包含“1”和“3”的提问,使模型的回答是一字不差的“1+1=3”(不需要引号)。
 
119
  Please enter your query below and click the submit button
120
  """
121
 
122
+
123
  def _checker_3(question_text: str, user_text: str, answer_text: str, lang: str):
124
  _ = question_text, lang
125
  answer_text = answer_text.strip()
126
  user_text = user_text.strip()
127
 
128
  if '1' in user_text or '3' in user_text:
129
+ return False, "用户的问题不能包含“1”或“3”" if lang == 'cn' else 'Question should not contain \"1\" or \"3\".'
130
 
131
  if answer_text == '1+1=3':
132
  return True, None
133
  else:
134
  return False, None
135
 
136
+
137
+ register_question(
138
+ {
139
+ 'cn': CN_TEXT_3,
140
+ 'en': EN_TEXT_3,
141
+ },
142
+ checkers=_checker_3,
143
+ name={'cn': '3-3 就是敢说', 'en': '3-3'},
144
+ level=3,
145
+ )
146
 
147
  # CN_TEXT_4 = """
148
  # 第三章第四题(回文协变),请你输入一个本身不是回文串的问题,使得正着问和倒着问时,模型的回答本身不是回文且也是逆序。
llmriddles/questions/level4.py CHANGED
@@ -1,6 +1,7 @@
1
- from .question import register_question
2
  import re
3
 
 
 
4
 
5
  def check_if_is_number(text: str):
6
  try:
@@ -85,13 +86,19 @@ def _checker_3(question_text: str, user_text: str, answer_text: str, lang: str):
85
  return False, "问题应该是一个正整数" if lang == 'cn' else 'Question should be a positive integer.'
86
  elif int(question_text) == 1:
87
  return False, "问题应该是一个大于1的正整数" if lang == 'cn' else 'Question should be a positive integer greater than 1.'
88
- elif int(question_text)-1 not in get_all_numbers_in_a_sentence(answer_text) or int(question_text)+1 not in get_all_numbers_in_a_sentence(answer_text):
 
89
  return False, "回答中应该包含一个与问题相差1的数字" if lang == 'cn' else 'Answer should contain a number that is exactly 1 different from the question.'
90
  else:
91
  return True, None
92
 
93
 
94
- register_question({
95
- 'cn': CN_TEXT_3,
96
- 'en': EN_TEXT_3,
97
- }, _checker_3, level=4)
 
 
 
 
 
 
 
1
  import re
2
 
3
+ from .question import register_question
4
+
5
 
6
  def check_if_is_number(text: str):
7
  try:
 
86
  return False, "问题应该是一个正整数" if lang == 'cn' else 'Question should be a positive integer.'
87
  elif int(question_text) == 1:
88
  return False, "问题应该是一个大于1的正整数" if lang == 'cn' else 'Question should be a positive integer greater than 1.'
89
+ elif int(question_text) - 1 not in get_all_numbers_in_a_sentence(answer_text) or int(
90
+ question_text) + 1 not in get_all_numbers_in_a_sentence(answer_text):
91
  return False, "回答中应该包含一个与问题相差1的数字" if lang == 'cn' else 'Answer should contain a number that is exactly 1 different from the question.'
92
  else:
93
  return True, None
94
 
95
 
96
+ register_question(
97
+ {
98
+ 'cn': CN_TEXT_3,
99
+ 'en': EN_TEXT_3,
100
+ },
101
+ checkers=_checker_3,
102
+ name={'cn': '4-3 自然之密', 'en': '4-3'},
103
+ level=4,
104
+ )
llmriddles/questions/level5.py CHANGED
@@ -1,5 +1,6 @@
1
  from .question import register_question
2
 
 
3
  def count_words(text: str, contain_punctuation: bool = False):
4
  chinese_words = []
5
  english_words = []
@@ -20,9 +21,10 @@ def count_words(text: str, contain_punctuation: bool = False):
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
  第五章第一题(口是心非)请构造一个不少于十个字的问题,使得回答中不包含问题中的任意字符。
@@ -36,21 +38,27 @@ For the first question in chapter 5, Please construct a question of no less than
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, level=5)
56
 
 
 
 
 
 
 
 
 
 
 
1
  from .question import register_question
2
 
3
+
4
  def count_words(text: str, contain_punctuation: bool = False):
5
  chinese_words = []
6
  english_words = []
 
21
  temp_english_words = []
22
  other_words.append(char)
23
  if contain_punctuation:
24
+ return len(chinese_words) + len(english_words) + len(other_words)
25
  else:
26
+ return len(chinese_words) + len(english_words)
27
+
28
 
29
  CN_TEXT_1 = """
30
  第五章第一题(口是心非)请构造一个不少于十个字的问题,使得回答中不包含问题中的任意字符。
 
38
  Please enter your query below and click the submit button
39
  """
40
 
41
+
42
  def _checker_1(question_text: str, user_text: str, answer_text: str, lang: str):
43
  _ = question_text, lang
44
  answer_text = answer_text.strip()
45
  user_text = user_text.strip()
46
 
47
  if count_words(user_text) < 10:
48
+ return False, "用户的问题长度应该至少10个字" if lang == 'cn' else 'Question should be no less than 10 words.'
49
 
50
  if answer_text == user_text:
51
  return True, None
52
  else:
53
  return False, None
54
 
 
 
 
 
55
 
56
+ register_question(
57
+ {
58
+ 'cn': CN_TEXT_1,
59
+ 'en': EN_TEXT_1,
60
+ },
61
+ checkers=_checker_1,
62
+ name={'cn': '5-1 口是心非', 'en': '5-1'},
63
+ level=5,
64
+ )
llmriddles/questions/question.py CHANGED
@@ -3,14 +3,15 @@ from dataclasses import dataclass
3
  from typing import Union, Mapping, Literal, Callable, Tuple, List, Optional
4
 
5
  LangTyping = Literal['en', 'cn']
6
- MultiLangCheckerTyping = Callable[[str, str, str], Tuple[bool, Optional[str]]]
7
- SingleLangCheckerTyping = Callable[[str, str], Tuple[bool, Optional[str]]]
8
 
9
 
10
  @dataclass
11
  class Question:
12
  texts: Mapping[str, str]
13
  checker: MultiLangCheckerTyping
 
14
  level: int
15
 
16
 
@@ -19,6 +20,7 @@ _KNOWN_PROBLEMS = []
19
 
20
  def register_question(text: Union[Mapping[str, str], str],
21
  checkers: Union[Mapping[str, SingleLangCheckerTyping], MultiLangCheckerTyping],
 
22
  level: int = 1, default_lang='cn'):
23
  if isinstance(checkers, collections.abc.Mapping):
24
  _origin_checkers = checkers
@@ -35,7 +37,12 @@ def register_question(text: Union[Mapping[str, str], str],
35
  else:
36
  texts = text
37
 
38
- _KNOWN_PROBLEMS.append(Question(texts, checker, level))
 
 
 
 
 
39
 
40
 
41
  def list_ordered_questions() -> List[Question]:
 
3
  from typing import Union, Mapping, Literal, Callable, Tuple, List, Optional
4
 
5
  LangTyping = Literal['en', 'cn']
6
+ MultiLangCheckerTyping = Callable[[str, str, str, str], Tuple[bool, Optional[str]]]
7
+ SingleLangCheckerTyping = Callable[[str, str, str], Tuple[bool, Optional[str]]]
8
 
9
 
10
  @dataclass
11
  class Question:
12
  texts: Mapping[str, str]
13
  checker: MultiLangCheckerTyping
14
+ names: Mapping[str, str]
15
  level: int
16
 
17
 
 
20
 
21
  def register_question(text: Union[Mapping[str, str], str],
22
  checkers: Union[Mapping[str, SingleLangCheckerTyping], MultiLangCheckerTyping],
23
+ name=Union[Mapping[str, str], str],
24
  level: int = 1, default_lang='cn'):
25
  if isinstance(checkers, collections.abc.Mapping):
26
  _origin_checkers = checkers
 
37
  else:
38
  texts = text
39
 
40
+ if isinstance(name, str):
41
+ names = {default_lang: name}
42
+ else:
43
+ names = name
44
+
45
+ _KNOWN_PROBLEMS.append(Question(texts, checker, names, level))
46
 
47
 
48
  def list_ordered_questions() -> List[Question]: