Skip to content

Commit

Permalink
Merge branch 'dev' into pgvector-add-normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
hajdul88 authored Jan 20, 2025
2 parents 2546844 + bbb8e89 commit 813a03c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/test_dynamic_steps_example_windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: test

on:
workflow_dispatch:
pull_request:
types: [labeled, synchronize]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
run_notebook_test_windows:
name: windows-latest
runs-on: windows-latest
defaults:
run:
shell: bash
steps:
- name: Check out
uses: actions/checkout@master

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11.x'

- name: Install Poetry
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Install dependencies
run: |
poetry install --no-interaction --all-extras
- name: Execute Python Example
env:
ENV: 'dev'
PYTHONFAULTHANDLER: 1
LLM_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: poetry run python ./examples/python/dynamic_steps_example.py
30 changes: 24 additions & 6 deletions cognee/infrastructure/databases/graph/networkx/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ async def save_graph_to_file(self, file_path: str = None) -> None:
graph_data = nx.readwrite.json_graph.node_link_data(self.graph)

async with aiofiles.open(file_path, "w") as file:
await file.write(json.dumps(graph_data, cls=JSONEncoder))
json_data = json.dumps(graph_data, cls=JSONEncoder)
await file.write(json_data)

async def load_graph_from_file(self, file_path: str = None):
"""Asynchronously load the graph from a file in JSON format."""
Expand All @@ -265,19 +266,32 @@ async def load_graph_from_file(self, file_path: str = None):
graph_data = json.loads(await file.read())
for node in graph_data["nodes"]:
try:
node["id"] = UUID(node["id"])
if not isinstance(node["id"], UUID):
node["id"] = UUID(node["id"])
except Exception as e:
print(e)
pass
if "updated_at" in node:

if isinstance(node.get("updated_at"), int):
node["updated_at"] = datetime.fromtimestamp(
node["updated_at"] / 1000, tz=timezone.utc
)
elif isinstance(node.get("updated_at"), str):
node["updated_at"] = datetime.strptime(
node["updated_at"], "%Y-%m-%dT%H:%M:%S.%f%z"
)

for edge in graph_data["links"]:
try:
source_id = UUID(edge["source"])
target_id = UUID(edge["target"])
if not isinstance(edge["source"], UUID):
source_id = UUID(edge["source"])
else:
source_id = edge["source"]

if not isinstance(edge["target"], UUID):
target_id = UUID(edge["target"])
else:
target_id = edge["target"]

edge["source"] = source_id
edge["target"] = target_id
Expand All @@ -287,7 +301,11 @@ async def load_graph_from_file(self, file_path: str = None):
print(e)
pass

if "updated_at" in edge:
if isinstance(edge["updated_at"], int): # Handle timestamp in milliseconds
edge["updated_at"] = datetime.fromtimestamp(
edge["updated_at"] / 1000, tz=timezone.utc
)
elif isinstance(edge["updated_at"], str):
edge["updated_at"] = datetime.strptime(
edge["updated_at"], "%Y-%m-%dT%H:%M:%S.%f%z"
)
Expand Down

0 comments on commit 813a03c

Please sign in to comment.