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

refactor: toolkits #1012

Draft
wants to merge 31 commits into
base: master
Choose a base branch
from
Draft

refactor: toolkits #1012

wants to merge 31 commits into from

Conversation

Wendong-Fan
Copy link
Member

Description

Describe your changes in detail.

Motivation and Context

Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.
You can use the syntax close #15213 if this solves the issue #15213

  • 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.

Comment on lines 58 to 71
if hasattr(module, '__all__'):
for name in module.__all__:
func = getattr(module, name, None)
if callable(func) and func.__module__ == module.__name__:
self.toolkits[name] = func
else:
for name, func in inspect.getmembers(
module, inspect.isfunction
):
if (
not name.startswith('_')
and func.__module__ == module.__name__
):
self.toolkits[name] = func
Copy link
Member

Choose a reason for hiding this comment

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

It might be because I previously had limited understanding of discussions about refactoring, but could you explain why the get_tools method from BaseToolkit wasn't used here to obtain all available tools? Thank you for your explanation!

Copy link
Collaborator

@ZackYule ZackYule Oct 12, 2024

Choose a reason for hiding this comment

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

Hi~ @yiyiyi0817 Since using the get_tools method requires instantiating BaseToolkit, calling it to list all tools would cause all BaseToolkit classes to be instantiated, which could lead to unnecessary resource usage. It might be more efficient to instantiate the BaseToolkit class only when a specific tool is being used.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It might be because I previously had limited understanding of discussions about refactoring, but could you explain why the get_tools method from BaseToolkit wasn't used here to obtain all available tools? Thank you for your explanation!

I believe it might be better if we could list all functional tools as well as the BaseToolkit tools in one place, rather than listing all tools within a single BaseToolkit class.

Copy link
Member

Choose a reason for hiding this comment

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

Zack and I discussed in slack that there may be some duplication in the functions of our two PRs(#1012 and #1036). This may depend on how we want users to use all tookits. Does BaseTookit itself needlist_toolsand get_a_tool methods, or do we need to load all toolkits through an external Manager to complete this process?

In addition, the design of BaseTookit.get_tools method and @export_to_toolkit decorator may also be duplicated. Further and more extensive discussion is needed.

Regarding the instantiation problem of using get_tools design, one solution is to make get_tools, list_tools and get_a_tool methods as class methods, but the premise is that these methods do not really need to be instantiated.

And open_api_function need to be considered also.

@ZackYule ZackYule self-assigned this Oct 12, 2024
@ZackYule
Copy link
Collaborator

ZackYule commented Oct 15, 2024

At this point, all toolkit usage methods are fully supported, and the presentation of these methods has been unified (with the exception of OpenAPIToolkit):
Toolkits that don’t support FUNCS and require configuration no longer need to have the get_tools method manually written;
Toolkits that do support FUNCS should define tools as functions and override the get_tools method in a standardized format.

@ZackYule
Copy link
Collaborator

Initial support has been added for using multiple tool instances within the same toolkit class, but further improvements will require adding support for modifying the docstrings of tool instances.

@Wendong-Fan Wendong-Fan changed the title Refactor/toolkits refactor: toolkits Oct 15, 2024
@yiyiyi0817
Copy link
Member

At this point, all toolkit usage methods are fully supported, and the presentation of these methods has been unified (with the exception of OpenAPIToolkit): Toolkits that don’t support FUNCS and require configuration no longer need to have the get_tools method manually written; Toolkits that do support FUNCS should define tools as functions and override the get_tools method in a standardized format.

If needed, I can help to integrate OpenAPIToolkit to the Tookit Manager.

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

Successfully merging this pull request may close these issues.

5 participants