MCPcopy
hub / github.com/LazyAGI/LazyLLM / _extract_schema

Method _extract_schema

lazyllm/tools/tools/json.py:194–207  ·  view source on GitHub ↗
(self, jsons: List[Dict[str, Any]], schema: Optional[Dict[str, Any]] = None,
                        prefix: str = '')

Source from the content-addressed store, hash-verified

192 return result
193
194 def _extract_schema(self, jsons: List[Dict[str, Any]], schema: Optional[Dict[str, Any]] = None,
195 prefix: str = '') -> Dict[str, Any]:
196 schema = schema or {}
197 for json_obj in jsons:
198 for key, value in json_obj.items():
199 if isinstance(value, dict):
200 if (sub_schema := schema.get(key, {})) and not isinstance(sub_schema, dict):
201 raise ValueError(f'Key {key} already in schema with type {sub_schema} at {prefix}.')
202 schema[key] = self._extract_schema(value, sub_schema, prefix=f'{prefix}.{key}' if prefix else key)
203 else:
204 if key not in schema: schema[key] = type(value)
205 elif schema[key] != type(value):
206 raise ValueError(f'Key {key} already in schema with type {schema[key]} at {prefix}.')
207 return schema
208
209 def _distinct_aggregate(self, jsons: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
210 if len(jsons) <= 1: return jsons

Callers 1

forwardMethod · 0.95

Calls 2

itemsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected