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..d0a9c93e3 --- /dev/null +++ b/.github/workflows/test_dynamic_steps_example_windows.yml @@ -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 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" )