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

Function dict_shorten

toolbench/inference/server.py:96–108  ·  view source on GitHub ↗
(origin: dict, schema: dict)

Source from the content-addressed store, hash-verified

94
95
96def dict_shorten(origin: dict, schema: dict):
97 for key, value in list(origin.items()):
98 if key not in schema:
99 del origin[key]
100 else:
101 if isinstance(value, dict):
102 dict_shorten(value, schema[key]) # schema[key] should be a dict
103 elif isinstance(value, list):
104 if value:
105 if isinstance(value[0], dict):
106 for item in value:
107 dict_shorten(item, schema[key][0]) # schema[key] should be a list with only one dict element
108 return origin
109
110def observation_shorten(schema_root, response_dict, category, tool_name, api_name, strip_method):
111 print(random.random())

Callers 1

observation_shortenFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected