Skip to content

Commit

Permalink
only look for the function_name definition to check if the output is …
Browse files Browse the repository at this point in the history
…repeated
  • Loading branch information
jmercat committed Jan 9, 2025
1 parent 6e774fc commit 6f5e718
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions eval/chat_benchmarks/HumanEval/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ def extract_generation_code(example: str, lang_code: str, verbose: bool = False)
lang = setting["full_name"]
indent = setting["indent"]

# If the model did not repeat the question, add it to the output
if question not in output:
output = "```" + lang + "\n" + question + "\n" + get_code_block(output, lang_code) + "\n```"

try:
func_name, func_prefix = get_function_name(question, lang)

# If the model did not repeat the question, add it to the output
if func_name not in output:
output = "```" + lang + "\n" + question + "\n" + get_code_block(output, lang_code) + "\n```"

code_block: str = re.findall(f"```{lang.lower()}\n(.*?)```", output, re.DOTALL | re.IGNORECASE)[0]
if verbose:
print(">>> Task: {}\n{}".format(task_id, code_block))
Expand All @@ -85,8 +87,6 @@ def extract_generation_code(example: str, lang_code: str, verbose: bool = False)
main_start = code_block.index(setting["main"])
code_block = code_block[:main_start]

func_name, func_prefix = get_function_name(question, lang)

try:
start = code_block.lower().index(func_name.lower())
indent = 0
Expand Down

0 comments on commit 6f5e718

Please sign in to comment.