MCPcopy
hub / github.com/OpenBMB/ToolBench / observation_shorten

Function observation_shorten

toolbench/inference/server.py:110–126  ·  view source on GitHub ↗
(schema_root, response_dict, category, tool_name, api_name, strip_method)

Source from the content-addressed store, hash-verified

108 return origin
109
110def 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
129def get_rapidapi_response(input_dict: dict, api_customization: bool=False, tools_root: str="data.toolenv.tools", schema_root: str="data/toolenv/response_examples"):

Callers 1

get_rapidapi_responseFunction · 0.85

Calls 3

change_nameFunction · 0.90
standardizeFunction · 0.90
dict_shortenFunction · 0.85

Tested by

no test coverage detected