regex_remove_5_words.py 769 B

12345678910111213141516171819
  1. from evaluator import *
  2. DESCRIPTION = "Test if the model can write a Python function with a straightforward regex."
  3. TAGS = ['code', 'python']
  4. question = """
  5. Write a function called `match` in Python that uses a regex to find any word repeated 5 times or more. Return that word. If no word is repeated 5 times or more, return an empty string.
  6. """
  7. test_case, answer = make_python_test([("match('hi hi hi hi hi')", '"hi"'),
  8. ("match('hi hi hi hi')", '""'),
  9. ("match('hello this is is is is is a test')", '"is"')])
  10. TestRegex = question >> LLMRun() >> ExtractCode(keep_main=False) >> PythonRun(test_case) >> SubstringEvaluator(answer)
  11. if __name__ == "__main__":
  12. print(run_test(TestRegex))