root commited on
Commit
ca09329
·
1 Parent(s): c48dfd2

update app

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -45,7 +45,7 @@ def unsafe_execute(prompt, completion, suffix, test_case, timeout=3):
45
  except Exception as e:
46
  # 捕获异常并记录堆栈跟踪
47
  output = ''
48
- error_output = e
49
  finally:
50
  # 恢复标准输出和标准错误
51
  sys.stdout = old_stdout
@@ -57,6 +57,11 @@ def unsafe_execute(prompt, completion, suffix, test_case, timeout=3):
57
  elif not output and not error_output:
58
  return 'Pass all test cases!'
59
  else:
 
 
 
 
 
60
  return f'Error: {error_output}'
61
  def read_problems() -> Dict[str, Dict]:
62
  benchmark_file = "HumanEval-SingleLineInfilling.jsonl.gz"
@@ -428,6 +433,8 @@ def get_example_input():
428
  problem = problems[task_id]
429
  prefix, suffix = problem['prompt'], problem['suffix']
430
  test_case = problem['test']
 
 
431
  test_case = test_case.replace('def check(candidate):', 'def run_test():')
432
  test_case = test_case.replace('candidate', problem['entry_point'])
433
  test_case = test_case + '\n\n\nrun_test()'
 
45
  except Exception as e:
46
  # 捕获异常并记录堆栈跟踪
47
  output = ''
48
+ error_output = str(e)
49
  finally:
50
  # 恢复标准输出和标准错误
51
  sys.stdout = old_stdout
 
57
  elif not output and not error_output:
58
  return 'Pass all test cases!'
59
  else:
60
+ error_lines = error_output.splitlines()
61
+ if error_lines:
62
+ return f'Error: {error_lines[-1]}'
63
+ else:
64
+ return 'Error: Unknown error'
65
  return f'Error: {error_output}'
66
  def read_problems() -> Dict[str, Dict]:
67
  benchmark_file = "HumanEval-SingleLineInfilling.jsonl.gz"
 
433
  problem = problems[task_id]
434
  prefix, suffix = problem['prompt'], problem['suffix']
435
  test_case = problem['test']
436
+ pattern = r'METADATA\s*=\s*\{.*?\}\n\n'
437
+ cleaned_code = re.sub(pattern, '', code, flags=re.DOTALL)
438
  test_case = test_case.replace('def check(candidate):', 'def run_test():')
439
  test_case = test_case.replace('candidate', problem['entry_point'])
440
  test_case = test_case + '\n\n\nrun_test()'