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_commandline_code_executor.py 18 kB

Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
Code executors (#1405) * code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <davor@airt.ai> Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com> Co-authored-by: Aaron <aaronlaptop12@hotmail.com> Co-authored-by: Chi Wang <wang.chi@microsoft.com>
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. import os
  2. import shutil
  3. import sys
  4. import tempfile
  5. import uuid
  6. import venv
  7. from pathlib import Path
  8. import pytest
  9. from autogen.agentchat.conversable_agent import ConversableAgent
  10. from autogen.code_utils import WIN32, decide_use_docker, is_docker_running
  11. from autogen.coding.base import CodeBlock, CodeExecutor
  12. from autogen.coding.docker_commandline_code_executor import DockerCommandLineCodeExecutor
  13. from autogen.coding.factory import CodeExecutorFactory
  14. from autogen.coding.local_commandline_code_executor import LocalCommandLineCodeExecutor
  15. sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
  16. from conftest import MOCK_OPEN_AI_API_KEY, skip_docker # noqa: E402
  17. if skip_docker or not is_docker_running() or not decide_use_docker(use_docker=None):
  18. skip_docker_test = True
  19. classes_to_test = [LocalCommandLineCodeExecutor]
  20. else:
  21. skip_docker_test = False
  22. classes_to_test = [LocalCommandLineCodeExecutor, DockerCommandLineCodeExecutor]
  23. UNIX_SHELLS = ["bash", "sh", "shell"]
  24. WINDOWS_SHELLS = ["ps1", "pwsh", "powershell"]
  25. PYTHON_VARIANTS = ["python", "Python", "py"]
  26. @pytest.mark.parametrize(
  27. "lang, should_execute",
  28. [
  29. ("python", False), # Python should not execute
  30. ("bash", False), # Bash should execute
  31. ("html", False), # HTML should not execute
  32. ("javascript", False), # JavaScript should not execute
  33. ],
  34. )
  35. def test_execution_policy_enforcement(lang, should_execute):
  36. with tempfile.TemporaryDirectory() as temp_dir:
  37. executor = LocalCommandLineCodeExecutor(
  38. work_dir=temp_dir,
  39. execution_policies={"python": False, "bash": False, "html": False, "javascript": False, "css": False},
  40. )
  41. code = "print('Hello, world!')" if lang == "python" else "echo 'Hello, world!'"
  42. code_block = CodeBlock(code=code, language=lang)
  43. result = executor.execute_code_blocks([code_block])
  44. if should_execute:
  45. assert "Hello, world!" in result.output, f"Expected execution for {lang}, but it didn't execute."
  46. else:
  47. assert "Hello, world!" not in result.output, f"Expected no execution for {lang}, but it executed."
  48. # Ensure files are saved regardless of execution
  49. assert result.code_file is not None, f"Expected code file to be saved for {lang}, but it wasn't."
  50. @pytest.mark.parametrize("cls", classes_to_test)
  51. def test_is_code_executor(cls) -> None:
  52. assert isinstance(cls, CodeExecutor)
  53. def test_create_local() -> None:
  54. config = {"executor": "commandline-local"}
  55. executor = CodeExecutorFactory.create(config)
  56. assert isinstance(executor, LocalCommandLineCodeExecutor)
  57. config = {"executor": LocalCommandLineCodeExecutor()}
  58. executor = CodeExecutorFactory.create(config)
  59. assert executor is config["executor"]
  60. @pytest.mark.skipif(
  61. skip_docker_test,
  62. reason="docker is not running or requested to skip docker tests",
  63. )
  64. def test_create_docker() -> None:
  65. config = {"executor": DockerCommandLineCodeExecutor()}
  66. executor = CodeExecutorFactory.create(config)
  67. assert executor is config["executor"]
  68. @pytest.mark.parametrize("cls", classes_to_test)
  69. def test_commandline_executor_init(cls) -> None:
  70. executor = cls(timeout=10, work_dir=".")
  71. assert executor.timeout == 10 and str(executor.work_dir) == "."
  72. # Try invalid working directory.
  73. with pytest.raises(FileNotFoundError):
  74. executor = cls(timeout=111, work_dir="/invalid/directory")
  75. @pytest.mark.parametrize("py_variant", PYTHON_VARIANTS)
  76. @pytest.mark.parametrize("cls", classes_to_test)
  77. def test_commandline_executor_execute_code(cls, py_variant) -> None:
  78. with tempfile.TemporaryDirectory() as temp_dir:
  79. executor = cls(work_dir=temp_dir)
  80. _test_execute_code(py_variant, executor=executor)
  81. @pytest.mark.parametrize("py_variant", PYTHON_VARIANTS)
  82. def _test_execute_code(py_variant, executor: CodeExecutor) -> None:
  83. # Test single code block.
  84. code_blocks = [CodeBlock(code="import sys; print('hello world!')", language=py_variant)]
  85. code_result = executor.execute_code_blocks(code_blocks)
  86. assert code_result.exit_code == 0 and "hello world!" in code_result.output and code_result.code_file is not None
  87. # Test multiple code blocks.
  88. code_blocks = [
  89. CodeBlock(code="import sys; print('hello world!')", language=py_variant),
  90. CodeBlock(code="a = 100 + 100; print(a)", language=py_variant),
  91. ]
  92. code_result = executor.execute_code_blocks(code_blocks)
  93. assert (
  94. code_result.exit_code == 0
  95. and "hello world!" in code_result.output
  96. and "200" in code_result.output
  97. and code_result.code_file is not None
  98. )
  99. # Test bash script.
  100. if sys.platform not in ["win32"]:
  101. code_blocks = [CodeBlock(code="echo 'hello world!'", language="bash")]
  102. code_result = executor.execute_code_blocks(code_blocks)
  103. assert code_result.exit_code == 0 and "hello world!" in code_result.output and code_result.code_file is not None
  104. # Test running code.
  105. file_lines = ["import sys", "print('hello world!')", "a = 100 + 100", "print(a)"]
  106. code_blocks = [CodeBlock(code="\n".join(file_lines), language=py_variant)]
  107. code_result = executor.execute_code_blocks(code_blocks)
  108. assert (
  109. code_result.exit_code == 0
  110. and "hello world!" in code_result.output
  111. and "200" in code_result.output
  112. and code_result.code_file is not None
  113. )
  114. # Check saved code file.
  115. with open(code_result.code_file) as f:
  116. code_lines = f.readlines()
  117. for file_line, code_line in zip(file_lines, code_lines):
  118. assert file_line.strip() == code_line.strip()
  119. @pytest.mark.parametrize("cls", classes_to_test)
  120. def test_local_commandline_code_executor_save_files(cls) -> None:
  121. with tempfile.TemporaryDirectory() as temp_dir:
  122. executor = cls(work_dir=temp_dir)
  123. _test_save_files(executor, save_file_only=False)
  124. @pytest.mark.parametrize("cls", classes_to_test)
  125. def test_local_commandline_code_executor_save_files_only(cls) -> None:
  126. with tempfile.TemporaryDirectory() as temp_dir:
  127. # Using execution_policies to specify that no languages should execute
  128. executor = cls(
  129. work_dir=temp_dir,
  130. execution_policies={"python": False, "bash": False, "javascript": False, "html": False, "css": False},
  131. )
  132. _test_save_files(executor, save_file_only=True)
  133. def _test_save_files(executor: CodeExecutor, save_file_only: bool) -> None:
  134. def _check_output(code_result: CodeBlock, expected_output: str) -> None:
  135. if save_file_only:
  136. return expected_output not in code_result.output
  137. else:
  138. return expected_output in code_result.output
  139. # Test executable code block.
  140. # Test saving to a given filename, Python.
  141. code_blocks = [CodeBlock(code="# filename: test.py\nimport sys; print('hello world!')", language="python")]
  142. code_result = executor.execute_code_blocks(code_blocks)
  143. assert (
  144. code_result.exit_code == 0 and _check_output(code_result, "hello world!") and code_result.code_file is not None
  145. )
  146. assert os.path.basename(code_result.code_file) == "test.py"
  147. # Test saving to a given filename without "filename" prefix, Python.
  148. code_blocks = [CodeBlock(code="# test.py\nimport sys; print('hello world!')", language="python")]
  149. code_result = executor.execute_code_blocks(code_blocks)
  150. assert (
  151. code_result.exit_code == 0 and _check_output(code_result, "hello world!") and code_result.code_file is not None
  152. )
  153. assert os.path.basename(code_result.code_file) == "test.py"
  154. # Test non-executable code block.
  155. # Test saving to a given filename, Javascript.
  156. code_blocks = [CodeBlock(code="// filename: test.js\nconsole.log('hello world!')", language="javascript")]
  157. code_result = executor.execute_code_blocks(code_blocks)
  158. assert code_result.exit_code == 0 and "hello world!" not in code_result.output and code_result.code_file is not None
  159. assert os.path.basename(code_result.code_file) == "test.js"
  160. # Test saving to a given filename without "filename" prefix, Javascript.
  161. code_blocks = [CodeBlock(code="// test.js\nconsole.log('hello world!')", language="javascript")]
  162. code_result = executor.execute_code_blocks(code_blocks)
  163. assert code_result.exit_code == 0 and "hello world!" not in code_result.output and code_result.code_file is not None
  164. assert os.path.basename(code_result.code_file) == "test.js"
  165. # Test saving to a given filename, CSS.
  166. code_blocks = [CodeBlock(code="/* filename: test.css */\nh1 { color: red; }", language="css")]
  167. code_result = executor.execute_code_blocks(code_blocks)
  168. assert code_result.exit_code == 0 and "hello world!" not in code_result.output and code_result.code_file is not None
  169. assert os.path.basename(code_result.code_file) == "test.css"
  170. # Test saving to a given filename without "filename" prefix, CSS.
  171. code_blocks = [CodeBlock(code="/* test.css */\nh1 { color: red; }", language="css")]
  172. code_result = executor.execute_code_blocks(code_blocks)
  173. assert code_result.exit_code == 0 and "hello world!" not in code_result.output and code_result.code_file is not None
  174. assert os.path.basename(code_result.code_file) == "test.css"
  175. # Test saving to a given filename, HTML.
  176. code_blocks = [CodeBlock(code="<!-- filename: test.html -->\n<h1>hello world!</h1>", language="html")]
  177. code_result = executor.execute_code_blocks(code_blocks)
  178. assert code_result.exit_code == 0 and "hello world!" not in code_result.output and code_result.code_file is not None
  179. assert os.path.basename(code_result.code_file) == "test.html"
  180. # Test saving to a given filename without "filename" prefix, HTML.
  181. code_blocks = [CodeBlock(code="<!-- test.html -->\n<h1>hello world!</h1>", language="html")]
  182. code_result = executor.execute_code_blocks(code_blocks)
  183. assert code_result.exit_code == 0 and "hello world!" not in code_result.output and code_result.code_file is not None
  184. assert os.path.basename(code_result.code_file) == "test.html"
  185. @pytest.mark.parametrize("cls", classes_to_test)
  186. def test_commandline_code_executor_timeout(cls) -> None:
  187. with tempfile.TemporaryDirectory() as temp_dir:
  188. executor = cls(timeout=1, work_dir=temp_dir)
  189. _test_timeout(executor)
  190. def _test_timeout(executor: CodeExecutor) -> None:
  191. code_blocks = [CodeBlock(code="import time; time.sleep(10); print('hello world!')", language="python")]
  192. code_result = executor.execute_code_blocks(code_blocks)
  193. assert code_result.exit_code and "Timeout" in code_result.output
  194. def test_local_commandline_code_executor_restart() -> None:
  195. executor = LocalCommandLineCodeExecutor()
  196. _test_restart(executor)
  197. # This is kind of hard to test because each exec is a new env
  198. @pytest.mark.skipif(
  199. skip_docker_test,
  200. reason="docker is not running or requested to skip docker tests",
  201. )
  202. def test_docker_commandline_code_executor_restart() -> None:
  203. with DockerCommandLineCodeExecutor() as executor:
  204. result = executor.execute_code_blocks([CodeBlock(code="echo $HOME", language="sh")])
  205. assert result.exit_code == 0
  206. executor.restart()
  207. result = executor.execute_code_blocks([CodeBlock(code="echo $HOME", language="sh")])
  208. assert result.exit_code == 0
  209. @pytest.mark.skipif(
  210. skip_docker_test,
  211. reason="docker is not running or requested to skip docker tests",
  212. )
  213. def test_policy_override():
  214. default_policy = DockerCommandLineCodeExecutor.DEFAULT_EXECUTION_POLICY
  215. custom_policy = {
  216. "python": False,
  217. "javascript": True,
  218. }
  219. executor = DockerCommandLineCodeExecutor(execution_policies=custom_policy)
  220. assert not executor.execution_policies["python"], "Python execution should be disabled"
  221. assert executor.execution_policies["javascript"], "JavaScript execution should be enabled"
  222. for lang, should_execute in default_policy.items():
  223. if lang not in custom_policy:
  224. assert executor.execution_policies[lang] == should_execute, f"Policy for {lang} should not be changed"
  225. assert set(executor.execution_policies.keys()) == set(
  226. default_policy.keys()
  227. ), "Execution policies should only contain known languages"
  228. def _test_restart(executor: CodeExecutor) -> None:
  229. # Check warning.
  230. with pytest.warns(UserWarning, match=r".*No action is taken."):
  231. executor.restart()
  232. @pytest.mark.parametrize("cls", classes_to_test)
  233. def test_commandline_executor_conversable_agent_code_execution(cls) -> None:
  234. with tempfile.TemporaryDirectory() as temp_dir:
  235. executor = cls(work_dir=temp_dir)
  236. with pytest.MonkeyPatch.context() as mp:
  237. mp.setenv("OPENAI_API_KEY", MOCK_OPEN_AI_API_KEY)
  238. _test_conversable_agent_code_execution(executor)
  239. def _test_conversable_agent_code_execution(executor: CodeExecutor) -> None:
  240. agent = ConversableAgent(
  241. "user_proxy",
  242. code_execution_config={"executor": executor},
  243. llm_config=False,
  244. )
  245. assert agent.code_executor is executor
  246. message = """
  247. Example:
  248. ```python
  249. print("hello extract code")
  250. ```
  251. """
  252. reply = agent.generate_reply(
  253. [{"role": "user", "content": message}],
  254. sender=ConversableAgent("user", llm_config=False, code_execution_config=False),
  255. )
  256. assert "hello extract code" in reply # type: ignore[operator]
  257. # Test cases for dangerous commands that should be caught by the sanitizer
  258. @pytest.mark.parametrize(
  259. "lang, code, expected_message",
  260. [
  261. ("bash", "rm -rf /", "Use of 'rm -rf' command is not allowed."),
  262. ("bash", "mv myFile /dev/null", "Moving files to /dev/null is not allowed."),
  263. ("bash", "dd if=/dev/zero of=/dev/sda", "Use of 'dd' command is not allowed."),
  264. ("bash", "echo Hello > /dev/sda", "Overwriting disk blocks directly is not allowed."),
  265. ("bash", ":(){ :|:& };:", "Fork bombs are not allowed."),
  266. ],
  267. )
  268. def test_dangerous_commands(lang, code, expected_message):
  269. with pytest.raises(ValueError) as exc_info:
  270. LocalCommandLineCodeExecutor.sanitize_command(lang, code)
  271. assert expected_message in str(
  272. exc_info.value
  273. ), f"Expected message '{expected_message}' not found in '{str(exc_info.value)}'"
  274. @pytest.mark.parametrize("cls", classes_to_test)
  275. def test_invalid_relative_path(cls) -> None:
  276. executor = cls()
  277. code = """# filename: /tmp/test.py
  278. print("hello world")
  279. """
  280. result = executor.execute_code_blocks([CodeBlock(code=code, language="python")])
  281. assert result.exit_code == 1 and "Filename is not in the workspace" in result.output
  282. @pytest.mark.parametrize("cls", classes_to_test)
  283. def test_valid_relative_path(cls) -> None:
  284. with tempfile.TemporaryDirectory() as temp_dir:
  285. temp_dir = Path(temp_dir)
  286. executor = cls(work_dir=temp_dir)
  287. code = """# filename: test.py
  288. print("hello world")
  289. """
  290. result = executor.execute_code_blocks([CodeBlock(code=code, language="python")])
  291. assert result.exit_code == 0
  292. assert "hello world" in result.output
  293. assert "test.py" in result.code_file
  294. assert (temp_dir / "test.py").resolve() == Path(result.code_file).resolve()
  295. assert (temp_dir / "test.py").exists()
  296. @pytest.mark.parametrize("cls", classes_to_test)
  297. @pytest.mark.parametrize("lang", WINDOWS_SHELLS + UNIX_SHELLS)
  298. def test_silent_pip_install(cls, lang: str) -> None:
  299. # Ensure that the shell is supported.
  300. lang = "ps1" if lang in ["powershell", "pwsh"] else lang
  301. if sys.platform in ["win32"] and lang in UNIX_SHELLS:
  302. pytest.skip("Linux shells are not supported on Windows.")
  303. elif sys.platform not in ["win32"] and lang in WINDOWS_SHELLS:
  304. pytest.skip("Windows shells are not supported on Unix.")
  305. error_exit_code = 0 if sys.platform in ["win32"] else 1
  306. executor = cls(timeout=600)
  307. code = "pip install matplotlib numpy"
  308. code_blocks = [CodeBlock(code=code, language=lang)]
  309. code_result = executor.execute_code_blocks(code_blocks)
  310. assert code_result.exit_code == 0 and code_result.output.strip() == ""
  311. none_existing_package = uuid.uuid4().hex
  312. code = f"pip install matplotlib_{none_existing_package}"
  313. code_blocks = [CodeBlock(code=code, language=lang)]
  314. code_result = executor.execute_code_blocks(code_blocks)
  315. assert code_result.exit_code == error_exit_code and "ERROR: " in code_result.output
  316. def test_local_executor_with_custom_python_env():
  317. with tempfile.TemporaryDirectory() as temp_dir:
  318. env_builder = venv.EnvBuilder(with_pip=True)
  319. env_builder.create(temp_dir)
  320. env_builder_context = env_builder.ensure_directories(temp_dir)
  321. executor = LocalCommandLineCodeExecutor(work_dir=temp_dir, virtual_env_context=env_builder_context)
  322. code_blocks = [
  323. # https://stackoverflow.com/questions/1871549/how-to-determine-if-python-is-running-inside-a-virtualenv
  324. CodeBlock(code="import sys; print(sys.prefix != sys.base_prefix)", language="python"),
  325. ]
  326. execution = executor.execute_code_blocks(code_blocks)
  327. assert execution.exit_code == 0
  328. assert execution.output.strip() == "True"
  329. def test_local_executor_with_custom_python_env_in_local_relative_path():
  330. try:
  331. relative_folder_path = "temp_folder"
  332. if not os.path.isdir(relative_folder_path):
  333. os.mkdir(relative_folder_path)
  334. venv_path = os.path.join(relative_folder_path, ".venv")
  335. env_builder = venv.EnvBuilder(with_pip=True)
  336. env_builder.create(venv_path)
  337. env_builder_context = env_builder.ensure_directories(venv_path)
  338. executor = LocalCommandLineCodeExecutor(work_dir=relative_folder_path, virtual_env_context=env_builder_context)
  339. code_blocks = [
  340. CodeBlock(code="import sys; print(sys.executable)", language="python"),
  341. ]
  342. execution = executor.execute_code_blocks(code_blocks)
  343. assert execution.exit_code == 0
  344. # Check if the expected venv is used
  345. bin_path = os.path.abspath(env_builder_context.bin_path)
  346. assert Path(execution.output.strip()).parent.samefile(bin_path)
  347. finally:
  348. if os.path.isdir(relative_folder_path):
  349. shutil.rmtree(relative_folder_path)