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