Files
wehub-resource-sync c889a57b6b
Test Suites / Build CI Environment (push) Has been cancelled
Test Suites / Basic Tests (push) Has been cancelled
Test Suites / End-to-End Tests (push) Has been cancelled
Test Suites / CLI Tests (push) Has been cancelled
Test Suites / Slow End-to-End Tests (push) Has been cancelled
Test Suites / Graph Database Tests (push) Has been cancelled
Test Suites / Vector DB Tests (push) Has been cancelled
Test Suites / Temporal Graph Test (push) Has been cancelled
Test Suites / Search Test on Different DBs (push) Has been cancelled
Test Suites / Example Tests (push) Has been cancelled
Test Suites / Notebook Tests (push) Has been cancelled
Test Suites / OS and Python Tests Ubuntu (push) Has been cancelled
Test Suites / OS and Python Tests Extended (push) Has been cancelled
Test Suites / LLM Test Suite (push) Has been cancelled
Test Suites / S3 File Storage Test (push) Has been cancelled
Test Suites / Run Integration Tests (push) Has been cancelled
Test Suites / MCP Tests (push) Has been cancelled
Test Suites / Docker Compose Test (push) Has been cancelled
Test Suites / Docker CI test (push) Has been cancelled
Test Suites / Relational DB Migration Tests (push) Has been cancelled
Test Suites / Distributed Cognee Test (push) Has been cancelled
Test Suites / DB Examples Tests (push) Has been cancelled
Test Suites / Test Completion Status (push) Has been cancelled
Test Suites / Claude Code Review (push) Has been cancelled
Test Suites / basic checks (push) Has been cancelled
build | Build and Push Cognee MCP Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
build | Build and Push Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.11) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.12) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (kuzu, kuzu) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (neo4j, neo4j) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Examples (push) Has been cancelled
Weighted Edges Tests / Code Quality for Weighted Edges (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:02:24 +08:00

77 lines
2.5 KiB
Python

import json
import copy
from uuid import UUID
from decimal import Decimal
from datetime import datetime
from pydantic_core import PydanticUndefined
from pydantic import create_model, ConfigDict, BaseModel, Field
from cognee.infrastructure.engine import DataPoint
class JSONEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime):
return obj.isoformat() # Convert datetime to ISO 8601 string
elif isinstance(obj, UUID):
# if the obj is uuid, we simply return the value of uuid
return str(obj)
elif isinstance(obj, Decimal):
return float(obj)
return json.JSONEncoder.default(self, obj)
def copy_model(
model: DataPoint, include_fields: dict | None = None, exclude_fields: list | None = None
):
if include_fields is None:
include_fields = {}
if exclude_fields is None:
exclude_fields = []
fields = {}
for name, field in model.model_fields.items():
if name in exclude_fields:
continue
if hasattr(field, "is_required") and field.is_required():
fields[name] = (field.annotation, PydanticUndefined)
elif field.default_factory is not None:
fields[name] = (field.annotation, Field(default_factory=field.default_factory))
else:
# Preserve explicit None defaults (and other scalar/container defaults)
# so optional fields remain optional in copied models.
fields[name] = (field.annotation, copy.deepcopy(field.default))
final_fields = {**fields, **include_fields}
# Create a base class with the same configuration as DataPoint
class ConfiguredBase(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)
# Create the model inheriting from the configured base
new_model = create_model(model.__name__, __base__=ConfiguredBase, **final_fields)
new_model.model_rebuild()
return new_model
def get_own_properties(data_point: DataPoint):
properties = {}
for field_name, field_value in data_point:
if (
field_name == "metadata"
or isinstance(field_value, dict)
or isinstance(field_value, DataPoint)
or (
isinstance(field_value, list)
and len(field_value) > 0
and isinstance(field_value[0], DataPoint)
)
):
continue
properties[field_name] = field_value
return properties