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_code_utils.py 19 kB

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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. #!/usr/bin/env python3 -m pytest
  2. import os
  3. import sys
  4. import tempfile
  5. import unittest
  6. from io import StringIO
  7. from types import SimpleNamespace
  8. from unittest.mock import patch
  9. import pytest
  10. from conftest import skip_docker
  11. import autogen
  12. from autogen.code_utils import (
  13. UNKNOWN,
  14. check_can_use_docker_or_throw,
  15. content_str,
  16. create_virtual_env,
  17. decide_use_docker,
  18. execute_code,
  19. extract_code,
  20. get_powershell_command,
  21. improve_code,
  22. improve_function,
  23. in_docker_container,
  24. infer_lang,
  25. is_docker_running,
  26. )
  27. KEY_LOC = "notebook"
  28. OAI_CONFIG_LIST = "OAI_CONFIG_LIST"
  29. here = os.path.abspath(os.path.dirname(__file__))
  30. if skip_docker or not is_docker_running() or not decide_use_docker(use_docker=None):
  31. skip_docker_test = True
  32. else:
  33. skip_docker_test = False
  34. # def test_find_code():
  35. # try:
  36. # import openai
  37. # except ImportError:
  38. # return
  39. # # need gpt-4 for this task
  40. # config_list = autogen.config_list_from_json(
  41. # OAI_CONFIG_LIST,
  42. # file_location=KEY_LOC,
  43. # filter_dict={
  44. # "model": ["gpt-4", "gpt4", "gpt-4-32k", "gpt-4-32k-0314"],
  45. # },
  46. # )
  47. # # config_list = autogen.config_list_from_json(
  48. # # OAI_CONFIG_LIST,
  49. # # file_location=KEY_LOC,
  50. # # filter_dict={
  51. # # "model": {
  52. # # "gpt-3.5-turbo",
  53. # # "gpt-3.5-turbo-16k",
  54. # # "gpt-3.5-turbo-16k-0613",
  55. # # "gpt-3.5-turbo-0301",
  56. # # "chatgpt-35-turbo-0301",
  57. # # "gpt-35-turbo-v0301",
  58. # # },
  59. # # },
  60. # # )
  61. # seed = 42
  62. # messages = [
  63. # {
  64. # "role": "user",
  65. # "content": "Print hello world to a file called hello.txt",
  66. # },
  67. # {
  68. # "role": "user",
  69. # "content": """
  70. # # filename: write_hello.py
  71. # ```
  72. # with open('hello.txt', 'w') as f:
  73. # f.write('Hello, World!')
  74. # print('Hello, World! printed to hello.txt')
  75. # ```
  76. # Please execute the above Python code to print "Hello, World!" to a file called hello.txt and print the success message.
  77. # """,
  78. # },
  79. # ]
  80. # codeblocks, _ = find_code(messages, seed=seed, config_list=config_list)
  81. # assert codeblocks[0][0] == "python", codeblocks
  82. # messages += [
  83. # {
  84. # "role": "user",
  85. # "content": """
  86. # exitcode: 0 (execution succeeded)
  87. # Code output:
  88. # Hello, World! printed to hello.txt
  89. # """,
  90. # },
  91. # {
  92. # "role": "assistant",
  93. # "content": "Great! Can I help you with anything else?",
  94. # },
  95. # ]
  96. # codeblocks, content = find_code(messages, seed=seed, config_list=config_list)
  97. # assert codeblocks[0][0] == "unknown", content
  98. # messages += [
  99. # {
  100. # "role": "user",
  101. # "content": "Save a pandas df with 3 rows and 3 columns to disk.",
  102. # },
  103. # {
  104. # "role": "assistant",
  105. # "content": """
  106. # ```
  107. # # filename: save_df.py
  108. # import pandas as pd
  109. # df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]})
  110. # df.to_csv('df.csv')
  111. # print('df saved to df.csv')
  112. # ```
  113. # Please execute the above Python code to save a pandas df with 3 rows and 3 columns to disk.
  114. # Before you run the code above, run
  115. # ```
  116. # pip install pandas
  117. # ```
  118. # first to install pandas.
  119. # """,
  120. # },
  121. # ]
  122. # codeblocks, content = find_code(messages, seed=seed, config_list=config_list)
  123. # assert (
  124. # len(codeblocks) == 2
  125. # and (codeblocks[0][0] == "sh"
  126. # and codeblocks[1][0] == "python"
  127. # or codeblocks[0][0] == "python"
  128. # and codeblocks[1][0] == "sh")
  129. # ), content
  130. # messages += [
  131. # {
  132. # "role": "user",
  133. # "content": "The code is unsafe to execute in my environment.",
  134. # },
  135. # {
  136. # "role": "assistant",
  137. # "content": "please run python write_hello.py",
  138. # },
  139. # ]
  140. # # codeblocks, content = find_code(messages, config_list=config_list)
  141. # # assert codeblocks[0][0] != "unknown", content
  142. # # I'm sorry, but I cannot execute code from earlier messages. Please provide the code again if you would like me to execute it.
  143. # messages[-1]["content"] = "please skip pip install pandas if you already have pandas installed"
  144. # codeblocks, content = find_code(messages, seed=seed, config_list=config_list)
  145. # assert codeblocks[0][0] != "sh", content
  146. # messages += [
  147. # {
  148. # "role": "user",
  149. # "content": "The code is still unsafe to execute in my environment.",
  150. # },
  151. # {
  152. # "role": "assistant",
  153. # "content": "Let me try something else. Do you have docker installed?",
  154. # },
  155. # ]
  156. # codeblocks, content = find_code(messages, seed=seed, config_list=config_list)
  157. # assert codeblocks[0][0] == "unknown", content
  158. # print(content)
  159. def test_infer_lang():
  160. assert infer_lang("print('hello world')") == "python"
  161. assert infer_lang("pip install autogen") == "sh"
  162. # test infer lang for unknown code/invalid code
  163. assert infer_lang("dummy text") == UNKNOWN
  164. assert infer_lang("print('hello world'))") == UNKNOWN
  165. def test_extract_code():
  166. print(extract_code("```bash\npython temp.py\n```"))
  167. # test extract_code from markdown
  168. codeblocks = extract_code(
  169. """
  170. Example:
  171. ```
  172. print("hello extract code")
  173. ```
  174. """,
  175. detect_single_line_code=False,
  176. )
  177. print(codeblocks)
  178. codeblocks2 = extract_code(
  179. """
  180. Example:
  181. ```
  182. print("hello extract code")
  183. ```
  184. """,
  185. detect_single_line_code=True,
  186. )
  187. print(codeblocks2)
  188. assert codeblocks2 == codeblocks
  189. # import pdb; pdb.set_trace()
  190. codeblocks = extract_code(
  191. """
  192. Example:
  193. ```python
  194. def scrape(url):
  195. import requests
  196. from bs4 import BeautifulSoup
  197. response = requests.get(url)
  198. soup = BeautifulSoup(response.text, "html.parser")
  199. title = soup.find("title").text
  200. text = soup.find("div", {"id": "bodyContent"}).text
  201. return title, text
  202. ```
  203. Test:
  204. ```python
  205. url = "https://en.wikipedia.org/wiki/Web_scraping"
  206. title, text = scrape(url)
  207. print(f"Title: {title}")
  208. print(f"Text: {text}")
  209. ```
  210. """
  211. )
  212. print(codeblocks)
  213. assert len(codeblocks) == 2 and codeblocks[0][0] == "python" and codeblocks[1][0] == "python"
  214. codeblocks = extract_code(
  215. """
  216. Example:
  217. ``` python
  218. def scrape(url):
  219. import requests
  220. from bs4 import BeautifulSoup
  221. response = requests.get(url)
  222. soup = BeautifulSoup(response.text, "html.parser")
  223. title = soup.find("title").text
  224. text = soup.find("div", {"id": "bodyContent"}).text
  225. return title, text
  226. ```
  227. Test:
  228. ``` python
  229. url = "https://en.wikipedia.org/wiki/Web_scraping"
  230. title, text = scrape(url)
  231. print(f"Title: {title}")
  232. print(f"Text: {text}")
  233. ```
  234. """
  235. )
  236. print(codeblocks)
  237. assert len(codeblocks) == 2 and codeblocks[0][0] == "python" and codeblocks[1][0] == "python"
  238. # Check for indented code blocks
  239. codeblocks = extract_code(
  240. """
  241. Example:
  242. ```python
  243. def scrape(url):
  244. import requests
  245. from bs4 import BeautifulSoup
  246. response = requests.get(url)
  247. soup = BeautifulSoup(response.text, "html.parser")
  248. title = soup.find("title").text
  249. text = soup.find("div", {"id": "bodyContent"}).text
  250. return title, text
  251. ```
  252. """
  253. )
  254. print(codeblocks)
  255. assert len(codeblocks) == 1 and codeblocks[0][0] == "python"
  256. # Check for codeblocks with \r\n
  257. codeblocks = extract_code(
  258. """
  259. Example:
  260. ``` python
  261. def scrape(url):
  262. import requests
  263. from bs4 import BeautifulSoup
  264. response = requests.get(url)
  265. soup = BeautifulSoup(response.text, "html.parser")
  266. title = soup.find("title").text
  267. text = soup.find("div", {"id": "bodyContent"}).text
  268. return title, text
  269. ```
  270. """.replace(
  271. "\n", "\r\n"
  272. )
  273. )
  274. print(codeblocks)
  275. assert len(codeblocks) == 1 and codeblocks[0][0] == "python"
  276. codeblocks = extract_code("no code block")
  277. assert len(codeblocks) == 1 and codeblocks[0] == (UNKNOWN, "no code block")
  278. # Disable single line code detection
  279. line = "Run `source setup.sh` from terminal"
  280. codeblocks = extract_code(line, detect_single_line_code=False)
  281. assert len(codeblocks) == 1 and codeblocks[0] == (UNKNOWN, line)
  282. # Enable single line code detection
  283. codeblocks = extract_code("Run `source setup.sh` from terminal", detect_single_line_code=True)
  284. assert len(codeblocks) == 1 and codeblocks[0] == ("", "source setup.sh")
  285. @pytest.mark.skipif(skip_docker_test, reason="docker is not running or requested to skip docker tests")
  286. def test_execute_code(use_docker=True):
  287. # Test execute code and save the code to a file.
  288. with tempfile.TemporaryDirectory() as tempdir:
  289. filename = "temp_file_with_code.py"
  290. # execute code and save the code to a file.
  291. exit_code, msg, image = execute_code(
  292. "print('hello world')",
  293. filename=filename,
  294. work_dir=tempdir,
  295. use_docker=use_docker,
  296. )
  297. assert exit_code == 0 and msg == "hello world\n", msg
  298. # read the file just saved
  299. exit_code, msg, image = execute_code(
  300. f"with open('{filename}', 'rt') as f: print(f.read())",
  301. use_docker=use_docker,
  302. work_dir=tempdir,
  303. )
  304. assert exit_code == 0 and "print('hello world')" in msg, msg
  305. # execute code in a file
  306. exit_code, msg, image = execute_code(
  307. filename=filename,
  308. use_docker=use_docker,
  309. work_dir=tempdir,
  310. )
  311. assert exit_code == 0 and msg == "hello world\n", msg
  312. # execute code in a file using shell command directly
  313. exit_code, msg, image = execute_code(
  314. f"python {filename}",
  315. lang="sh",
  316. use_docker=use_docker,
  317. work_dir=tempdir,
  318. )
  319. assert exit_code == 0 and msg == "hello world\n", msg
  320. with tempfile.TemporaryDirectory() as tempdir:
  321. # execute code for assertion error
  322. exit_code, msg, image = execute_code(
  323. "assert 1==2",
  324. use_docker=use_docker,
  325. work_dir=tempdir,
  326. )
  327. assert exit_code, msg
  328. assert "AssertionError" in msg
  329. assert 'File "' in msg or 'File ".\\"' in msg # py3.8 + win32
  330. with tempfile.TemporaryDirectory() as tempdir:
  331. # execute code which takes a long time
  332. exit_code, error, image = execute_code(
  333. "import time; time.sleep(2)",
  334. timeout=1,
  335. use_docker=use_docker,
  336. work_dir=tempdir,
  337. )
  338. assert exit_code and error == "Timeout"
  339. if use_docker is True:
  340. assert isinstance(image, str)
  341. @pytest.mark.skipif(skip_docker_test, reason="docker is not running or requested to skip docker tests")
  342. def test_execute_code_with_custom_filename_on_docker():
  343. with tempfile.TemporaryDirectory() as tempdir:
  344. filename = "codetest.py"
  345. exit_code, msg, image = execute_code(
  346. "print('hello world')",
  347. filename=filename,
  348. use_docker=True,
  349. work_dir=tempdir,
  350. )
  351. assert exit_code == 0 and msg == "hello world\n", msg
  352. assert image == "python:codetest.py"
  353. @pytest.mark.skipif(
  354. skip_docker_test,
  355. reason="docker is not running or requested to skip docker tests",
  356. )
  357. def test_execute_code_with_misformed_filename_on_docker():
  358. with tempfile.TemporaryDirectory() as tempdir:
  359. filename = "codetest.py (some extra information)"
  360. exit_code, msg, image = execute_code(
  361. "print('hello world')",
  362. filename=filename,
  363. use_docker=True,
  364. work_dir=tempdir,
  365. )
  366. assert exit_code == 0 and msg == "hello world\n", msg
  367. assert image == "python:codetest.py__some_extra_information_"
  368. def test_execute_code_raises_when_code_and_filename_are_both_none():
  369. with pytest.raises(AssertionError):
  370. execute_code(code=None, filename=None)
  371. def test_execute_code_no_docker():
  372. test_execute_code(use_docker=False)
  373. def test_execute_code_timeout_no_docker():
  374. exit_code, error, image = execute_code("import time; time.sleep(2)", timeout=1, use_docker=False)
  375. assert exit_code and error == "Timeout"
  376. assert image is None
  377. def get_current_autogen_env_var():
  378. return os.environ.get("AUTOGEN_USE_DOCKER", None)
  379. def restore_autogen_env_var(current_env_value):
  380. if current_env_value is None:
  381. del os.environ["AUTOGEN_USE_DOCKER"]
  382. else:
  383. os.environ["AUTOGEN_USE_DOCKER"] = current_env_value
  384. def test_decide_use_docker_truthy_values():
  385. current_env_value = get_current_autogen_env_var()
  386. for truthy_value in ["1", "true", "yes", "t"]:
  387. os.environ["AUTOGEN_USE_DOCKER"] = truthy_value
  388. assert decide_use_docker(None) is True
  389. restore_autogen_env_var(current_env_value)
  390. def test_decide_use_docker_falsy_values():
  391. current_env_value = get_current_autogen_env_var()
  392. for falsy_value in ["0", "false", "no", "f"]:
  393. os.environ["AUTOGEN_USE_DOCKER"] = falsy_value
  394. assert decide_use_docker(None) is False
  395. restore_autogen_env_var(current_env_value)
  396. def test_decide_use_docker():
  397. current_env_value = get_current_autogen_env_var()
  398. os.environ["AUTOGEN_USE_DOCKER"] = "none"
  399. assert decide_use_docker(None) is None
  400. os.environ["AUTOGEN_USE_DOCKER"] = "invalid"
  401. with pytest.raises(ValueError):
  402. decide_use_docker(None)
  403. restore_autogen_env_var(current_env_value)
  404. def test_decide_use_docker_with_env_var():
  405. current_env_value = get_current_autogen_env_var()
  406. os.environ["AUTOGEN_USE_DOCKER"] = "false"
  407. assert decide_use_docker(None) is False
  408. os.environ["AUTOGEN_USE_DOCKER"] = "true"
  409. assert decide_use_docker(None) is True
  410. os.environ["AUTOGEN_USE_DOCKER"] = "none"
  411. assert decide_use_docker(None) is None
  412. os.environ["AUTOGEN_USE_DOCKER"] = "invalid"
  413. with pytest.raises(ValueError):
  414. decide_use_docker(None)
  415. restore_autogen_env_var(current_env_value)
  416. def test_decide_use_docker_with_env_var_and_argument():
  417. current_env_value = get_current_autogen_env_var()
  418. os.environ["AUTOGEN_USE_DOCKER"] = "false"
  419. assert decide_use_docker(True) is True
  420. os.environ["AUTOGEN_USE_DOCKER"] = "true"
  421. assert decide_use_docker(False) is False
  422. os.environ["AUTOGEN_USE_DOCKER"] = "none"
  423. assert decide_use_docker(True) is True
  424. os.environ["AUTOGEN_USE_DOCKER"] = "invalid"
  425. assert decide_use_docker(True) is True
  426. restore_autogen_env_var(current_env_value)
  427. def test_can_use_docker_or_throw():
  428. check_can_use_docker_or_throw(None)
  429. if not is_docker_running() and not in_docker_container():
  430. check_can_use_docker_or_throw(False)
  431. if not is_docker_running() and not in_docker_container():
  432. with pytest.raises(RuntimeError):
  433. check_can_use_docker_or_throw(True)
  434. def test_create_virtual_env():
  435. with tempfile.TemporaryDirectory() as temp_dir:
  436. venv_context = create_virtual_env(temp_dir)
  437. assert isinstance(venv_context, SimpleNamespace)
  438. assert venv_context.env_name == os.path.split(temp_dir)[1]
  439. def test_create_virtual_env_with_extra_args():
  440. with tempfile.TemporaryDirectory() as temp_dir:
  441. venv_context = create_virtual_env(temp_dir, with_pip=False)
  442. assert isinstance(venv_context, SimpleNamespace)
  443. assert venv_context.env_name == os.path.split(temp_dir)[1]
  444. def _test_improve():
  445. try:
  446. import openai
  447. except ImportError:
  448. return
  449. config_list = autogen.config_list_openai_aoai(KEY_LOC)
  450. improved, _ = improve_function(
  451. "autogen/math_utils.py",
  452. "solve_problem",
  453. "Solve math problems accurately, by avoiding calculation errors and reduce reasoning errors.",
  454. config_list=config_list,
  455. )
  456. with open(f"{here}/math_utils.py.improved", "w") as f:
  457. f.write(improved)
  458. suggestion, _ = improve_code(
  459. ["autogen/code_utils.py", "autogen/math_utils.py"],
  460. "leverage generative AI smartly and cost-effectively",
  461. config_list=config_list,
  462. )
  463. print(suggestion)
  464. improvement, cost = improve_code(
  465. ["autogen/code_utils.py", "autogen/math_utils.py"],
  466. "leverage generative AI smartly and cost-effectively",
  467. suggest_only=False,
  468. config_list=config_list,
  469. )
  470. print(cost)
  471. with open(f"{here}/suggested_improvement.txt", "w") as f:
  472. f.write(improvement)
  473. class TestContentStr(unittest.TestCase):
  474. def test_string_content(self):
  475. self.assertEqual(content_str("simple string"), "simple string")
  476. def test_list_of_text_content(self):
  477. content = [{"type": "text", "text": "hello"}, {"type": "text", "text": " world"}]
  478. self.assertEqual(content_str(content), "hello world")
  479. def test_mixed_content(self):
  480. content = [{"type": "text", "text": "hello"}, {"type": "image_url", "url": "http://example.com/image.png"}]
  481. self.assertEqual(content_str(content), "hello<image>")
  482. def test_invalid_content(self):
  483. content = [{"type": "text", "text": "hello"}, {"type": "wrong_type", "url": "http://example.com/image.png"}]
  484. with self.assertRaises(ValueError) as context:
  485. content_str(content)
  486. self.assertIn("Wrong content format", str(context.exception))
  487. def test_empty_list(self):
  488. self.assertEqual(content_str([]), "")
  489. def test_non_dict_in_list(self):
  490. content = ["string", {"type": "text", "text": "text"}]
  491. with self.assertRaises(TypeError):
  492. content_str(content)
  493. class TestGetPowerShellCommand(unittest.TestCase):
  494. @patch("subprocess.run")
  495. def test_get_powershell_command_powershell(self, mock_subprocess_run):
  496. # Set up the mock to return a successful result for 'powershell'
  497. mock_subprocess_run.return_value.returncode = 0
  498. mock_subprocess_run.return_value.stdout = StringIO("5")
  499. self.assertEqual(get_powershell_command(), "powershell")
  500. @patch("subprocess.run")
  501. def test_get_powershell_command_pwsh(self, mock_subprocess_run):
  502. # Set up the mock to return a successful result for 'pwsh'
  503. mock_subprocess_run.side_effect = [FileNotFoundError, mock_subprocess_run.return_value]
  504. mock_subprocess_run.return_value.returncode = 0
  505. mock_subprocess_run.return_value.stdout = StringIO("7")
  506. self.assertEqual(get_powershell_command(), "pwsh")
  507. @patch("subprocess.run")
  508. def test_get_powershell_command_not_found(self, mock_subprocess_run):
  509. mock_subprocess_run.side_effect = [FileNotFoundError, FileNotFoundError]
  510. with self.assertRaises(FileNotFoundError):
  511. get_powershell_command()
  512. @patch("subprocess.run")
  513. def test_get_powershell_command_no_permission(self, mock_subprocess_run):
  514. mock_subprocess_run.side_effect = [PermissionError, FileNotFoundError]
  515. with self.assertRaises(PermissionError):
  516. get_powershell_command()
  517. if __name__ == "__main__":
  518. # test_infer_lang()
  519. test_extract_code()
  520. # test_execute_code()
  521. # test_find_code()
  522. # unittest.main()