Spaces:
Build error
Build error
Download backend/open_webui/retrieval/vector/utils.py from fathos82/open-webui: direct link, hf CLI and curl.
- Browser
- Download file 889 Bytes
-
https://huggingface.co/spaces/fathos82/open-webui/resolve/main/backend/open_webui/retrieval/vector/utils.py
- Command line
-
hf download hf://spaces/fathos82/open-webui/backend/open_webui/retrieval/vector/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/fathos82/open-webui/resolve/main/backend/open_webui/retrieval/vector/utils.py
889 Bytes
| from datetime import datetime | |
| KEYS_TO_EXCLUDE = ["content", "pages", "tables", "paragraphs", "sections", "figures"] | |
| def filter_metadata(metadata: dict[str, any]) -> dict[str, any]: | |
| # Removes large/redundant fields from metadata dict. | |
| metadata = { | |
| key: value for key, value in metadata.items() if key not in KEYS_TO_EXCLUDE | |
| } | |
| return metadata | |
| def process_metadata( | |
| metadata: dict[str, any], | |
| ) -> dict[str, any]: | |
| # Removes large fields and converts non-serializable types (datetime, list, dict) to strings. | |
| result = {} | |
| for key, value in metadata.items(): | |
| # Skip large fields | |
| if key in KEYS_TO_EXCLUDE: | |
| continue | |
| # Convert non-serializable fields to strings | |
| if isinstance(value, (datetime, list, dict)): | |
| result[key] = str(value) | |
| else: | |
| result[key] = value | |
| return result | |