mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-11 00:58:30 +00:00
0b3f00e6 chore: update project version to 0.73.0 and revise uv.lock dependencies (#455) ad19b074 feat: replace embedchain with native crewai adapter (#451) git-subtree-dir: packages/tools git-subtree-split: 0b3f00e67c0dae24d188c292dc99759fd1c841f7
30 lines
1.0 KiB
Python
30 lines
1.0 KiB
Python
import hashlib
|
|
from typing import Any
|
|
|
|
def compute_sha256(content: str) -> str:
|
|
return hashlib.sha256(content.encode("utf-8")).hexdigest()
|
|
|
|
def sanitize_metadata_for_chromadb(metadata: dict[str, Any]) -> dict[str, Any]:
|
|
"""Sanitize metadata to ensure ChromaDB compatibility.
|
|
|
|
ChromaDB only accepts str, int, float, or bool values in metadata.
|
|
This function converts other types to strings.
|
|
|
|
Args:
|
|
metadata: Dictionary of metadata to sanitize
|
|
|
|
Returns:
|
|
Sanitized metadata dictionary with only ChromaDB-compatible types
|
|
"""
|
|
sanitized = {}
|
|
for key, value in metadata.items():
|
|
if isinstance(value, (str, int, float, bool)) or value is None:
|
|
sanitized[key] = value
|
|
elif isinstance(value, (list, tuple)):
|
|
# Convert lists/tuples to pipe-separated strings
|
|
sanitized[key] = " | ".join(str(v) for v in value)
|
|
else:
|
|
# Convert other types to string
|
|
sanitized[key] = str(value)
|
|
return sanitized
|