Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: python interpreter #182

Merged
merged 21 commits into from
Jul 4, 2023
Merged

feat: python interpreter #182

merged 21 commits into from
Jul 4, 2023

Conversation

dandansamax
Copy link
Collaborator

Description

  • Extract utils.py as a individual module camel.utils
  • Add PythonInterpreter class in camel.utils, an abstraction controlable python code executor. It contains several features than eval() like variable accessing control, module import, and fuzzy variable matching. It is also extendable and flexiable.
  • Change code executor of EmbodiedAgent from built-in function eval() to PythonInterpreter

Motivation and Context

#150

  • I have raised an issue to propose this change (required for new features and bug fixes)

Types of changes

What types of changes does your code introduce? Put an x in all the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds core functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (update in the documentation)
  • Example (update in the folder of example)

Implemented Tasks

  • Subtask 1
  • Subtask 2
  • Subtask 3

Checklist

Go over all the following points, and put an x in all the boxes that apply.
If you are unsure about any of these, don't hesitate to ask. We are here to help!

  • I have read the CONTRIBUTION guide. (required)
  • My change requires a change to the documentation.
  • I have updated the tests accordingly. (required for a bug fix or a new feature)
  • I have updated the documentation accordingly.

@dandansamax
Copy link
Collaborator Author

The example in hugging_face_tool.py has been run successfully.

@lightaime
Copy link
Member

Thanks, @dandansamax. Looks amazing. I will look into it soon!

@lightaime lightaime requested a review from oserikov June 28, 2023 01:43
Copy link
Collaborator

@Obs01ete Obs01ete left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks cool. Please let us know if it is an original code or it was borrowed from somewhere.

camel/prompts/base.py Outdated Show resolved Hide resolved
camel/prompts/base.py Show resolved Hide resolved
camel/utils/__init__.py Outdated Show resolved Hide resolved
camel/utils/python_interpreter.py Outdated Show resolved Hide resolved
camel/utils/python_interpreter.py Outdated Show resolved Hide resolved
self.state = self.action_space.copy()
self.fuzz_state = {}

def _execute_ast(self, expression: ast.AST) -> Any:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this whole file taken from somewhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic of this class was borrowed from hugging face agent. See python_interpreter.py. However, most of the codes are rewritten to fit our need.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lightaime I think we should refer the original file since it is quite similar

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm not very familiar with these licenses and copyright things. As Apache 2.0 request, I should contain original license from HuggingFace team and add our modifications copyright. However, the license checker didn't allow me to do that. Also, I don't know if it is acceptable in our project.

Another solution may be to totally modify its implementation. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we should add the link to the original hugging face implementation and their license to the docstring of PythonInterpreter, and mention that it is adapted from the hugging face implementation. We should also mention what is added and rewritten.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your advisions. I have updated the docstring.

camel/agents/embodied_agent.py Show resolved Hide resolved
@lightaime lightaime added the Prompt Related to camel prompts label Jun 30, 2023
Copy link
Member

@lightaime lightaime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Liked it. Left some comments. As we mention, we may also support other actions like file IO. But it is not in the scope of this PR. But we may support unsafe running mode or safe running mode with docker in the future. Thanks!

camel/utils/__init__.py Outdated Show resolved Hide resolved
camel/utils/__init__.py Outdated Show resolved Hide resolved
self.state = self.action_space.copy()
self.fuzz_state = {}

def _execute_ast(self, expression: ast.AST) -> Any:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we should add the link to the original hugging face implementation and their license to the docstring of PythonInterpreter, and mention that it is adapted from the hugging face implementation. We should also mention what is added and rewritten.

camel/utils/python_interpreter.py Outdated Show resolved Hide resolved
Returns:
Any: An evaluation value of the last line in the code.
"""
if state:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if state:
if state is not None:

test/utils/test_python_interpreter.py Outdated Show resolved Hide resolved
test/utils/test_python_interpreter.py Outdated Show resolved Hide resolved
camel/prompts/base.py Outdated Show resolved Hide resolved
camel/utils/python_interpreter.py Show resolved Hide resolved
test/utils/test_python_interpreter.py Outdated Show resolved Hide resolved
@Benjamin-eecs Benjamin-eecs changed the title Python interpreter feat: Python interpreter Jul 3, 2023
@Benjamin-eecs Benjamin-eecs changed the title feat: Python interpreter feat: python interpreter Jul 3, 2023
Copy link
Collaborator

@Obs01ete Obs01ete left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please resolve the remaining comment about the reference to the original code.

@dandansamax
Copy link
Collaborator Author

Please resolve the remaining comment about the reference to the original code.

Updated. Could you please review it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Prompt Related to camel prompts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants