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.py 17 kB

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