MCPcopy Create free account
hub / github.com/LeapLabTHU/Absolute-Zero-Reasoner / construct_prompt

Function construct_prompt

evaluation/math_eval/eval/utils.py:221–293  ·  view source on GitHub ↗
(example, data_name, args)

Source from the content-addressed store, hash-verified

219
220
221def construct_prompt(example, data_name, args):
222 if args.adapt_few_shot and data_name in [
223 "gaokao2024_I",
224 "gaokao2024_II",
225 "gaokao_math_qa",
226 "gaokao2024_mix",
227 "cn_middle_school",
228 ]:
229 demos = load_prompt(data_name, args.prompt_type, 5)
230 else:
231 demos = load_prompt(data_name, args.prompt_type, args.num_shots)
232 prompt_type = args.prompt_type
233 if prompt_type == "platypus_fs":
234 prompt_type = "cot"
235 if prompt_type == "tool-integrated":
236 prompt_type = "tora"
237
238 prompt_temp = PROMPT_TEMPLATES[args.prompt_type]
239
240 splitter = prompt_temp[2]
241 input_template, output_template, splitter = (
242 prompt_temp[0],
243 prompt_temp[1],
244 prompt_temp[2],
245 )
246 if args.prompt_type == "qwen25-math-cot":
247 # Hotfix to support putting all demos into a single turn
248 demo_prompt = splitter.join([q + "\n" + a for q, a in demos])
249 else:
250 demo_prompt = splitter.join(
251 [
252 input_template.format(input=q) + output_template.format(output=a)
253 for q, a in demos
254 ]
255 )
256 context = input_template.format(input=example["question"])
257 if len(demo_prompt) == 0 or (
258 args.adapt_few_shot and example["gt_ans"] not in ["A", "B", "C", "D", "E"]
259 ):
260 full_prompt = context
261 else:
262 if args.prompt_type == "qwen25-math-cot":
263 # Hotfix to supportting put all demos into a single turn
264 full_prompt = demo_prompt + splitter + example["question"]
265 full_prompt = input_template.format(input=full_prompt)
266 else:
267 full_prompt = demo_prompt + splitter + context
268
269 if args.prompt_type == "platypus_fs":
270 full_prompt_temp = (
271 "Below is an instruction that describes a task. "
272 "Write a response that appropriately completes the request.\n\n"
273 "### Instruction:\n{instruction}\n\n### Response:\n"
274 )
275 full_prompt = full_prompt_temp.format(instruction=full_prompt)
276
277 if prompt_type == "tora":
278 full_prompt = (

Callers 1

mainFunction · 0.90

Calls 1

load_promptFunction · 0.85

Tested by

no test coverage detected