Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
zzhangpurdue committed Nov 13, 2024
1 parent f21507e commit 50d63af
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
36 changes: 20 additions & 16 deletions modelscope_agent/tools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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}')
Expand Down
12 changes: 12 additions & 0 deletions modelscope_agent/tools/utils/openapi_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down

0 comments on commit 50d63af

Please sign in to comment.