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