Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(zjow): fix checker 2-2 #20

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions llmriddles/questions/level2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sympy

from .question import register_question
from .math_tools import get_all_numbers

CN_TEXT_1 = """
第二章第一题(质数长度),你需要提出一个字数是质数的问题,使回答的长度刚好是它的下一个质数。
Expand Down Expand Up @@ -83,8 +84,7 @@ def _cn_checker_2(question_text: str, user_text: str, answer_text: str) -> Tuple
except (TypeError, ValueError):
return False, f'输入内容{user_text!r},并非一个大于1的正整数'

for value_item in re.findall('[-+]?\d+', answer_text):
value_item = int(value_item)
for value_item in get_all_numbers(answer_text):
if value_item >= value + 1000:
return True, f'检测到输出中数字{value_item},满足要求'

Expand All @@ -99,8 +99,7 @@ def _en_checker_2(question_text: str, user_text: str, answer_text: str) -> Tuple
except (TypeError, ValueError):
return False, f'You entered {user_text!r}, which is not a positive integer greater than 1'

for value_item in re.findall('[-+]?\d+', answer_text):
value_item = int(value_item)
for value_item in get_all_numbers(answer_text):
if value_item >= value + 1000:
return True, f'Detected the number {value_item} in the output, which meets the requirement'

Expand Down Expand Up @@ -137,8 +136,7 @@ def _cn_checker_3(question_text: str, user_text: str, answer_text: str) -> Tuple
return False, f'输入内容{user_text!r},并非一个大于1的正整数'

collected_values = []
for value_item in re.findall('[-+]?\d+', answer_text):
value_item = int(value_item)
for value_item in get_all_numbers(answer_text):
if value_item <= value - 1000:
collected_values.append(value_item)

Expand All @@ -158,8 +156,7 @@ def _en_checker_3(question_text: str, user_text: str, answer_text: str) -> Tuple
return False, f'You entered {user_text!r}, which is not a positive integer greater than 1'

collected_values = []
for value_item in re.findall('[-+]?\d+', answer_text):
value_item = int(value_item)
for value_item in get_all_numbers(answer_text):
if value_item <= value - 1000:
collected_values.append(value_item)

Expand Down Expand Up @@ -238,8 +235,7 @@ def _cn_checker_5(question_text: str, user_text: str, answer_text: str) -> Tuple
return False, f'输入内容{user_text!r},并非一个大于1的平方数'

sq = int(value ** 0.5)
for value_item in re.findall('[-+]?\d+', answer_text):
value_item = int(value_item)
for value_item in get_all_numbers(answer_text):
if value_item == sq:
return True, f'检测到平方根数{sq}'
else:
Expand All @@ -257,8 +253,7 @@ def _en_checker_5(question_text: str, user_text: str, answer_text: str) -> Tuple
return False, f'The input, {user_text!r}, is not a square number greater than 1'

sq = int(value ** 0.5)
for value_item in re.findall('[-+]?\d+', answer_text):
value_item = int(value_item)
for value_item in get_all_numbers(answer_text):
if value_item == sq:
return True, f'Detected square root: {sq}'
else:
Expand Down
16 changes: 3 additions & 13 deletions llmriddles/questions/level4.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,7 @@
from typing import Callable
from .utility import count_words, word_reverse_text

def check_if_is_number(text: str):
try:
int(text)
return True
except ValueError:
return False


def get_all_numbers_in_a_sentence(text: str):
return [int(i) for i in re.findall(r'\d+', text)]

from .math_tools import check_if_is_number, get_all_numbers

CN_TEXT_1 = """
第四章第一题(循环往复),请构造一个问题A,它的回复是不同于A的B,然后以B提问能再次得到A。
Expand Down Expand Up @@ -105,8 +95,8 @@ def _checker_3(question_text: str, user_text: str, answer_text: str, lang: str):
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_in_a_sentence(answer_text) and int(
user_text) + 1 not in get_all_numbers_in_a_sentence(answer_text):
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
Expand Down
20 changes: 20 additions & 0 deletions llmriddles/questions/math_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import re


def check_if_is_number(text: str):
try:
int(text)
return True
except ValueError:
return False

def get_all_numbers_in_a_sentence(text: str):
return [int(i) for i in re.findall(r'[-+]?\d+', text)]

def get_all_numbers_in_a_sentence_with_comma(text: str):
#remove comma in numbers
text = text.replace(',', '')
return [int(i) for i in re.findall(r'[-+]?\d+', text)]

def get_all_numbers(text: str):
return get_all_numbers_in_a_sentence(text) + get_all_numbers_in_a_sentence_with_comma(text)