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