basic_git_setup.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from evaluator import *
  2. DESCRIPTION = "Test if the model can guide a user in a conversation to setup a git repo."
  3. TAGS = ['bash', "git", "agent"]
  4. question = """
  5. You are in a repository with two files `a` and `b`. Make a new git repo and then commit them both.
  6. On each round you should just give me just one command to type, I'll run it, and give you the exact output. I'll get started:
  7. INPUT: `pwd`
  8. OUTPUT: `/usr/src/app`
  9. INPUT: `ls`
  10. OUTPUT: `main.py a b`
  11. Now your turn. What do you want to run? Do not explain yourself, just give me exactly one command. Start your response with INPUT:"""
  12. def test_ok():
  13. import os
  14. success = os.popen("git rev-list --all --count").read().strip() == "1"
  15. return success
  16. def setup():
  17. import os
  18. open("a", "w").write("a")
  19. open("b", "w").write("b")
  20. os.popen('git config --global user.email "you@example.com"').read()
  21. os.popen('git config --global user.name "Your Name"').read()
  22. def do_extract(x):
  23. if 'INPUT:' in x:
  24. x = x.split("INPUT:")[1]
  25. try:
  26. to_send = x.split("`")[1]
  27. except:
  28. to_send = x.split("\n")[0]
  29. return to_send
  30. def do_prepare(x):
  31. print("Preparing to pass back", x)
  32. return f"OUTPUT: `{x}`.\n\nWhat command should I run next? Start your response with INPUT:"
  33. TestGitSimple = Setup(setup) >> question >> UntilDone(PyEvaluator(test_ok), (LLMConversation() >> PyFunc(do_extract) >> TerminalRun() >> PyFunc(do_prepare)), max_iters=4) >> PyEvaluator(test_ok)
  34. if __name__ == "__main__":
  35. print(run_test(TestGitSimple))