Files
modelscope/examples/apps/llm_riddles/check_challenge.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

29 lines
912 B
Python

from app import challenges, generate_response
def check_answer(chap_idx,
challenge_idx,
input='input',
model_name='qwen-max'):
print('{}章 第{}'.format(chap_idx + 1, challenge_idx + 1))
challenge = challenges[chap_idx]['problems'][challenge_idx]
print(challenge['description'])
val_fn = challenge['validator']
response = generate_response(input, model_name)
try:
res = val_fn(response, input)
print('input:\n', input)
print('response:\n', response)
print('validation result: ', res)
except Exception:
import traceback
traceback.print_exc()
print('failed')
if __name__ == '__main__':
chap = 5
ques = 1
input = '请使用“盛 夏”、“蝉 鸣”、“少 年”、“橘 子味汽水”这几个词造句'
check_answer(chap - 1, ques - 1, input)