shorten_python_if_missing.py 661 B

1234567891011121314151617181920212223
  1. from evaluator import *
  2. DESCRIPTION = "Test if the model can shorten a line of python with an equal line."
  3. TAGS = ['code', 'python']
  4. question = """
  5. Shorten this python code. Keep the name the same.
  6. ```
  7. def foo(arr, keys):
  8. return [[x[y] if y in x else -5 for y in keys] for x in arr]
  9. ```
  10. """
  11. test_case, answer = make_python_test([("foo([{1: 2, 3: 4, 5: 6}], [1, 2, 3, 4])", "[[2, -5, 4, -5]]")])
  12. TestShortenPyGet = question >> LLMRun() >> (SubstringEvaluator(".get") & (ExtractCode() >> PythonRun(test_case) >> SubstringEvaluator(answer)))
  13. if __name__ == "__main__":
  14. print(run_test(TestShortenPyGet))