MCPcopy Create free account
hub / github.com/23japhone/HALO / format_example

Function format_example

utils/basic_operation.py:304–324  ·  view source on GitHub ↗

format the subject example from a df into prompt, which conclude question, choices and correct choices

(df: pd.DataFrame, 
                   idx: int, 
                   include_answer: bool = True)

Source from the content-addressed store, hash-verified

302
303
304def format_example(df: pd.DataFrame,
305 idx: int,
306 include_answer: bool = True) -> str:
307 '''
308 format the subject example from a df into prompt, which conclude question, choices and correct choices
309 '''
310 choices = ["A", "B", "C", "D"]
311 prompt = f"[Example {idx + 1}]\nquestion:\n```\n{df.iloc[idx, 0]}\n```\n"
312 options = "options:\n```"
313 k = df.shape[1] - 2
314 for j in range(k):
315 if j == k - 1:
316 options += f"\n{choices[j]}. {df.iloc[idx, j + 1]}\n```\n"
317 else:
318 options += f"\n{choices[j]}. {df.iloc[idx, j + 1]}"
319 answer = "answer:"
320 if include_answer:
321 answer += f" {df.iloc[idx, k + 1]}\n\n"
322 prompt += options
323 prompt += answer
324 return prompt
325
326
327def gen_prompt(train_df: pd.DataFrame,

Callers 1

gen_promptFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected