From f9a4e869c0a85bb6868862a6d1e82f94ceed493e Mon Sep 17 00:00:00 2001 From: Zhicheng Zhang Date: Mon, 11 Nov 2024 16:35:26 +0800 Subject: [PATCH] make sure the data is structed in openapi --- modelscope_agent/tools/utils/openapi_utils.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/modelscope_agent/tools/utils/openapi_utils.py b/modelscope_agent/tools/utils/openapi_utils.py index 518321e9..2cce9c8e 100644 --- a/modelscope_agent/tools/utils/openapi_utils.py +++ b/modelscope_agent/tools/utils/openapi_utils.py @@ -6,6 +6,26 @@ def execute_api_call(url: str, method: str, headers: dict, params: dict, data: dict, cookies: dict): + + def structure_json(flat_json): + structured = {} + + for key, value in flat_json.items(): + parts = key.split('.') + current = structured + + for i, part in enumerate(parts): + if i == len(parts) - 1: + current[part] = value + else: + if part not in current: + current[part] = {} + current = current[part] + + return structured + + if data: + data = structure_json(data) try: print('url:', url) print('headers:', headers)