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_function_call.py 7.6 kB

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
Support function_call in `autogen/agent` (#1091) * update funccall * code format * update to comments * update notebook * remove test for py3.7 * allow funccall to class functions * add test and clean up notebook * revise notebook and test * update * update mathagent * Update flaml/autogen/agent/agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * revise to comments * revise function call design, notebook and test. add doc * code format * ad message_to_dict function * update mathproxyagent * revise docstr * update * Update flaml/autogen/agent/math_user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update flaml/autogen/agent/math_user_proxy_agent.py Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> * simply funccall in userproxyagent, rewind auto-gen.md, revise to comments * code format * update * remove notebook for another pr * revise oai_conversation part in agent, revise function exec in user_proxy_agent * update test_funccall * update * update * fix pydantic version * Update test/autogen/test_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * fix bug * fix bug * update * update is_termination_msg to accept dict --------- Co-authored-by: Chi Wang <wang.chi@microsoft.com> Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> Co-authored-by: Li Jiang <bnujli@gmail.com>
3 years ago
2 years ago
Support function_call in `autogen/agent` (#1091) * update funccall * code format * update to comments * update notebook * remove test for py3.7 * allow funccall to class functions * add test and clean up notebook * revise notebook and test * update * update mathagent * Update flaml/autogen/agent/agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * revise to comments * revise function call design, notebook and test. add doc * code format * ad message_to_dict function * update mathproxyagent * revise docstr * update * Update flaml/autogen/agent/math_user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update flaml/autogen/agent/math_user_proxy_agent.py Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> * simply funccall in userproxyagent, rewind auto-gen.md, revise to comments * code format * update * remove notebook for another pr * revise oai_conversation part in agent, revise function exec in user_proxy_agent * update test_funccall * update * update * fix pydantic version * Update test/autogen/test_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * fix bug * fix bug * update * update is_termination_msg to accept dict --------- Co-authored-by: Chi Wang <wang.chi@microsoft.com> Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> Co-authored-by: Li Jiang <bnujli@gmail.com>
3 years ago
Support function_call in `autogen/agent` (#1091) * update funccall * code format * update to comments * update notebook * remove test for py3.7 * allow funccall to class functions * add test and clean up notebook * revise notebook and test * update * update mathagent * Update flaml/autogen/agent/agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * revise to comments * revise function call design, notebook and test. add doc * code format * ad message_to_dict function * update mathproxyagent * revise docstr * update * Update flaml/autogen/agent/math_user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update flaml/autogen/agent/math_user_proxy_agent.py Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> * simply funccall in userproxyagent, rewind auto-gen.md, revise to comments * code format * update * remove notebook for another pr * revise oai_conversation part in agent, revise function exec in user_proxy_agent * update test_funccall * update * update * fix pydantic version * Update test/autogen/test_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * fix bug * fix bug * update * update is_termination_msg to accept dict --------- Co-authored-by: Chi Wang <wang.chi@microsoft.com> Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> Co-authored-by: Li Jiang <bnujli@gmail.com>
3 years ago
2 years ago
Support function_call in `autogen/agent` (#1091) * update funccall * code format * update to comments * update notebook * remove test for py3.7 * allow funccall to class functions * add test and clean up notebook * revise notebook and test * update * update mathagent * Update flaml/autogen/agent/agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * revise to comments * revise function call design, notebook and test. add doc * code format * ad message_to_dict function * update mathproxyagent * revise docstr * update * Update flaml/autogen/agent/math_user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update flaml/autogen/agent/math_user_proxy_agent.py Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> * simply funccall in userproxyagent, rewind auto-gen.md, revise to comments * code format * update * remove notebook for another pr * revise oai_conversation part in agent, revise function exec in user_proxy_agent * update test_funccall * update * update * fix pydantic version * Update test/autogen/test_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * fix bug * fix bug * update * update is_termination_msg to accept dict --------- Co-authored-by: Chi Wang <wang.chi@microsoft.com> Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> Co-authored-by: Li Jiang <bnujli@gmail.com>
3 years ago
Support function_call in `autogen/agent` (#1091) * update funccall * code format * update to comments * update notebook * remove test for py3.7 * allow funccall to class functions * add test and clean up notebook * revise notebook and test * update * update mathagent * Update flaml/autogen/agent/agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * revise to comments * revise function call design, notebook and test. add doc * code format * ad message_to_dict function * update mathproxyagent * revise docstr * update * Update flaml/autogen/agent/math_user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update flaml/autogen/agent/math_user_proxy_agent.py Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> * simply funccall in userproxyagent, rewind auto-gen.md, revise to comments * code format * update * remove notebook for another pr * revise oai_conversation part in agent, revise function exec in user_proxy_agent * update test_funccall * update * update * fix pydantic version * Update test/autogen/test_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * fix bug * fix bug * update * update is_termination_msg to accept dict --------- Co-authored-by: Chi Wang <wang.chi@microsoft.com> Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> Co-authored-by: Li Jiang <bnujli@gmail.com>
3 years ago
Support function_call in `autogen/agent` (#1091) * update funccall * code format * update to comments * update notebook * remove test for py3.7 * allow funccall to class functions * add test and clean up notebook * revise notebook and test * update * update mathagent * Update flaml/autogen/agent/agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * revise to comments * revise function call design, notebook and test. add doc * code format * ad message_to_dict function * update mathproxyagent * revise docstr * update * Update flaml/autogen/agent/math_user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update flaml/autogen/agent/math_user_proxy_agent.py Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> * simply funccall in userproxyagent, rewind auto-gen.md, revise to comments * code format * update * remove notebook for another pr * revise oai_conversation part in agent, revise function exec in user_proxy_agent * update test_funccall * update * update * fix pydantic version * Update test/autogen/test_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * fix bug * fix bug * update * update is_termination_msg to accept dict --------- Co-authored-by: Chi Wang <wang.chi@microsoft.com> Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> Co-authored-by: Li Jiang <bnujli@gmail.com>
3 years ago
Support function_call in `autogen/agent` (#1091) * update funccall * code format * update to comments * update notebook * remove test for py3.7 * allow funccall to class functions * add test and clean up notebook * revise notebook and test * update * update mathagent * Update flaml/autogen/agent/agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * revise to comments * revise function call design, notebook and test. add doc * code format * ad message_to_dict function * update mathproxyagent * revise docstr * update * Update flaml/autogen/agent/math_user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update flaml/autogen/agent/math_user_proxy_agent.py Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> * simply funccall in userproxyagent, rewind auto-gen.md, revise to comments * code format * update * remove notebook for another pr * revise oai_conversation part in agent, revise function exec in user_proxy_agent * update test_funccall * update * update * fix pydantic version * Update test/autogen/test_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * fix bug * fix bug * update * update is_termination_msg to accept dict --------- Co-authored-by: Chi Wang <wang.chi@microsoft.com> Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> Co-authored-by: Li Jiang <bnujli@gmail.com>
3 years ago
Support function_call in `autogen/agent` (#1091) * update funccall * code format * update to comments * update notebook * remove test for py3.7 * allow funccall to class functions * add test and clean up notebook * revise notebook and test * update * update mathagent * Update flaml/autogen/agent/agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * revise to comments * revise function call design, notebook and test. add doc * code format * ad message_to_dict function * update mathproxyagent * revise docstr * update * Update flaml/autogen/agent/math_user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update flaml/autogen/agent/math_user_proxy_agent.py Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> * simply funccall in userproxyagent, rewind auto-gen.md, revise to comments * code format * update * remove notebook for another pr * revise oai_conversation part in agent, revise function exec in user_proxy_agent * update test_funccall * update * update * fix pydantic version * Update test/autogen/test_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * fix bug * fix bug * update * update is_termination_msg to accept dict --------- Co-authored-by: Chi Wang <wang.chi@microsoft.com> Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> Co-authored-by: Li Jiang <bnujli@gmail.com>
3 years ago
Support function_call in `autogen/agent` (#1091) * update funccall * code format * update to comments * update notebook * remove test for py3.7 * allow funccall to class functions * add test and clean up notebook * revise notebook and test * update * update mathagent * Update flaml/autogen/agent/agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * revise to comments * revise function call design, notebook and test. add doc * code format * ad message_to_dict function * update mathproxyagent * revise docstr * update * Update flaml/autogen/agent/math_user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update flaml/autogen/agent/math_user_proxy_agent.py Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> * simply funccall in userproxyagent, rewind auto-gen.md, revise to comments * code format * update * remove notebook for another pr * revise oai_conversation part in agent, revise function exec in user_proxy_agent * update test_funccall * update * update * fix pydantic version * Update test/autogen/test_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * fix bug * fix bug * update * update is_termination_msg to accept dict --------- Co-authored-by: Chi Wang <wang.chi@microsoft.com> Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> Co-authored-by: Li Jiang <bnujli@gmail.com>
3 years ago
Support function_call in `autogen/agent` (#1091) * update funccall * code format * update to comments * update notebook * remove test for py3.7 * allow funccall to class functions * add test and clean up notebook * revise notebook and test * update * update mathagent * Update flaml/autogen/agent/agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * revise to comments * revise function call design, notebook and test. add doc * code format * ad message_to_dict function * update mathproxyagent * revise docstr * update * Update flaml/autogen/agent/math_user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update flaml/autogen/agent/math_user_proxy_agent.py Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> * simply funccall in userproxyagent, rewind auto-gen.md, revise to comments * code format * update * remove notebook for another pr * revise oai_conversation part in agent, revise function exec in user_proxy_agent * update test_funccall * update * update * fix pydantic version * Update test/autogen/test_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * fix bug * fix bug * update * update is_termination_msg to accept dict --------- Co-authored-by: Chi Wang <wang.chi@microsoft.com> Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> Co-authored-by: Li Jiang <bnujli@gmail.com>
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. try:
  2. from openai import OpenAI
  3. except ImportError:
  4. OpenAI = None
  5. import pytest
  6. import asyncio
  7. import json
  8. import autogen
  9. from autogen.math_utils import eval_math_responses
  10. from test_assistant_agent import KEY_LOC
  11. @pytest.mark.skipif(OpenAI is None, reason="openai>=1 not installed")
  12. def test_eval_math_responses():
  13. config_list = autogen.config_list_from_models(
  14. KEY_LOC, exclude="aoai", model_list=["gpt-4-0613", "gpt-3.5-turbo-0613", "gpt-3.5-turbo-16k"]
  15. )
  16. functions = [
  17. {
  18. "name": "eval_math_responses",
  19. "description": "Select a response for a math problem using voting, and check if the response is correct if the solution is provided",
  20. "parameters": {
  21. "type": "object",
  22. "properties": {
  23. "responses": {
  24. "type": "array",
  25. "items": {"type": "string"},
  26. "description": "The responses in a list",
  27. },
  28. "solution": {
  29. "type": "string",
  30. "description": "The canonical solution",
  31. },
  32. },
  33. "required": ["responses"],
  34. },
  35. },
  36. ]
  37. client = autogen.OpenAIWrapper(config_list=config_list)
  38. response = client.create(
  39. messages=[
  40. {
  41. "role": "user",
  42. "content": 'evaluate the math responses ["1", "5/2", "5/2"] against the true answer \\frac{5}{2}',
  43. },
  44. ],
  45. functions=functions,
  46. )
  47. print(response)
  48. responses = client.extract_text_or_function_call(response)
  49. print(responses[0])
  50. function_call = responses[0].function_call
  51. name, arguments = function_call.name, json.loads(function_call.arguments)
  52. assert name == "eval_math_responses"
  53. print(arguments["responses"])
  54. # if isinstance(arguments["responses"], str):
  55. # arguments["responses"] = json.loads(arguments["responses"])
  56. arguments["responses"] = [f"\\boxed{{{x}}}" for x in arguments["responses"]]
  57. print(arguments["responses"])
  58. arguments["solution"] = f"\\boxed{{{arguments['solution']}}}"
  59. print(eval_math_responses(**arguments))
  60. def test_json_extraction():
  61. from autogen.agentchat import UserProxyAgent
  62. user = UserProxyAgent(name="test", code_execution_config={"use_docker": False})
  63. jstr = '{\n"location": "Boston, MA"\n}'
  64. assert user._format_json_str(jstr) == '{"location": "Boston, MA"}'
  65. jstr = '{\n"code": "python",\n"query": "x=3\nprint(x)"}'
  66. assert user._format_json_str(jstr) == '{"code": "python","query": "x=3\\nprint(x)"}'
  67. jstr = '{"code": "a=\\"hello\\""}'
  68. assert user._format_json_str(jstr) == '{"code": "a=\\"hello\\""}'
  69. def test_execute_function():
  70. from autogen.agentchat import UserProxyAgent
  71. # 1. test calling a simple function
  72. def add_num(num_to_be_added):
  73. given_num = 10
  74. return num_to_be_added + given_num
  75. user = UserProxyAgent(name="test", function_map={"add_num": add_num})
  76. # correct execution
  77. correct_args = {"name": "add_num", "arguments": '{ "num_to_be_added": 5 }'}
  78. assert user.execute_function(func_call=correct_args)[1]["content"] == "15"
  79. # function name called is wrong or doesn't exist
  80. wrong_func_name = {"name": "subtract_num", "arguments": '{ "num_to_be_added": 5 }'}
  81. assert "Error: Function" in user.execute_function(func_call=wrong_func_name)[1]["content"]
  82. # arguments passed is not in correct json format
  83. wrong_json_format = {
  84. "name": "add_num",
  85. "arguments": '{ "num_to_be_added": 5, given_num: 10 }',
  86. } # should be "given_num" with quotes
  87. assert "You argument should follow json format." in user.execute_function(func_call=wrong_json_format)[1]["content"]
  88. # function execution error with wrong arguments passed
  89. wrong_args = {"name": "add_num", "arguments": '{ "num_to_be_added": 5, "given_num": 10 }'}
  90. assert "Error: " in user.execute_function(func_call=wrong_args)[1]["content"]
  91. # 2. test calling a class method
  92. class AddNum:
  93. def __init__(self, given_num):
  94. self.given_num = given_num
  95. def add(self, num_to_be_added):
  96. self.given_num = num_to_be_added + self.given_num
  97. return self.given_num
  98. user = UserProxyAgent(name="test", function_map={"add_num": AddNum(given_num=10).add})
  99. func_call = {"name": "add_num", "arguments": '{ "num_to_be_added": 5 }'}
  100. assert user.execute_function(func_call=func_call)[1]["content"] == "15"
  101. assert user.execute_function(func_call=func_call)[1]["content"] == "20"
  102. # 3. test calling a function with no arguments
  103. def get_number():
  104. return 42
  105. user = UserProxyAgent("user", function_map={"get_number": get_number})
  106. func_call = {"name": "get_number", "arguments": "{}"}
  107. assert user.execute_function(func_call)[1]["content"] == "42"
  108. @pytest.mark.asyncio
  109. async def test_a_execute_function():
  110. from autogen.agentchat import UserProxyAgent
  111. import time
  112. # Create an async function
  113. async def add_num(num_to_be_added):
  114. given_num = 10
  115. time.sleep(1)
  116. return num_to_be_added + given_num
  117. user = UserProxyAgent(name="test", function_map={"add_num": add_num})
  118. correct_args = {"name": "add_num", "arguments": '{ "num_to_be_added": 5 }'}
  119. # Asset coroutine doesn't match.
  120. assert user.execute_function(func_call=correct_args)[1]["content"] != "15"
  121. # Asset awaited coroutine does match.
  122. assert (await user.a_execute_function(func_call=correct_args))[1]["content"] == "15"
  123. # function name called is wrong or doesn't exist
  124. wrong_func_name = {"name": "subtract_num", "arguments": '{ "num_to_be_added": 5 }'}
  125. assert "Error: Function" in (await user.a_execute_function(func_call=wrong_func_name))[1]["content"]
  126. # arguments passed is not in correct json format
  127. wrong_json_format = {
  128. "name": "add_num",
  129. "arguments": '{ "num_to_be_added": 5, given_num: 10 }',
  130. } # should be "given_num" with quotes
  131. assert (
  132. "You argument should follow json format."
  133. in (await user.a_execute_function(func_call=wrong_json_format))[1]["content"]
  134. )
  135. # function execution error with wrong arguments passed
  136. wrong_args = {"name": "add_num", "arguments": '{ "num_to_be_added": 5, "given_num": 10 }'}
  137. assert "Error: " in (await user.a_execute_function(func_call=wrong_args))[1]["content"]
  138. # 2. test calling a class method
  139. class AddNum:
  140. def __init__(self, given_num):
  141. self.given_num = given_num
  142. def add(self, num_to_be_added):
  143. self.given_num = num_to_be_added + self.given_num
  144. return self.given_num
  145. user = UserProxyAgent(name="test", function_map={"add_num": AddNum(given_num=10).add})
  146. func_call = {"name": "add_num", "arguments": '{ "num_to_be_added": 5 }'}
  147. assert (await user.a_execute_function(func_call=func_call))[1]["content"] == "15"
  148. assert (await user.a_execute_function(func_call=func_call))[1]["content"] == "20"
  149. # 3. test calling a function with no arguments
  150. def get_number():
  151. return 42
  152. user = UserProxyAgent("user", function_map={"get_number": get_number})
  153. func_call = {"name": "get_number", "arguments": "{}"}
  154. assert (await user.a_execute_function(func_call))[1]["content"] == "42"
  155. if __name__ == "__main__":
  156. # test_json_extraction()
  157. # test_execute_function()
  158. asyncio.run(test_a_execute_function())
  159. test_eval_math_responses()