@@ -57,7 +57,50 @@ def test_multi_choices_multi_answers():
5757 for letter , answer in question .letter_mapping .items ():
5858 assert f"{ letter } :{ answer } " in rendered_prompt
5959
60+ def test_multi_choices_multi_answers_original_letters ():
61+ prompt = MultiChoicesMultiAnswersPrompt (use_original_letters = True )
62+ question_text = "What is true about Paris"
63+ question = Question (id = 1 ,
64+ question = question_text ,
65+ answer = "It is the capital of France" ,
66+ additional_answers = ["The Louvre is there" ,
67+ "The effeil tower is there" ],
68+ choices = ["It is the capital of Portugal" ,
69+ "It is the capital of Germany" ,
70+ "The Guggenheim museum is there" ,
71+ "THe MoMa is there" ],
72+ original_letters = ['G' , 'F' , 'E' , 'D' , 'C' , 'B' , 'A' ])
73+
74+ task = Task (name = "Paris Info" , type = TaskType .multiple_choices_multiple_answers ,
75+ scorer = get_scorer (ScorerType .contains_answer_letters_insensitive ))
76+ rendered_prompt = prompt .render (question , task )
77+ print (prompt .template )
78+ print (rendered_prompt )
79+
80+ assert question_text in rendered_prompt
81+ for choice in question .choices :
82+ assert choice in rendered_prompt
83+ for answer in question .answer :
84+ assert answer in rendered_prompt
85+ for c in ['A' , 'B' , 'C' , 'D' , 'E' , 'F' , 'G' ]:
86+ assert f"\n { c } :" in rendered_prompt
87+
88+ # check that the answer letter is tied to the correct answer
89+
90+ assert f"{ answer } " in rendered_prompt
91+
92+ # check that the additional answers are in the prompt
93+ for additional_answer in question .additional_answers :
94+ assert additional_answer in rendered_prompt
6095
96+ # check the mapping from letter to answer exist
97+ for letter , answer in question .letter_mapping .items ():
98+ assert f"{ letter } :{ answer } " in rendered_prompt
99+ # test the original order is preserved
100+ for idx , answer in enumerate (
101+ [question .answer ] + question .additional_answers + question .choices
102+ ):
103+ assert f"{ question .original_letters [idx ]} :{ answer } " in rendered_prompt
61104
62105def test_multi_choices ():
63106 prompt = MultiChoicesPrompt ()
@@ -83,6 +126,34 @@ def test_multi_choices():
83126 for letter , answer in question .letter_mapping .items ():
84127 assert f"{ letter } :{ answer } " in rendered_prompt
85128
129+ def test_multi_choices_original_letters ():
130+ prompt = MultiChoicesPrompt (use_original_letters = True )
131+ question_text = "What is the capital of France?"
132+ question = Question (id = 1 , question = question_text , answer = "Paris" ,
133+ choices = ["London" , "Berlin" , "Madrid" ],
134+ original_letters = ["D" , "B" , "A" , "C" ])
135+ task = Task (name = "City capital" , type = TaskType .multiple_choices ,
136+ scorer = get_scorer (ScorerType .contain_text_insensitive ))
137+ rendered_prompt = prompt .render (question , task )
138+ print (prompt .template )
139+ print (rendered_prompt )
140+
141+
142+ assert question_text in rendered_prompt
143+ for choice in question .choices :
144+ assert choice in rendered_prompt
145+ assert question .answer in rendered_prompt
146+ for c in ['A' , 'B' , 'C' , 'D' ]:
147+ assert f"\n { c } :" in rendered_prompt
148+
149+ # check that the answer letter is tied to the correct answer
150+ assert f"{ question .answer_letter } :{ question .answer } " in rendered_prompt
151+ for letter , answer in question .letter_mapping .items ():
152+ assert f"{ letter } :{ answer } " in rendered_prompt
153+ # test the original order is preserved
154+ for idx , answer in enumerate ([question .answer ] + question .choices ):
155+ assert f"{ question .original_letters [idx ]} :{ answer } " in rendered_prompt
156+
86157def test_repeated_used_multi_choices ():
87158 prompt = MultiChoicesPrompt ()
88159 question_text = "What is the capital of France?"
@@ -122,4 +193,4 @@ def test_answer_in_choice_fail():
122193 task = Task (name = "City capital" , type = TaskType .multiple_choices ,
123194 scorer = get_scorer (ScorerType .contain_text_insensitive ))
124195 with pytest .raises (AssertionError ):
125- prompt .render (question , task )
196+ prompt .render (question , task )
0 commit comments