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 all commits
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
23 changes: 20 additions & 3 deletions modelscope_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,28 @@ def _register_tool(self,
Returns:

"""
tool_name = tool
tool_name = None
tool_cfg = {}

# # Check if the tool is a dictionary and extract the tool name and configuration from it.
if isinstance(tool, dict):
tool_name = next(iter(tool))
tool_cfg = tool[tool_name]
try:
tool_name = next(iter(tool))
tool_cfg = tool[tool_name]
except StopIteration:
# If the tool is an empty dictionary, proceed to register the next tool.
print("Empty tool dictionary provided, skipping the registration of the current tool")
return

# If the tool is a string, assign it directly to tool_name.
elif isinstance(tool, str):
tool_name = tool

# If the tool_name is empty, skip the registration of the current tool.
if not tool_name:
print("No tool name provided, skipping the registration of the current tool")
return

if tool_name not in TOOL_REGISTRY and not self.use_tool_api:
raise NotImplementedError
if tool_name not in self.function_list:
Expand Down
9 changes: 9 additions & 0 deletions modelscope_agent/tools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ def __init__(self,
self.tenant_id = tenant_id
self._register_tool()

if not self.tool_name:
print("Skipping tool registration and status check because 'tool_name' is not defined or empty.")
return # When tool_name is an empty string, skip registration and status check.

max_retry = 10
while max_retry > 0:
status = self._check_tool_status()
Expand Down Expand Up @@ -368,6 +372,11 @@ def parse_service_response(response):

def _register_tool(self):
try:
# Check if `tool_name` is defined and not empty.
if not self.tool_name:
print("Skipping tool registration because 'tool_name' is not defined or empty.")
return # Return directly, skipping registration.

service_token = os.getenv('TOOL_MANAGER_AUTH', '')
headers = {
'Content-Type': 'application/json',
Expand Down
9 changes: 5 additions & 4 deletions modelscope_agent/tools/utils/openapi_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,14 @@ def swagger_to_openapi(swagger_data):

def openapi_schema_convert(schema: dict, auth: dict = {}):
config_data = {}
host = schema.get('host', '')
host = schema.get('host', '') if schema else '' # Check if schema is None

if host:
schema = swagger_to_openapi(schema)
schema = swagger_to_openapi(schema) if schema else {} # Call only if schema is not None

schema = jsonref.replace_refs(schema)
schema = jsonref.replace_refs(schema) if schema else {} # Call only if schema is not None

servers = schema.get('servers', [])
servers = schema.get('servers', []) if schema else [] # Check if schema is None

if servers:
servers_url = servers[0].get('url')
Expand Down