You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_math_user_proxy_agent.py 3.6 kB

raise error when msg is invalid; fix docstr; improve ResponsiveAgent; update doc and packaging; capture ipython output; find code blocks with llm when regex fails. (#1154) * autogen.agent -> autogen.agentchat * bug fix in portfolio * notebook * timeout * timeout * infer lang; close #1150 * timeout * message context * context handling * add sender to generate_reply * clean up the receive function * move mathchat to contrib * contrib * last_message * Add OptiGuide: agent and notebook * Optiguide notebook: add figures and URL 1. figures and code points to remote URL 2. simplify the prompt for the interpreter, because all information is already in the chat history. * Update name: Agent -> GenericAgent * Update notebook * Rename: GenericAgent -> ResponsiveAgent * Rebase to autogen.agentchat * OptiGuide: Comment, sytle, and notebook updates * simplify optiguide * raise error when msg is invalid; fix docstr * allow return None for generate_reply() * update_system_message * test update_system_message * simplify optiguide * simplify optiguide * simplify optiguide * simplify optiguide * move test * add test and fix bug * doc update * doc update * doc update * color * optiguide * prompt * test danger case * packaging * docker * remove path in traceback * capture ipython output * simplify * find code blocks with llm * find code with llm * order * order * fix bug in context handling * print executing msg * print executing msg * test find code * test find code * disable find_code * default_auto_reply * default auto reply * remove optiguide * remove -e --------- Co-authored-by: Beibin Li <beibin79@gmail.com>
3 years ago
2 years ago
raise error when msg is invalid; fix docstr; improve ResponsiveAgent; update doc and packaging; capture ipython output; find code blocks with llm when regex fails. (#1154) * autogen.agent -> autogen.agentchat * bug fix in portfolio * notebook * timeout * timeout * infer lang; close #1150 * timeout * message context * context handling * add sender to generate_reply * clean up the receive function * move mathchat to contrib * contrib * last_message * Add OptiGuide: agent and notebook * Optiguide notebook: add figures and URL 1. figures and code points to remote URL 2. simplify the prompt for the interpreter, because all information is already in the chat history. * Update name: Agent -> GenericAgent * Update notebook * Rename: GenericAgent -> ResponsiveAgent * Rebase to autogen.agentchat * OptiGuide: Comment, sytle, and notebook updates * simplify optiguide * raise error when msg is invalid; fix docstr * allow return None for generate_reply() * update_system_message * test update_system_message * simplify optiguide * simplify optiguide * simplify optiguide * simplify optiguide * move test * add test and fix bug * doc update * doc update * doc update * color * optiguide * prompt * test danger case * packaging * docker * remove path in traceback * capture ipython output * simplify * find code blocks with llm * find code with llm * order * order * fix bug in context handling * print executing msg * print executing msg * test find code * test find code * disable find_code * default_auto_reply * default auto reply * remove optiguide * remove -e --------- Co-authored-by: Beibin Li <beibin79@gmail.com>
3 years ago
2 years ago
raise error when msg is invalid; fix docstr; improve ResponsiveAgent; update doc and packaging; capture ipython output; find code blocks with llm when regex fails. (#1154) * autogen.agent -> autogen.agentchat * bug fix in portfolio * notebook * timeout * timeout * infer lang; close #1150 * timeout * message context * context handling * add sender to generate_reply * clean up the receive function * move mathchat to contrib * contrib * last_message * Add OptiGuide: agent and notebook * Optiguide notebook: add figures and URL 1. figures and code points to remote URL 2. simplify the prompt for the interpreter, because all information is already in the chat history. * Update name: Agent -> GenericAgent * Update notebook * Rename: GenericAgent -> ResponsiveAgent * Rebase to autogen.agentchat * OptiGuide: Comment, sytle, and notebook updates * simplify optiguide * raise error when msg is invalid; fix docstr * allow return None for generate_reply() * update_system_message * test update_system_message * simplify optiguide * simplify optiguide * simplify optiguide * simplify optiguide * move test * add test and fix bug * doc update * doc update * doc update * color * optiguide * prompt * test danger case * packaging * docker * remove path in traceback * capture ipython output * simplify * find code blocks with llm * find code with llm * order * order * fix bug in context handling * print executing msg * print executing msg * test find code * test find code * disable find_code * default_auto_reply * default auto reply * remove optiguide * remove -e --------- Co-authored-by: Beibin Li <beibin79@gmail.com>
3 years ago
raise error when msg is invalid; fix docstr; improve ResponsiveAgent; update doc and packaging; capture ipython output; find code blocks with llm when regex fails. (#1154) * autogen.agent -> autogen.agentchat * bug fix in portfolio * notebook * timeout * timeout * infer lang; close #1150 * timeout * message context * context handling * add sender to generate_reply * clean up the receive function * move mathchat to contrib * contrib * last_message * Add OptiGuide: agent and notebook * Optiguide notebook: add figures and URL 1. figures and code points to remote URL 2. simplify the prompt for the interpreter, because all information is already in the chat history. * Update name: Agent -> GenericAgent * Update notebook * Rename: GenericAgent -> ResponsiveAgent * Rebase to autogen.agentchat * OptiGuide: Comment, sytle, and notebook updates * simplify optiguide * raise error when msg is invalid; fix docstr * allow return None for generate_reply() * update_system_message * test update_system_message * simplify optiguide * simplify optiguide * simplify optiguide * simplify optiguide * move test * add test and fix bug * doc update * doc update * doc update * color * optiguide * prompt * test danger case * packaging * docker * remove path in traceback * capture ipython output * simplify * find code blocks with llm * find code with llm * order * order * fix bug in context handling * print executing msg * print executing msg * test find code * test find code * disable find_code * default_auto_reply * default auto reply * remove optiguide * remove -e --------- Co-authored-by: Beibin Li <beibin79@gmail.com>
3 years ago
raise error when msg is invalid; fix docstr; improve ResponsiveAgent; update doc and packaging; capture ipython output; find code blocks with llm when regex fails. (#1154) * autogen.agent -> autogen.agentchat * bug fix in portfolio * notebook * timeout * timeout * infer lang; close #1150 * timeout * message context * context handling * add sender to generate_reply * clean up the receive function * move mathchat to contrib * contrib * last_message * Add OptiGuide: agent and notebook * Optiguide notebook: add figures and URL 1. figures and code points to remote URL 2. simplify the prompt for the interpreter, because all information is already in the chat history. * Update name: Agent -> GenericAgent * Update notebook * Rename: GenericAgent -> ResponsiveAgent * Rebase to autogen.agentchat * OptiGuide: Comment, sytle, and notebook updates * simplify optiguide * raise error when msg is invalid; fix docstr * allow return None for generate_reply() * update_system_message * test update_system_message * simplify optiguide * simplify optiguide * simplify optiguide * simplify optiguide * move test * add test and fix bug * doc update * doc update * doc update * color * optiguide * prompt * test danger case * packaging * docker * remove path in traceback * capture ipython output * simplify * find code blocks with llm * find code with llm * order * order * fix bug in context handling * print executing msg * print executing msg * test find code * test find code * disable find_code * default_auto_reply * default auto reply * remove optiguide * remove -e --------- Co-authored-by: Beibin Li <beibin79@gmail.com>
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import pytest
  2. import sys
  3. import autogen
  4. from autogen.agentchat.contrib.math_user_proxy_agent import (
  5. MathUserProxyAgent,
  6. _remove_print,
  7. _add_print_to_last_line,
  8. )
  9. from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST
  10. @pytest.mark.skipif(
  11. sys.platform in ["darwin", "win32"],
  12. reason="do not run on MacOS or windows",
  13. )
  14. def test_math_user_proxy_agent():
  15. try:
  16. import openai
  17. except ImportError:
  18. return
  19. from autogen.agentchat.assistant_agent import AssistantAgent
  20. conversations = {}
  21. autogen.ChatCompletion.start_logging(conversations)
  22. config_list = autogen.config_list_from_json(
  23. OAI_CONFIG_LIST,
  24. file_location=KEY_LOC,
  25. filter_dict={
  26. "model": ["gpt-4", "gpt4", "gpt-4-32k", "gpt-4-32k-0314", "gpt-4-32k-v0314"],
  27. },
  28. )
  29. assistant = AssistantAgent(
  30. "assistant",
  31. system_message="You are a helpful assistant.",
  32. llm_config={
  33. "request_timeout": 600,
  34. "seed": 42,
  35. "config_list": config_list,
  36. },
  37. )
  38. mathproxyagent = MathUserProxyAgent(name="MathChatAgent", human_input_mode="NEVER")
  39. assistant.reset()
  40. math_problem = "$x^3=125$. What is x?"
  41. # assistant.receive(
  42. # message=mathproxyagent.generate_init_message(math_problem),
  43. # sender=mathproxyagent,
  44. # )
  45. mathproxyagent.initiate_chat(assistant, problem=math_problem)
  46. print(conversations)
  47. def test_add_remove_print():
  48. # test add print
  49. code = "a = 4\nb = 5\na,b"
  50. assert _add_print_to_last_line(code) == "a = 4\nb = 5\nprint(a,b)"
  51. # test remove print
  52. code = """print("hello")\na = 4*5\nprint("wolrld")"""
  53. assert _remove_print(code) == "a = 4*5"
  54. # test remove print. Only remove prints without indentation
  55. code = "if 4 > 5:\n\tprint('True')"
  56. assert _remove_print(code) == code
  57. @pytest.mark.skipif(
  58. sys.platform in ["darwin", "win32"],
  59. reason="do not run on MacOS or windows",
  60. )
  61. def test_execute_one_python_code():
  62. mathproxyagent = MathUserProxyAgent(name="MathChatAgent", human_input_mode="NEVER")
  63. # no output found 1
  64. code = "x=3"
  65. assert mathproxyagent.execute_one_python_code(code)[0] == "No output found. Make sure you print the results."
  66. # no output found 2
  67. code = "if 4 > 5:\n\tprint('True')"
  68. assert mathproxyagent.execute_one_python_code(code)[0] == "No output found."
  69. # return error
  70. code = "2+'2'"
  71. assert "Error:" in mathproxyagent.execute_one_python_code(code)[0]
  72. # save previous status
  73. mathproxyagent.execute_one_python_code("x=3\ny=x*2")
  74. assert mathproxyagent.execute_one_python_code("print(y)")[0].strip() == "6"
  75. code = "print('*'*2001)"
  76. assert (
  77. mathproxyagent.execute_one_python_code(code)[0]
  78. == "Your requested query response is too long. You might have made a mistake. Please revise your reasoning and query."
  79. )
  80. def test_execute_one_wolfram_query():
  81. mathproxyagent = MathUserProxyAgent(name="MathChatAgent", human_input_mode="NEVER")
  82. code = "2x=3"
  83. try:
  84. mathproxyagent.execute_one_wolfram_query(code)[0]
  85. except ValueError:
  86. print("Wolfrma API key not found. Skip test.")
  87. def test_generate_prompt():
  88. mathproxyagent = MathUserProxyAgent(name="MathChatAgent", human_input_mode="NEVER")
  89. assert "customized" in mathproxyagent.generate_init_message(
  90. problem="2x=4", prompt_type="python", customized_prompt="customized"
  91. )
  92. if __name__ == "__main__":
  93. # test_add_remove_print()
  94. # test_execute_one_python_code()
  95. # test_generate_prompt()
  96. test_math_user_proxy_agent()