Files
modelscope/examples/apps/llm_riddles/challenges/ch5.py
DuskSwan 3695e4491f LLM riddle add challenge (#692)
* 1. add a challenge in chapter 2 as challenge 9
2. add a check_challenge.py script to makesure a challenge actually has answer
3. add blank lines to the file README_CN.md to look better

* delete redundant function

* code style check

* code style check

* style checkout change

---------

Co-authored-by: DuskSwan <aquark@foxmail.com>
2023-12-24 21:28:34 +08:00

36 lines
1.5 KiB
Python

def check_word_in_sentence(words, sentence):
return [word in sentence for word in words]
challenge5 = {
'name':
'第五章 登堂入室',
'problems': [
{
'title':
'第1题 盛夏少年',
'description':
'模型的回答应该包含“盛夏”、“蝉鸣”、“少年”、“橘子味汽水”这几个词,同时输入的问题不能包含其中任一个词。',
'validator':
lambda response, input: all(
check_word_in_sentence(['盛夏', '蝉鸣', '少年', '橘子味汽水'], response))
and not any(
check_word_in_sentence(['盛夏', '蝉鸣', '少年', '橘子味汽水'], input))
},
{
'title':
'第2题 蝉鸣日出',
'description':
'模型的回答应该包含“盛夏”、“蝉鸣”、“少年”、“橘子味汽水”、“日出”这几个词,同时输入的问题不能包含其中任一个字。',
'validator':
lambda response, input: all(
check_word_in_sentence(
['盛夏', '蝉鸣', '少年', '橘子味汽水', '日出'], response)) and not any(
check_word_in_sentence([
'', '', '', '', '', '', '', '', '', '',
'', '', ''
], input))
},
]
}