-
Notifications
You must be signed in to change notification settings - Fork 211
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: AgentLegoToolkit #164
Open
liujiangning30
wants to merge
14
commits into
InternLM:main
Choose a base branch
from
liujiangning30:ljn/agentlego_toolkit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bed25f2
Feat: AgentLegoToolkit
liujiangning30 deaca83
refine code
liujiangning30 de64e7e
To lagent
liujiangning30 02701c2
To lagent
liujiangning30 c66c0d6
fix comments
liujiangning30 a3e2822
rename 'type' to 'name'
liujiangning30 e014aa5
test 7b model
liujiangning30 6c5a37e
test 7b model
liujiangning30 83a070d
Merge branch 'main' of github.com:InternLM/lagent into ljn/agentlego_…
liujiangning30 d60881e
Fix errmsg: cast dict to str
liujiangning30 ec00c7d
cast errmsg to type str in builtin_actions
liujiangning30 24304ac
update
liujiangning30 ca2682a
update for mindSearch
liujiangning30 84fd0a6
Feat: stream chat for GPTAPI
liujiangning30 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,51 @@ | ||||||||||||
from typing import Optional | ||||||||||||
|
||||||||||||
# from agentlego.parsers import DefaultParser | ||||||||||||
from agentlego.tools.remote import RemoteTool | ||||||||||||
|
||||||||||||
from lagent import BaseAction | ||||||||||||
from lagent.actions.parser import JsonParser | ||||||||||||
|
||||||||||||
|
||||||||||||
class AgentLegoToolkit(BaseAction): | ||||||||||||
|
||||||||||||
def __init__(self, | ||||||||||||
type: str, | ||||||||||||
url: Optional[str] = None, | ||||||||||||
text: Optional[str] = None, | ||||||||||||
spec_dict: Optional[dict] = None, | ||||||||||||
parser=JsonParser, | ||||||||||||
enable: bool = True): | ||||||||||||
|
||||||||||||
if url is not None: | ||||||||||||
spec = dict(url=url) | ||||||||||||
elif text is not None: | ||||||||||||
spec = dict(text=text) | ||||||||||||
else: | ||||||||||||
assert spec_dict is not None | ||||||||||||
spec = dict(spec_dict=spec_dict) | ||||||||||||
if url is not None and not url.endswith('.json'): | ||||||||||||
api_list = [RemoteTool.from_url(url).to_lagent()] | ||||||||||||
else: | ||||||||||||
api_list = [ | ||||||||||||
api.to_lagent() for api in RemoteTool.from_openapi(**spec) | ||||||||||||
] | ||||||||||||
api_desc = [] | ||||||||||||
for api in api_list: | ||||||||||||
api_desc.append(api.description) | ||||||||||||
if len(api_list) > 1: | ||||||||||||
tool_description = dict(name=type, api_list=api_desc) | ||||||||||||
self.add_method(api_list) | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Suggested change
|
||||||||||||
else: | ||||||||||||
tool_description = api_desc[0] | ||||||||||||
setattr(self, 'run', api_list[0].run) | ||||||||||||
super().__init__( | ||||||||||||
description=tool_description, parser=parser, enable=enable) | ||||||||||||
|
||||||||||||
@property | ||||||||||||
def is_toolkit(self): | ||||||||||||
return 'api_list' in self.description | ||||||||||||
|
||||||||||||
def add_method(self, funcs): | ||||||||||||
for func in funcs: | ||||||||||||
setattr(self, func.name, func.run) | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.