why_broken_flask_extra_brace.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from evaluator import *
  2. DESCRIPTION = "This test checks is the model can figure out the user has put an accidental extra brace in the request body."
  3. TAGS = ['explain', 'python']
  4. question = """
  5. Why isn't this working
  6. ```
  7. @app.route('/getsimilar', methods=['GET'])
  8. def getsimilar():
  9. print('args',request.args)
  10. positive = request.args.get('positive', '')
  11. positive = positive.split("##")
  12. negative = request.args.get('negative', '')
  13. negative = negative.split("##")
  14. keep_yes = [i for i,x in enumerate(titles) if x in positive]
  15. set1_yes = emb[keep_yes]
  16. keep_no = [i for i,x in enumerate(titles) if x in negative]
  17. set1_no = emb[keep_no]
  18. print("OK", len(set1_yes), len(set1_no))
  19. ```
  20. I see
  21. ```
  22. args ImmutableMultiDict([('positive', 'Title: Towards Evaluating the Robustness of Neural Networks\nAuthors: Nicholas Carlini; David Wagner'), ('negative', 'Title: On Evaluating Adversarial Robustness Authors: Nicholas Carlini; Anish Athalye; Nicolas Papernot; Wieland Brendel; Jonas Rauber; Dimitris Tsipras; Ian Goodfellow; Aleksander Madry; Alexey Kurakin}')])
  23. OK 1 0
  24. ```
  25. Why don't I see OK 1 1? Instead it just says OK 1 0. List exactly one reason explaining what's wrong and what one change would fix it.
  26. """
  27. judge = "I asked a question about why some code was incorrect. The answer is \"because the input contains an extra curly brace }\". Does this student answer say that?\n\n<A>\n\nAnswer either 'The student passes' or 'The student fails'."
  28. TestBrokenExtraBrace = question >> LLMRun() >> (LLMRun(judge, llm=EVAL_LLM) >> SubstringEvaluator("student passes"))
  29. if __name__ == "__main__":
  30. print(run_test(TestBrokenExtraBrace))