add 3 problems to llm-riddle and fix some bugs (#632)

* add 3 problems


---------

Co-authored-by: wenmeng.zwm <wenmeng.zwm@alibaba-inc.com>
Co-authored-by: YorickHe <yongyi.hyy@alibaba-inc.com>
This commit is contained in:
Yorick He
2023-11-10 17:47:56 +08:00
committed by GitHub
parent 0e9f21decf
commit b3e8fd0609
5 changed files with 38 additions and 4 deletions

View File

@@ -176,7 +176,7 @@ with block as demo:
disabled=True)
challenge_result = gr.Textbox(label='挑战结果', disabled=True)
chatbot = gr.Chatbot(
lines=8, label='Qwen-max', elem_classes='control-height')
lines=8, label='Qwen-plus', elem_classes='control-height')
message = gr.Textbox(lines=2, label='输入')
with gr.Row():

View File

@@ -1,11 +1,15 @@
def validate_palindrome_invariance(origin_input, response, generate_response):
"""
验证器函数,检查对于给定的问题,正着问和倒着问的模型回答是否一致。
验证器函数,检查对于给定的问题,检验是否是回文串,且正着问和倒着问的模型回答是否一致。
:param origin_input: 原始问题
:return: True 如果回答一致,否则 False
"""
# 检查原始输入不是回文
if origin_input == origin_input[::-1]:
return False
# 将原始问题倒序并提交
reversed_question = origin_input[::-1]
reversed_response = generate_response(reversed_question)
@@ -66,5 +70,13 @@ challenge1 = {
lambda response, input: '' not in input and response.count('') \
>= 3
},
{
'title':
'第7题 事半功倍',
'description':
'请输入一个本身不是回文串的问题,使模型回答的长度刚好是问题长度的两倍。',
'validator':
lambda response, input: input != input[::-1] and len(response) == 2 * len(input)
},
]
}

View File

@@ -90,5 +90,18 @@ challenge2 = {
'' not in input and len(input) <= 10 and # noqa: W504
response.count('') >= 2 * len(input))
},
{
'title':
'第7题 暗藏玄机',
'description':
'请输入一个大于一的正整数作为问题使回答包含一个两位数其十位上的数字比个位上的数字小5。',
'validator':
lambda response, input:
(input.isdigit() and int(input) > 1 and (len({
int(num)
for num in re.findall(r'\d+', response)
if len(num) == 2 and int(num[1]) - int(num[0]) == 5
}) >= 1))
},
]
}

View File

@@ -1,3 +1,5 @@
import re
def validate_palindrome_inverse(origin_input, response, generate_response):
"""
验证器函数,检查对于给定的问题,正着问和倒着问的模型的回答本身不回文且也是逆序的关系。
@@ -49,7 +51,7 @@ challenge3 = {
'title':
'第3题 就是敢说',
'description':
'请在不提及1,3这个字符的情况下让模型回答1+1=3不要有多余的字符。',
'请在不提及1,3这个字符的情况下让模型回答1+1=3不要有多余的字符。',
'validator':
lambda response, input: response.strip() == '1+1=3' and all(
c not in input for c in ['1', '3'])
@@ -63,5 +65,13 @@ challenge3 = {
lambda response, input, generate_response:
validate_palindrome_inverse(input, response, generate_response)
},
{
'title':
'第5题 答非所问',
'description':
'请输入一个以“为什么”开头,以“?”结尾的不包含数字的问题,使回答中只包含数字。',
'validator':
lambda response, input: '为什么' == input[:3] and "" == input[-1] and len(re.findall(r'\d+', input)) == 0 and response.isdigit()
},
]
}

View File

@@ -1,6 +1,5 @@
import re
def validate_reciprocal_question(input, response, generate_response):
"""
验证器函数检查给定的问题A和回答B是否能够通过以B作为新的提问得到原始问题A作为回答。