Spaces:
Runtime error
Runtime error
File size: 4,443 Bytes
7b6f638 bacbf19 f6acaa7 bacbf19 f6acaa7 7b6f638 f6acaa7 7b6f638 f6acaa7 7b6f638 f6acaa7 7b6f638 f6acaa7 7b6f638 f6acaa7 7b6f638 f6acaa7 7b6f638 f6acaa7 7b6f638 f6acaa7 7b6f638 f6acaa7 7b6f638 f6acaa7 7b6f638 f6acaa7 7b6f638 f6acaa7 7b6f638 f6acaa7 7b6f638 f6acaa7 7b6f638 f6acaa7 7b6f638 4200f57 7b6f638 4200f57 7b6f638 f6acaa7 7b6f638 bacbf19 |
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 |
import re
from .question import register_question
from .question import Checker
from typing import Callable
from .utility import count_words, word_reverse_text
from .math_tools import check_if_is_number, get_all_numbers
CN_TEXT_1 = """
第四章第一题(循环往复),请构造一个问题A,它的回复是不同于A的B,然后以B提问能再次得到A。
请在下面的输入框内填写你构造并点击按钮提交。
"""
EN_TEXT_1 = """
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.
Please enter your query below and click the submit button
"""
def _checker_1(question_text: str, user_text: str, answer_text: str, lang: str, llm_callback: Callable[[str], str]):
answer_text = answer_text.strip()
user_text = user_text.strip()
second_answer_text = llm_callback(answer_text)
if second_answer_text != user_text:
return False, f"B产生的回答和原问题A不一致:\n A: {user_text}\n B: {answer_text}\n Answer from B: {second_answer_text}" if lang == 'cn' else f'The answer from B is not the same as the original question A:\n A: {user_text}\n B: {answer_text}\n Answer from B: {second_answer_text}'
return True, None
register_question(
{
'cn': CN_TEXT_1,
'en': EN_TEXT_1,
},
checkers=Checker(_checker_1, required_input_keys=['question_text', 'user_text', 'answer_text', 'lang', 'llm_callback']),
name={'cn': '4-1 循环往复', 'en': '4-1'},
level=4,
)
CN_TEXT_2 = """
第四章第二题(惜字如金),本题可能没有答案,你可以自由的先去做其他的题。请输入一个字的问题,使模型的回答在16个字以内。
请在下面的输入框内填写你构造并点击按钮提交。
"""
EN_TEXT_2 = """
For the second question in chapter 4, please enter a question of one word so that the model's answer is within 16 words (The Chinese version of this problem may not have a correct answer, but the English version might).
Please enter your query below and click the submit button
"""
def _checker_2(question_text: str, user_text: str, answer_text: str, lang: str):
answer_text = answer_text.strip()
user_text = user_text.strip()
if count_words(user_text) > 1:
return False, "用户的问题长度应该在一个字以内" if lang == 'cn' else 'Question should be within one word.'
if count_words(answer_text) > 16:
return False, "大语言模型的答案应该在16个字以内" if lang == 'cn' else 'Answer should be within 16 words.'
else:
return True, None
register_question(
{
'cn': CN_TEXT_2,
'en': EN_TEXT_2,
},
checkers=_checker_2,
name={'cn': '4-2 惜字如金', 'en': '4-2'},
level=4,
)
CN_TEXT_3 = """
第四章第三题(自然之密),请输入一个大于一的正整数作为问题,使回答里包含和它刚好相差1的数。
请在下面的输入框内填写你构造并点击按钮提交。
"""
EN_TEXT_3 = """
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.
Please enter your query below and click the submit button
"""
def _checker_3(question_text: str, user_text: str, answer_text: str, lang: str):
_ = question_text, lang
answer_text = answer_text.strip()
user_text = user_text.strip()
if not check_if_is_number(user_text):
return False, "问题应该是一个正整数" if lang == 'cn' else 'Question should be a positive integer.'
elif int(user_text) == 1:
return False, "问题应该是一个大于1的正整数" if lang == 'cn' else 'Question should be a positive integer greater than 1.'
elif int(user_text) - 1 not in get_all_numbers(answer_text) and int(
user_text) + 1 not in get_all_numbers(answer_text):
return False, "回答中应该包含一个与问题相差1的数字" if lang == 'cn' else 'Answer should contain a number that is exactly 1 different from the question.'
else:
return True, None
register_question(
{
'cn': CN_TEXT_3,
'en': EN_TEXT_3,
},
checkers=_checker_3,
name={'cn': '4-3 自然之密', 'en': '4-3'},
level=4,
)
|