From a20662482111991d692e147aa0ebb7cd0432f75f Mon Sep 17 00:00:00 2001 From: suluyana Date: Wed, 4 Dec 2024 15:56:38 +0800 Subject: [PATCH] update agentfabric requirement & fix lint --- apps/agentfabric/requirements.txt | 2 +- modelscope_agent/agent.py | 8 +++++-- modelscope_agent/tools/base.py | 21 ++++++++++++------- modelscope_agent/tools/utils/openapi_utils.py | 9 +++++--- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/apps/agentfabric/requirements.txt b/apps/agentfabric/requirements.txt index 51731629..b2389dc5 100644 --- a/apps/agentfabric/requirements.txt +++ b/apps/agentfabric/requirements.txt @@ -1,7 +1,7 @@ gradio==4.36.1 markdown-cjk-spacing mdx_truly_sane_lists -modelscope-agent>=0.6.6 +modelscope-agent>=0.7.2 modelscope_studio>=0.4.0 moviepy pymdown-extensions diff --git a/modelscope_agent/agent.py b/modelscope_agent/agent.py index 67f22780..f15577e5 100644 --- a/modelscope_agent/agent.py +++ b/modelscope_agent/agent.py @@ -203,7 +203,9 @@ def _register_tool(self, 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") + 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. @@ -212,7 +214,9 @@ def _register_tool(self, # 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") + 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: diff --git a/modelscope_agent/tools/base.py b/modelscope_agent/tools/base.py index ad04f6ae..28570d55 100644 --- a/modelscope_agent/tools/base.py +++ b/modelscope_agent/tools/base.py @@ -337,7 +337,9 @@ def __init__(self, self._register_tool() if not self.tool_name: - print("Skipping tool registration and status check because 'tool_name' is not defined or empty.") + 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 @@ -375,7 +377,9 @@ 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.") + print( + "Skipping tool registration because 'tool_name' is not defined or empty." + ) return # Return directly, skipping registration. service_token = os.getenv('TOOL_MANAGER_AUTH', '') @@ -432,8 +436,8 @@ def _check_tool_status(self): return result['status'] except Exception as e: raise RuntimeError( - f'Get error during checking status from tool manager service: {self.tool_name} {self.tenant_id}. detail {e}, {traceback.format_exc()}' - ) + f'Get error during checking status from tool manager service: {self.tool_name} ' + f'{self.tenant_id}. detail {e}, {traceback.format_exc()}') def _get_tool_info(self): try: @@ -454,13 +458,14 @@ def _get_tool_info(self): response.raise_for_status() tool_info = ToolServiceProxy.parse_service_response(response) # check required params - name = tool_info['name'] - description = tool_info['description'] - parameters = tool_info['parameters'] + _ = tool_info['name'] + _ = tool_info['description'] + _ = tool_info['parameters'] return tool_info except Exception as e: raise RuntimeError( - f'Get error during getting tool info from tool manager, {self.tool_name} {self.tenant_id}. detail {e}, {traceback.format_exc()}' + f'Get error during getting tool info from tool manager, ' + f'{self.tool_name} {self.tenant_id}. detail {e}, {traceback.format_exc()}' ) def call(self, params: str, **kwargs): diff --git a/modelscope_agent/tools/utils/openapi_utils.py b/modelscope_agent/tools/utils/openapi_utils.py index e3e2bc3e..650960c9 100644 --- a/modelscope_agent/tools/utils/openapi_utils.py +++ b/modelscope_agent/tools/utils/openapi_utils.py @@ -192,11 +192,14 @@ def openapi_schema_convert(schema: dict, auth: dict = {}): host = schema.get('host', '') if schema else '' # Check if schema is None if host: - schema = swagger_to_openapi(schema) if schema else {} # Call only if schema is not None + schema = swagger_to_openapi(schema) if schema else { + } # Call only if schema is not None - schema = jsonref.replace_refs(schema) if schema else {} # Call only if schema is not None + schema = jsonref.replace_refs(schema) if schema else { + } # Call only if schema is not None - servers = schema.get('servers', []) if schema else [] # Check if schema is None + servers = schema.get('servers', []) if schema else [ + ] # Check if schema is None if servers: servers_url = servers[0].get('url')