diff --git a/modelscope_agent/tools/base.py b/modelscope_agent/tools/base.py index f5a9c4c1..8ad6e67a 100644 --- a/modelscope_agent/tools/base.py +++ b/modelscope_agent/tools/base.py @@ -12,10 +12,10 @@ DEFAULT_TOOL_MANAGER_SERVICE_URL, LOCAL_FILE_PATHS, MODELSCOPE_AGENT_TOKEN_HEADER_NAME) -from modelscope_agent.tools.utils.openapi_utils import (execute_api_call, +from modelscope_agent.tools.utils.openapi_utils import (dot_to_dict, + execute_api_call, get_parameter_value, - openapi_schema_convert, - structure_json) + openapi_schema_convert) from modelscope_agent.utils.base64_utils import decode_base64_to_files from modelscope_agent.utils.logger import agent_logger as logger from modelscope_agent.utils.utils import has_chinese_chars @@ -595,18 +595,18 @@ def _verify_args(self, params: str, api_info) -> Union[str, dict]: for param in api_info['parameters']: if 'required' in param and param['required']: - - current = {} - current_test = deepcopy(params_json) - parts = param['name'].split('.') - for i, part in enumerate(parts): - if part not in current: - current[part] = {} - current = current[part] - if part not in current_test: - raise ValueError( - f'param `{".".join(parts[:i])}` is required') - current_test = current_test[part] + if param['name'] not in params_json: + current = {} + current_test = deepcopy(params_json) + parts = param['name'].split('.') + for i, part in enumerate(parts): + if part not in current: + current[part] = {} + current = current[part] + if part not in current_test: + raise ValueError( + f'param `{".".join(parts[:i])}` is required') + current_test = current_test[part] return params_json def _parse_credentials(self, credentials: dict, headers=None): @@ -701,7 +701,11 @@ def call(self, params: str, **kwargs): elif parameter['in'] == 'header': header[parameter['name']] = value else: - data[parameter['name'].split('.')[0]] = value + if '.' in parameter['name']: + result = dot_to_dict(parameter['name'], value) + data.update(result) + else: + data[parameter['name'].split('.')[0]] = value for name, value in path_params.items(): url = url.replace(f'{{{name}}}', f'{value}') diff --git a/modelscope_agent/tools/utils/openapi_utils.py b/modelscope_agent/tools/utils/openapi_utils.py index 233bc81d..29b956bd 100644 --- a/modelscope_agent/tools/utils/openapi_utils.py +++ b/modelscope_agent/tools/utils/openapi_utils.py @@ -5,6 +5,18 @@ import requests +def dot_to_dict(key, value): + keys = key.split('.') + result = {} + current = result + for k in keys[:-1]: + current[k] = {} + current = current[k] + current[keys[ + -1]] = value # Using eval to convert the value to the appropriate type + return result + + def structure_json(flat_json): structured = {}