Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle cases where a model does not repeat the function signature #184

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
8 changes: 6 additions & 2 deletions Evaluation/HumanEval/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ def extract_generation_code(example: str, lang_code: str, verbose: bool=False):
code_block = code_block[:main_start]

func_name, func_prefix = get_function_name(question, lang)

found_signature = False
try:
start = code_block.lower().index(func_name.lower())
found_signature = True
indent = 0
while start - indent >= 0 and code_block[start - indent-1] == ' ':
indent += 1
Expand All @@ -93,7 +94,10 @@ def extract_generation_code(example: str, lang_code: str, verbose: bool=False):
if lang_code.lower() in ['php', 'ts', 'js']:
body += '\n' + ' '*indent + '}'

generation = func_prefix + '\n' + body + '\n'
if not found_signature:
generation = question + '\n' + body + '\n'
else:
generation = func_prefix + '\n' + body + '\n'
example['generation'] = generation

except Exception as ex:
Expand Down