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

工具名称为空或错误时,跳过注册 #605

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions modelscope_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,19 @@ def _register_tool(self,
Returns:

"""
tool_name = tool
tool_cfg = {}
# Check if tool is a dictionary and extract the tool name
if isinstance(tool, dict):
tool_name = next(iter(tool), None) # Use None as default to handle empty dict
tool_cfg = tool[tool_name]

Choose a reason for hiding this comment

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

KeyError

else:
tool_name = tool
tool_cfg = {}

# Skip registration if tool_name is None or empty
if not tool_name:
print("Skipping tool registration because 'tool_name' is not defined or empty.")
return

if isinstance(tool, dict):
tool_name = next(iter(tool))
tool_cfg = tool[tool_name]
Expand Down
5 changes: 5 additions & 0 deletions modelscope_agent/tools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,11 @@ def parse_service_response(response):

def _register_tool(self):
try:
# 检查tool_name是否已定义且非空

Choose a reason for hiding this comment

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

English

if not hasattr(self, 'tool_name') or not self.tool_name:

Choose a reason for hiding this comment

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

if getattr(self, 'tool_name', None) is None

print("Skipping tool registration because 'tool_name' is not defined or empty.")
return # 直接返回,跳过注册

service_token = os.getenv('TOOL_MANAGER_AUTH', '')
headers = {
'Content-Type': 'application/json',
Expand Down