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_notebook.py 3.1 kB

2 years ago
Agent notebook example with human feedback; Support shell command and multiple code blocks; Improve the system message for assistant agent; Improve utility functions for config lists; reuse docker image (#1056) * add agent notebook and documentation * fix bug * set flush to True when printing msg in agent * add a math problem in agent notebook * remove * header * improve notebook doc * notebook update * improve notebook example * improve doc * agent notebook example with user feedback * log * log * improve notebook doc * improve print * doc * human_input_mode * human_input_mode str * indent * indent * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * shell command and multiple code blocks * Update notebook/autogen_agent.ipynb Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update notebook/autogen_agent.ipynb Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update notebook/autogen_agent.ipynb Co-authored-by: Chi Wang <wang.chi@microsoft.com> * coding agent * math notebook * renaming and doc format * typo * infer lang * sh * docker * docker * reset consecutive autoreply counter * fix explanation * paper talk * human feedback * web info * rename test * config list explanation * link to blogpost * installation * homepage features * features * features * rename agent * remove notebook * notebook test * docker command * notebook update * lang -> cmd * notebook * make it work for gpt-3.5 * return full log * quote * docker * docker * docker * docker * docker * docker image list * notebook * notebook * use_docker * use_docker * use_docker * doc * agent * doc * abs path * pandas * docker * reuse docker image * context window * news * print format * pyspark version in py3.8 * pyspark in py3.8 * pyspark and ray * quote * pyspark * pyspark * pyspark --------- Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu>
3 years ago
2 years ago
Agent notebook example with human feedback; Support shell command and multiple code blocks; Improve the system message for assistant agent; Improve utility functions for config lists; reuse docker image (#1056) * add agent notebook and documentation * fix bug * set flush to True when printing msg in agent * add a math problem in agent notebook * remove * header * improve notebook doc * notebook update * improve notebook example * improve doc * agent notebook example with user feedback * log * log * improve notebook doc * improve print * doc * human_input_mode * human_input_mode str * indent * indent * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * shell command and multiple code blocks * Update notebook/autogen_agent.ipynb Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update notebook/autogen_agent.ipynb Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update notebook/autogen_agent.ipynb Co-authored-by: Chi Wang <wang.chi@microsoft.com> * coding agent * math notebook * renaming and doc format * typo * infer lang * sh * docker * docker * reset consecutive autoreply counter * fix explanation * paper talk * human feedback * web info * rename test * config list explanation * link to blogpost * installation * homepage features * features * features * rename agent * remove notebook * notebook test * docker command * notebook update * lang -> cmd * notebook * make it work for gpt-3.5 * return full log * quote * docker * docker * docker * docker * docker * docker image list * notebook * notebook * use_docker * use_docker * use_docker * doc * agent * doc * abs path * pandas * docker * reuse docker image * context window * news * print format * pyspark version in py3.8 * pyspark in py3.8 * pyspark and ray * quote * pyspark * pyspark * pyspark --------- Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu>
3 years ago
2 years ago
2 years ago
2 years ago
Agent notebook example with human feedback; Support shell command and multiple code blocks; Improve the system message for assistant agent; Improve utility functions for config lists; reuse docker image (#1056) * add agent notebook and documentation * fix bug * set flush to True when printing msg in agent * add a math problem in agent notebook * remove * header * improve notebook doc * notebook update * improve notebook example * improve doc * agent notebook example with user feedback * log * log * improve notebook doc * improve print * doc * human_input_mode * human_input_mode str * indent * indent * Update flaml/autogen/agent/user_proxy_agent.py Co-authored-by: Chi Wang <wang.chi@microsoft.com> * shell command and multiple code blocks * Update notebook/autogen_agent.ipynb Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update notebook/autogen_agent.ipynb Co-authored-by: Chi Wang <wang.chi@microsoft.com> * Update notebook/autogen_agent.ipynb Co-authored-by: Chi Wang <wang.chi@microsoft.com> * coding agent * math notebook * renaming and doc format * typo * infer lang * sh * docker * docker * reset consecutive autoreply counter * fix explanation * paper talk * human feedback * web info * rename test * config list explanation * link to blogpost * installation * homepage features * features * features * rename agent * remove notebook * notebook test * docker command * notebook update * lang -> cmd * notebook * make it work for gpt-3.5 * return full log * quote * docker * docker * docker * docker * docker * docker image list * notebook * notebook * use_docker * use_docker * use_docker * doc * agent * doc * abs path * pandas * docker * reuse docker image * context window * news * print format * pyspark version in py3.8 * pyspark in py3.8 * pyspark and ray * quote * pyspark * pyspark * pyspark --------- Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu>
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import sys
  2. import os
  3. import pytest
  4. try:
  5. import openai
  6. skip = False
  7. except ImportError:
  8. skip = True
  9. here = os.path.abspath(os.path.dirname(__file__))
  10. def run_notebook(input_nb, output_nb="executed_openai_notebook.ipynb", save=False):
  11. import nbformat
  12. from nbconvert.preprocessors import ExecutePreprocessor
  13. from nbconvert.preprocessors import CellExecutionError
  14. try:
  15. nb_loc = os.path.join(here, os.pardir, "notebook")
  16. file_path = os.path.join(nb_loc, input_nb)
  17. with open(file_path) as nb_file:
  18. nb = nbformat.read(nb_file, as_version=4)
  19. preprocessor = ExecutePreprocessor(timeout=4800, kernel_name="python3")
  20. preprocessor.preprocess(nb, {"metadata": {"path": nb_loc}})
  21. output_file_name = "executed_openai_notebook_output.txt"
  22. output_file = os.path.join(here, output_file_name)
  23. with open(output_file, "a") as nb_output_file:
  24. for cell in nb.cells:
  25. if cell.cell_type == "code" and "outputs" in cell:
  26. for output in cell.outputs:
  27. if "text" in output:
  28. nb_output_file.write(output["text"].strip() + "\n")
  29. elif "data" in output and "text/plain" in output["data"]:
  30. nb_output_file.write(output["data"]["text/plain"].strip() + "\n")
  31. except CellExecutionError:
  32. raise
  33. finally:
  34. if save:
  35. with open(os.path.join(here, output_nb), "w", encoding="utf-8") as nb_executed_file:
  36. nbformat.write(nb, nb_executed_file)
  37. @pytest.mark.skipif(
  38. skip or not sys.version.startswith("3.11"),
  39. reason="do not run if openai is not installed or py!=3.11",
  40. )
  41. def test_agentchat_auto_feedback_from_code(save=False):
  42. run_notebook("agentchat_auto_feedback_from_code_execution.ipynb", save=save)
  43. @pytest.mark.skipif(
  44. skip or not sys.version.startswith("3.10"),
  45. reason="do not run if openai is not installed or py!=3.10",
  46. )
  47. def _test_oai_completion(save=False):
  48. run_notebook("oai_completion.ipynb", save=save)
  49. @pytest.mark.skipif(
  50. skip or not sys.version.startswith("3.10"),
  51. reason="do not run if openai is not installed or py!=3.10",
  52. )
  53. def test_agentchat_function_call(save=False):
  54. run_notebook("agentchat_function_call.ipynb", save=save)
  55. @pytest.mark.skipif(
  56. skip or not sys.version.startswith("3.10"),
  57. reason="do not run if openai is not installed or py!=3.10",
  58. )
  59. def _test_agentchat_MathChat(save=False):
  60. run_notebook("agentchat_MathChat.ipynb", save=save)
  61. @pytest.mark.skipif(
  62. skip or not sys.version.startswith("3.11"),
  63. reason="do not run if openai is not installed or py!=3.11",
  64. )
  65. def _test_oai_chatgpt_gpt4(save=False):
  66. run_notebook("oai_chatgpt_gpt4.ipynb", save=save)
  67. if __name__ == "__main__":
  68. test_agentchat_auto_feedback_from_code(save=True)
  69. # test_oai_chatgpt_gpt4(save=True)
  70. # test_oai_completion(save=True)
  71. # test_agentchat_MathChat(save=True)
  72. # test_agentchat_function_call(save=True)