Files
modelscope/examples/apps/llm_riddles/challenges/ch1.py
wenmeng zhou c2e900ee54 update llm riddles (#624)
* add multi online support

* add readme and requirements.txt

* refactor code to llm and challenges and update readme

* handle llm exception and return empty str

* update error handling

* fix gradio version and add concurrency control

* remove concurrency_limit

* update reame
2023-11-09 20:04:16 +08:00

71 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
def validate_palindrome_invariance(origin_input, respons, generate_response):
"""
验证器函数,检查对于给定的问题,正着问和倒着问的模型回答是否一致。
:param origin_input: 原始问题
:return: True 如果回答一致,否则 False
"""
# 将原始问题倒序并提交
reversed_question = origin_input[::-1]
reversed_response = generate_response(reversed_question)
# 比较两个回答是否一致
return response.strip() == reversed_response.strip()
challenge1 = {
'name':
'第一章 对话之趣',
'problems': [
{
'title': '第1题 初来乍到',
'description': '请你构造一个问题使模型的回答是一字不差的“1+1=3”不需要引号',
'validator': lambda response, input: response.strip() == '1+1=3'
},
{
'title':
'第2题 小试牛刀',
'description':
'请输入三个字以内的问题使模型的回答在30个字以上。',
'validator':
lambda response, input: len(input) <= 3 and len(response) > 30
},
{
'title':
'第3题 短说长话',
'description':
'请输入一个字的问题使模型的回答在100个字以上。',
'validator':
lambda response, input: len(input) == 1 and len(response) > 100
},
{
'title':
'第4题 短说短话',
'description':
'请输入一个字的问题使模型的回答在20个字以内。',
'validator':
lambda response, input: len(input) == 1 and len(response) <= 20
},
{
'title':
'第5题 回文不变',
'description':
'请输入一个本身不是回文串的问题,使无论正着问还是倒着问,模型的回答是一样的。',
# 验证器将取决于模型的行为,这里只是一个占位符
'validator':
lambda response, input: validate_palindrome_invariance(
input, response)
},
{
'title':
'第6题 无中生狗',
'description':
'请提一个不包含“狗”这个字的问题但是回答中至少出现3次“狗”这个字。',
'validator':
lambda response, input: '' not in input and response.count('') \
>= 3
},
]
}