Spaces:
Running
Running
Download native_schema.py from Leon4gr45/needle: direct link, hf CLI and curl.
- Browser
- Download file 1.71 kB
-
https://huggingface.co/spaces/Leon4gr45/needle/resolve/main/native_schema.py
- Command line
-
hf download hf://spaces/Leon4gr45/needle/native_schema.py
-
curl -L -o native_schema.py https://huggingface.co/spaces/Leon4gr45/needle/resolve/main/native_schema.py
1.71 kB
| """Private SDK schema view: omit non-assertive titles, preserve constraints. | |
| Needle can copy a field title such as 'Path' into its arguments. Titles are JSON | |
| Schema annotations, not validation keywords. Never walk instance-valued keywords | |
| (const/enum/default/examples) or erase a property literally named 'title'. Public | |
| catalogues and complete original-schema validation remain unchanged. | |
| """ | |
| import copy | |
| _MAPS=('properties','patternProperties','$defs','definitions','dependentSchemas') | |
| _SINGLE=('additionalProperties','unevaluatedProperties','propertyNames','contains','additionalItems','unevaluatedItems','not','if','then','else','contentSchema') | |
| _LISTS=('allOf','anyOf','oneOf','prefixItems') | |
| def _schema(schema): | |
| if not isinstance(schema,dict):return copy.deepcopy(schema) | |
| result=copy.deepcopy(schema);result.pop('title',None) | |
| for key in _MAPS: | |
| if isinstance(result.get(key),dict):result[key]={name:_schema(child) for name,child in result[key].items()} | |
| for key in _SINGLE: | |
| if key in result:result[key]=_schema(result[key]) | |
| for key in _LISTS: | |
| if isinstance(result.get(key),list):result[key]=[_schema(child) for child in result[key]] | |
| if 'items' in result: | |
| value=result['items'];result['items']=[_schema(child) for child in value] if isinstance(value,list) else _schema(value) | |
| if isinstance(result.get('dependencies'),dict): | |
| result['dependencies']={name:_schema(value) if isinstance(value,(dict,bool)) else value for name,value in result['dependencies'].items()} | |
| return result | |
| def inference_tools(tools): | |
| result=copy.deepcopy(tools) | |
| for tool in result:tool['parameters']=_schema(tool['parameters']) | |
| return result | |