Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion project/common/nanoeval/nanoeval/solvers/mcq_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@
""".strip()


def _answer_format_instruction(answer_keys: Sequence[str], allow_multiple_choices: bool) -> str:
answer_choices = ", ".join(answer_keys)
if allow_multiple_choices:
final_line_format = "'Answer: $LETTER1, $LETTER2, ...' (without quotes)"
choice_instruction = f"where each LETTER is one of {answer_choices}"
else:
final_line_format = "'Answer: $LETTER' (without quotes)"
choice_instruction = f"where LETTER is one of {answer_choices}"

return (
"Answer the following multiple choice question. The last line of your response should be "
f"of the following format: {final_line_format} {choice_instruction}. "
"Think step by step before answering."
)


@chz.chz
class OpenAIAPIMCQSolver(MCQSolver[Answer]):
model: str
Expand Down Expand Up @@ -94,7 +110,9 @@ async def solve(self, task: MCQTask) -> Answer:
{"role": "system", "content": "You are a helpful assistant."},
{
"role": "user",
"content": "Answer the following multiple choice question. The last line of your response should be of the following format: 'Answer: $LETTER' (without quotes) where LETTER is one of {answer_choices}. Think step by step before answering.",
"content": _answer_format_instruction(
list(letters_to_answers.keys()), question.allow_multiple_choices
),
},
{"role": "user", "content": prompt},
]
Expand Down