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

Add support to declare imports for code agent #31355

Merged

Conversation

JasonZhu1313
Copy link
Contributor

@JasonZhu1313 JasonZhu1313 commented Jun 10, 2024

What does this PR do?

Collected suggestions and guidance from @aymeric-roucher!

Add support for declaring a list of available packages to import for the code agent. Previously, the code agent was limited to a fixed list of packages, which restricted its ability to utilize a wide range of Python's utilities and functionalities. By providing this import list explicitly, we aim to enable the model to leverage the provided packages.

List of changes:

  • Add "You can use imports in your code, but only from the following list of modules: <<authorized_imports>>" in prompt
  • Add functions to render the prompt with authorized import list provided by users.
  • Fix a bug in test, the test is meant to add FinalAnswer in toolset but it added two duplicated PythonInterpreter tools.
  • Added tests for updating prompt in python interpreter tool.
  • Replaced *tools* in DEFAULT_REACT_CODE_SYSTEM_PROMPT with <<tool_names>> which will later be replaced with a list of tool names to confine model on a list of possible tools it can invoke.
  • Allow a reduction of parsing errors by adding exception handling blocks for _, code_action = self.extract_action(llm_output=llm_output, split_token="Code:") and rationale, raw_code_action = self.extract_action(llm_output=llm_output, split_token="Code:")

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@aymeric-roucher
Copy link
Contributor

@JasonZhu1313 you can check failing style tests here

@JasonZhu1313
Copy link
Contributor Author

@JasonZhu1313 you can check failing style tests here

Done thanks!

@aymeric-roucher
Copy link
Contributor

Seems all good to me, thanks a lot @JasonZhu1313! @LysandreJik do you want to have a double check?

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

Ok, sounds good

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@aymeric-roucher aymeric-roucher merged commit a2ede66 into huggingface:main Jun 12, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants