Norman Swain commited on
Commit
46ad888
1 Parent(s): 09b80dc

style(hus): add chapter 5 question and polish readme (#3)

Browse files

* style(hus):add new chapter and new question

* style(hus):polish readme(add submit custom level)

* style(hus):fix chapter name

---------

Co-authored-by: Swain <[email protected]>

README.md CHANGED
@@ -38,8 +38,15 @@ QUESTION_LANG=en QUESTION_LLM='mistral-7b' python3 -u app.py
38
  我们的目标是通过这一游戏,让参与者深入领略到提示工程(prompt engineering)和自然语言处理的令人着迷之处。这个过程将向玩家们展示,如何巧妙地构建提示词(prompts),以及如何运用它们来引发人工智能系统的惊人反应,同时也帮助他们更好地理解深度学习和自然语言处理技术的不可思议之处。
39
 
40
  ## :raising_hand: 如何提交设计好的关卡
41
- 如果有好玩的问题或想法,欢迎玩家提交自己的创意,可以通过
42
  [发起 Pull Request](https://github.com/opendilab/LLMRiddles/compare) 向我们提交, 我们会在审核通过后收录至关卡中。
 
 
 
 
 
 
 
43
 
44
  ## :writing_hand: 未来计划
45
 
 
38
  我们的目标是通过这一游戏,让参与者深入领略到提示工程(prompt engineering)和自然语言处理的令人着迷之处。这个过程将向玩家们展示,如何巧妙地构建提示词(prompts),以及如何运用它们来引发人工智能系统的惊人反应,同时也帮助他们更好地理解深度学习和自然语言处理技术的不可思议之处。
39
 
40
  ## :raising_hand: 如何提交设计好的关卡
41
+ 如果有好玩的问题或想法,欢迎玩家提交自己的创意,可以
42
  [发起 Pull Request](https://github.com/opendilab/LLMRiddles/compare) 向我们提交, 我们会在审核通过后收录至关卡中。
43
+ 问题的设计格式应包含以下几点:
44
+ - Pull Request标题,示例:feature(username): 章节X-关卡设计
45
+ - 希望被提及的ID
46
+ - 对应章节问题文件的修改
47
+ - init.py的修改
48
+
49
+ 完整示例请参考:[提交属于自己的关卡设计]()
50
 
51
  ## :writing_hand: 未来计划
52
 
llmriddles/questions/__init__.py CHANGED
@@ -2,8 +2,10 @@ from .executor import QuestionExecutor
2
  from .level1 import __file__ as _level1_file_
3
  from .level3 import __file__ as _level3_file_
4
  from .level4 import __file__ as _level4_file_
 
5
  from .question import Question, register_question, list_ordered_questions
6
 
7
  _ = _level1_file_
8
  _ = _level3_file_
9
  _ = _level4_file_
 
 
2
  from .level1 import __file__ as _level1_file_
3
  from .level3 import __file__ as _level3_file_
4
  from .level4 import __file__ as _level4_file_
5
+ from .level5 import __file__ as _level5_file_
6
  from .question import Question, register_question, list_ordered_questions
7
 
8
  _ = _level1_file_
9
  _ = _level3_file_
10
  _ = _level4_file_
11
+ _ = _level5_file_
llmriddles/questions/level5.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .question import register_question
2
+
3
+ def count_words(text: str, contain_punctuation: bool = False):
4
+ chinese_words = []
5
+ english_words = []
6
+ other_words = []
7
+ temp_english_words = []
8
+ for char in text:
9
+ if '\u4e00' <= char <= '\u9fff':
10
+ chinese_words.append(char)
11
+ if len(temp_english_words) > 0:
12
+ english_words.append(''.join(temp_english_words))
13
+ temp_english_words = []
14
+ else:
15
+ if char.isalpha():
16
+ temp_english_words.append(char)
17
+ else:
18
+ if len(temp_english_words) > 0:
19
+ english_words.append(''.join(temp_english_words))
20
+ temp_english_words = []
21
+ other_words.append(char)
22
+ if contain_punctuation:
23
+ return len(chinese_words)+len(english_words)+len(other_words)
24
+ else:
25
+ return len(chinese_words)+len(english_words)
26
+
27
+ CN_TEXT_1 = """
28
+ 第五章第一题(口是心非)请构造一个不少于十个字的问题,使得回答中不包含问题中的任意字符。
29
+
30
+ 请在下面的输入框内填写你的提问并点击按钮提交。
31
+ """
32
+
33
+ EN_TEXT_1 = """
34
+ For the first question in chapter 5, Please construct a question of no less than ten words so that the answer does not contain any of the characters in the question.
35
+
36
+ Please enter your query below and click the submit button
37
+ """
38
+
39
+ def _checker_1(question_text: str, user_text: str, answer_text: str, lang: str):
40
+ _ = question_text, lang
41
+ answer_text = answer_text.strip()
42
+ user_text = user_text.strip()
43
+
44
+ if count_words(user_text) < 10:
45
+ return False, "用户的问题长度应该至少10个字" if lang=='cn' else 'Question should be no less than 10 words.'
46
+
47
+ if answer_text == user_text:
48
+ return True, None
49
+ else:
50
+ return False, None
51
+
52
+ register_question({
53
+ 'cn': CN_TEXT_1,
54
+ 'en': EN_TEXT_1,
55
+ }, _checker_1, level=5)
56
+