(schema_root, response_dict, category, tool_name, api_name, strip_method)
| 108 | return origin |
| 109 | |
| 110 | def observation_shorten(schema_root, response_dict, category, tool_name, api_name, strip_method): |
| 111 | print(random.random()) |
| 112 | if strip_method == "filter" or (strip_method == "random" and random.random() > 0.5): |
| 113 | if isinstance(response_dict["response"], dict): |
| 114 | if os.path.exists(os.path.join(schema_root, category)): |
| 115 | if os.path.exists(os.path.join(schema_root, category, tool_name+".json")): |
| 116 | schema_dicts = json.load(open(os.path.join(schema_root, category, tool_name+".json"), "r")) |
| 117 | api_list = schema_dicts["api_list"] |
| 118 | schema = None |
| 119 | for schema_dict in api_list: |
| 120 | schema_api_name = change_name(standardize(schema_dict["name"])) |
| 121 | if schema_api_name == api_name and len(schema_dict["schema"]) > 0: |
| 122 | schema = schema_dict["schema"] |
| 123 | break |
| 124 | if schema is not None: |
| 125 | response_dict["response"] = dict_shorten(response_dict["response"], schema) |
| 126 | return str(response_dict["response"]) |
| 127 | |
| 128 | |
| 129 | def get_rapidapi_response(input_dict: dict, api_customization: bool=False, tools_root: str="data.toolenv.tools", schema_root: str="data/toolenv/response_examples"): |
no test coverage detected