Spaces:
Runtime error
Runtime error
niuyazhe
commited on
Commit
•
7b6f638
1
Parent(s):
d2f4f1c
feature(nyz): add naive level4
Browse files- app.py +2 -2
- llmriddles/questions/__init__.py +2 -0
- llmriddles/questions/level4.py +97 -0
app.py
CHANGED
@@ -122,7 +122,7 @@ if __name__ == '__main__':
|
|
122 |
gr_question = gr.TextArea(placeholder=question_ph, label=question_label)
|
123 |
gr_api_key = gr.Text(placeholder=api_ph, label=api_label, type='password', visible=_need_api_key())
|
124 |
with gr.Row():
|
125 |
-
gr_submit = gr.Button(submit_label, interactive=
|
126 |
gr_next = gr.Button(next_label)
|
127 |
|
128 |
with gr.Column():
|
@@ -144,7 +144,7 @@ if __name__ == '__main__':
|
|
144 |
if _qid >= len(_QUESTIONS):
|
145 |
del _QUESTION_IDS[uuid_]
|
146 |
return game_cleared_label, '', '', {}, '', \
|
147 |
-
gr.Button(submit_label, interactive=
|
148 |
gr.Button(try_again_label, interactive=True), \
|
149 |
''
|
150 |
else:
|
|
|
122 |
gr_question = gr.TextArea(placeholder=question_ph, label=question_label)
|
123 |
gr_api_key = gr.Text(placeholder=api_ph, label=api_label, type='password', visible=_need_api_key())
|
124 |
with gr.Row():
|
125 |
+
gr_submit = gr.Button(submit_label, interactive=False)
|
126 |
gr_next = gr.Button(next_label)
|
127 |
|
128 |
with gr.Column():
|
|
|
144 |
if _qid >= len(_QUESTIONS):
|
145 |
del _QUESTION_IDS[uuid_]
|
146 |
return game_cleared_label, '', '', {}, '', \
|
147 |
+
gr.Button(submit_label, interactive=False), \
|
148 |
gr.Button(try_again_label, interactive=True), \
|
149 |
''
|
150 |
else:
|
llmriddles/questions/__init__.py
CHANGED
@@ -1,7 +1,9 @@
|
|
1 |
from .executor import QuestionExecutor
|
2 |
from .level1 import __file__ as _level1_file_
|
3 |
from .level3 import __file__ as _level3_file_
|
|
|
4 |
from .question import Question, register_question, list_ordered_questions
|
5 |
|
6 |
_ = _level1_file_
|
7 |
_ = _level3_file_
|
|
|
|
1 |
from .executor import QuestionExecutor
|
2 |
from .level1 import __file__ as _level1_file_
|
3 |
from .level3 import __file__ as _level3_file_
|
4 |
+
from .level4 import __file__ as _level4_file_
|
5 |
from .question import Question, register_question, list_ordered_questions
|
6 |
|
7 |
_ = _level1_file_
|
8 |
_ = _level3_file_
|
9 |
+
_ = _level4_file_
|
llmriddles/questions/level4.py
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from .question import register_question
|
2 |
+
import re
|
3 |
+
|
4 |
+
|
5 |
+
def check_if_is_number(text: str):
|
6 |
+
try:
|
7 |
+
int(text)
|
8 |
+
return True
|
9 |
+
except ValueError:
|
10 |
+
return False
|
11 |
+
|
12 |
+
|
13 |
+
def get_all_numbers_in_a_sentence(text: str):
|
14 |
+
return [int(i) for i in re.findall(r'\d+', text)]
|
15 |
+
|
16 |
+
|
17 |
+
# CN_TEXT_1 = """
|
18 |
+
# 第四章第一题,请构造一个问题A,它的回复是不同于A的B,然后以B提问能再次得到A。
|
19 |
+
|
20 |
+
# 请在下面的输入框内填写你构造并点击按钮提交。
|
21 |
+
# """
|
22 |
+
|
23 |
+
# EN_TEXT_1 = """
|
24 |
+
# For the first question in chapter 4, please make a question A whose answer is B that is different from A, and then ask B to get A again.
|
25 |
+
|
26 |
+
# Please enter your query below and click the submit button
|
27 |
+
# """
|
28 |
+
|
29 |
+
|
30 |
+
# def _checker_1(question_text: str, user_text: str, answer_text: str, lang: str):
|
31 |
+
# _ = question_text, lang
|
32 |
+
# answer_text = answer_text.strip()
|
33 |
+
# user_text = user_text.strip()
|
34 |
+
# pass
|
35 |
+
|
36 |
+
# register_question({
|
37 |
+
# 'cn': CN_TEXT_1,
|
38 |
+
# 'en': EN_TEXT_1,
|
39 |
+
# }, _checker_1, level=4)
|
40 |
+
|
41 |
+
|
42 |
+
# CN_TEXT_2 = """
|
43 |
+
# 第四章第二题,
|
44 |
+
|
45 |
+
# 请在下面的输入框内填写你构造并点击按钮提交。
|
46 |
+
# """
|
47 |
+
|
48 |
+
# EN_TEXT_2 = """
|
49 |
+
# For the second question in chapter 4,
|
50 |
+
|
51 |
+
# Please enter your query below and click the submit button
|
52 |
+
# """
|
53 |
+
|
54 |
+
|
55 |
+
# def _checker_2(question_text: str, user_text: str, answer_text: str, lang: str):
|
56 |
+
# _ = question_text, lang
|
57 |
+
# answer_text = answer_text.strip()
|
58 |
+
# user_text = user_text.strip()
|
59 |
+
# pass
|
60 |
+
|
61 |
+
# register_question({
|
62 |
+
# 'cn': CN_TEXT_2,
|
63 |
+
# 'en': EN_TEXT_2,
|
64 |
+
# }, _checker_2, level=4)
|
65 |
+
|
66 |
+
|
67 |
+
CN_TEXT_3 = """
|
68 |
+
第四章第三题,
|
69 |
+
|
70 |
+
请在下面的输入框内填写你构造并点击按钮提交。
|
71 |
+
"""
|
72 |
+
|
73 |
+
EN_TEXT_3 = """
|
74 |
+
For the third question in chapter 4, please enter a positive integer greater than one as the question so that the answer contains a number that is exactly 1 different from it.
|
75 |
+
|
76 |
+
Please enter your query below and click the submit button
|
77 |
+
"""
|
78 |
+
|
79 |
+
|
80 |
+
def _checker_3(question_text: str, user_text: str, answer_text: str, lang: str):
|
81 |
+
_ = question_text, lang
|
82 |
+
answer_text = answer_text.strip()
|
83 |
+
user_text = user_text.strip()
|
84 |
+
if not check_if_is_number(question_text):
|
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)
|