From 1e4f71dacb620b629d9caa60e2fb05ee24985ceb Mon Sep 17 00:00:00 2001 From: hajdul88 <52442977+hajdul88@users.noreply.github.com> Date: Mon, 20 Jan 2025 09:32:09 +0100 Subject: [PATCH 1/5] feat: adds windows test for dynamic_steps_example --- .../test_dynamic_steps_example_windows.yml | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/test_dynamic_steps_example_windows.yml diff --git a/.github/workflows/test_dynamic_steps_example_windows.yml b/.github/workflows/test_dynamic_steps_example_windows.yml new file mode 100644 index 000000000..a97db9a5c --- /dev/null +++ b/.github/workflows/test_dynamic_steps_example_windows.yml @@ -0,0 +1,44 @@ +name: test-example-windows + +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: test-windows + 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 }} + GRAPHISTRY_USERNAME: ${{ secrets.GRAPHISTRY_USERNAME }} + GRAPHISTRY_PASSWORD: ${{ secrets.GRAPHISTRY_PASSWORD }} + run: poetry run python ./examples/python/dynamic_steps_example.py From b949b29fa7ffa90a417e2acdde572aa42240ab2a Mon Sep 17 00:00:00 2001 From: hajdul88 <52442977+hajdul88@users.noreply.github.com> Date: Mon, 20 Jan 2025 09:48:20 +0100 Subject: [PATCH 2/5] fix: changes graph DB to neo4j in windows test --- .github/workflows/test_dynamic_steps_example_windows.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_dynamic_steps_example_windows.yml b/.github/workflows/test_dynamic_steps_example_windows.yml index a97db9a5c..a3ee45da8 100644 --- a/.github/workflows/test_dynamic_steps_example_windows.yml +++ b/.github/workflows/test_dynamic_steps_example_windows.yml @@ -39,6 +39,7 @@ jobs: ENV: 'dev' PYTHONFAULTHANDLER: 1 LLM_API_KEY: ${{ secrets.OPENAI_API_KEY }} - GRAPHISTRY_USERNAME: ${{ secrets.GRAPHISTRY_USERNAME }} - GRAPHISTRY_PASSWORD: ${{ secrets.GRAPHISTRY_PASSWORD }} + GRAPH_DATABASE_URL: ${{ secrets.NEO4J_API_URL }} + GRAPH_DATABASE_PASSWORD: ${{ secrets.NEO4J_API_KEY }} + GRAPH_DATABASE_USERNAME: "neo4j" run: poetry run python ./examples/python/dynamic_steps_example.py From 7932cf71593a6c81a644ccb0b6b07eab7a3494b6 Mon Sep 17 00:00:00 2001 From: hajdul88 <52442977+hajdul88@users.noreply.github.com> Date: Mon, 20 Jan 2025 10:23:38 +0100 Subject: [PATCH 3/5] fix: sets graphdb back to networkx --- .github/workflows/test_dynamic_steps_example_windows.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/test_dynamic_steps_example_windows.yml b/.github/workflows/test_dynamic_steps_example_windows.yml index a3ee45da8..391f714da 100644 --- a/.github/workflows/test_dynamic_steps_example_windows.yml +++ b/.github/workflows/test_dynamic_steps_example_windows.yml @@ -39,7 +39,4 @@ jobs: ENV: 'dev' PYTHONFAULTHANDLER: 1 LLM_API_KEY: ${{ secrets.OPENAI_API_KEY }} - GRAPH_DATABASE_URL: ${{ secrets.NEO4J_API_URL }} - GRAPH_DATABASE_PASSWORD: ${{ secrets.NEO4J_API_KEY }} - GRAPH_DATABASE_USERNAME: "neo4j" run: poetry run python ./examples/python/dynamic_steps_example.py From bf70705ed045fcb299fc06982e53620a4dd03565 Mon Sep 17 00:00:00 2001 From: hajdul88 <52442977+hajdul88@users.noreply.github.com> Date: Mon, 20 Jan 2025 12:19:34 +0100 Subject: [PATCH 4/5] Fix: fixes networkx failed to load graph from file error --- .../databases/graph/networkx/adapter.py | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/cognee/infrastructure/databases/graph/networkx/adapter.py b/cognee/infrastructure/databases/graph/networkx/adapter.py index 75969c798..2cb6c2729 100644 --- a/cognee/infrastructure/databases/graph/networkx/adapter.py +++ b/cognee/infrastructure/databases/graph/networkx/adapter.py @@ -250,7 +250,8 @@ class NetworkXAdapter(GraphDBInterface): 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.""" @@ -265,19 +266,32 @@ class NetworkXAdapter(GraphDBInterface): 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 @@ -287,7 +301,11 @@ class NetworkXAdapter(GraphDBInterface): 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" ) From 957ab81879528c34ac231f78c6692abad1a62e29 Mon Sep 17 00:00:00 2001 From: hajdul88 <52442977+hajdul88@users.noreply.github.com> Date: Mon, 20 Jan 2025 12:27:22 +0100 Subject: [PATCH 5/5] chore: renaming test --- .github/workflows/test_dynamic_steps_example_windows.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_dynamic_steps_example_windows.yml b/.github/workflows/test_dynamic_steps_example_windows.yml index 391f714da..d0a9c93e3 100644 --- a/.github/workflows/test_dynamic_steps_example_windows.yml +++ b/.github/workflows/test_dynamic_steps_example_windows.yml @@ -1,4 +1,4 @@ -name: test-example-windows +name: test on: workflow_dispatch: @@ -11,7 +11,7 @@ concurrency: jobs: run_notebook_test_windows: - name: test-windows + name: windows-latest runs-on: windows-latest defaults: run: