From da40365932ce7056719dd323d6c721214e6919fa Mon Sep 17 00:00:00 2001 From: hajdul88 <52442977+hajdul88@users.noreply.github.com> Date: Wed, 13 Aug 2025 15:15:39 +0200 Subject: [PATCH] ruff formatting --- cognee/api/v1/exceptions/__init__.py | 2 +- cognee/api/v1/exceptions/exceptions.py | 9 +++++---- cognee/exceptions/exceptions.py | 1 - cognee/infrastructure/data/exceptions/__init__.py | 4 +--- cognee/infrastructure/databases/exceptions/__init__.py | 2 +- cognee/infrastructure/databases/exceptions/exceptions.py | 8 +++++--- cognee/infrastructure/llm/exceptions.py | 3 +++ .../litellm_instructor/llm/openai/adapter.py | 5 ++++- cognee/modules/graph/cognee_graph/CogneeGraph.py | 6 +++++- cognee/modules/graph/cognee_graph/CogneeGraphElements.py | 1 + cognee/modules/graph/exceptions/exceptions.py | 2 ++ cognee/modules/search/exceptions/__init__.py | 4 +--- .../unit/modules/graph/cognee_graph_elements_test.py | 1 + 13 files changed, 30 insertions(+), 18 deletions(-) diff --git a/cognee/api/v1/exceptions/__init__.py b/cognee/api/v1/exceptions/__init__.py index b2948934c..5767a5801 100644 --- a/cognee/api/v1/exceptions/__init__.py +++ b/cognee/api/v1/exceptions/__init__.py @@ -9,5 +9,5 @@ from .exceptions import ( DocumentNotFoundError, DatasetNotFoundError, DataNotFoundError, - DocumentSubgraphNotFoundError + DocumentSubgraphNotFoundError, ) diff --git a/cognee/api/v1/exceptions/exceptions.py b/cognee/api/v1/exceptions/exceptions.py index 8b65691f1..12dfa9d37 100644 --- a/cognee/api/v1/exceptions/exceptions.py +++ b/cognee/api/v1/exceptions/exceptions.py @@ -1,7 +1,4 @@ -from cognee.exceptions import ( - CogneeConfigurationError, - CogneeValidationError -) +from cognee.exceptions import CogneeConfigurationError, CogneeValidationError from fastapi import status @@ -15,6 +12,7 @@ class InvalidConfigAttributeError(CogneeConfigurationError): message = f"'{attribute}' is not a valid attribute of the configuration." super().__init__(message, name, status_code) + class DocumentNotFoundError(CogneeValidationError): def __init__( self, @@ -24,6 +22,7 @@ class DocumentNotFoundError(CogneeValidationError): ): super().__init__(message, name, status_code) + class DatasetNotFoundError(CogneeValidationError): def __init__( self, @@ -33,6 +32,7 @@ class DatasetNotFoundError(CogneeValidationError): ): super().__init__(message, name, status_code) + class DataNotFoundError(CogneeValidationError): def __init__( self, @@ -42,6 +42,7 @@ class DataNotFoundError(CogneeValidationError): ): super().__init__(message, name, status_code) + class DocumentSubgraphNotFoundError(CogneeValidationError): def __init__( self, diff --git a/cognee/exceptions/exceptions.py b/cognee/exceptions/exceptions.py index 9b6cef21d..d956d9cef 100644 --- a/cognee/exceptions/exceptions.py +++ b/cognee/exceptions/exceptions.py @@ -89,4 +89,3 @@ class CogneeTransientError(CogneeApiError): log_level="ERROR", ): super().__init__(message, name, status_code, log, log_level) - diff --git a/cognee/infrastructure/data/exceptions/__init__.py b/cognee/infrastructure/data/exceptions/__init__.py index 6735200ed..cc5f6044f 100644 --- a/cognee/infrastructure/data/exceptions/__init__.py +++ b/cognee/infrastructure/data/exceptions/__init__.py @@ -4,6 +4,4 @@ Custom exceptions for the Cognee API. This module defines a set of exceptions for handling various data errors """ -from .exceptions import ( - KeywordExtractionError -) +from .exceptions import KeywordExtractionError diff --git a/cognee/infrastructure/databases/exceptions/__init__.py b/cognee/infrastructure/databases/exceptions/__init__.py index 56deaac74..2969b1c59 100644 --- a/cognee/infrastructure/databases/exceptions/__init__.py +++ b/cognee/infrastructure/databases/exceptions/__init__.py @@ -10,5 +10,5 @@ from .exceptions import ( DatabaseNotCreatedError, EmbeddingException, MissingQueryParameterError, - MutuallyExclusiveQueryParametersError + MutuallyExclusiveQueryParametersError, ) diff --git a/cognee/infrastructure/databases/exceptions/exceptions.py b/cognee/infrastructure/databases/exceptions/exceptions.py index 6e1bb74f6..c240d3133 100644 --- a/cognee/infrastructure/databases/exceptions/exceptions.py +++ b/cognee/infrastructure/databases/exceptions/exceptions.py @@ -103,11 +103,13 @@ class EmbeddingException(CogneeConfigurationError): ): super().__init__(message, name, status_code) + class MissingQueryParameterError(CogneeValidationError): """ Raised when neither 'query_text' nor 'query_vector' is provided, and at least one is required to perform the operation. """ + def __init__( self, name: str = "MissingQueryParameterError", @@ -116,17 +118,17 @@ class MissingQueryParameterError(CogneeValidationError): message = "One of query_text or query_vector must be provided!" super().__init__(message, name, status_code) + class MutuallyExclusiveQueryParametersError(CogneeValidationError): """ Raised when both 'text' and 'embedding' are provided to the search function, but only one type of input is allowed at a time. """ + def __init__( self, name: str = "MutuallyExclusiveQueryParametersError", status_code: int = status.HTTP_400_BAD_REQUEST, ): - message = ( - "The search function accepts either text or embedding as input, but not both." - ) + message = "The search function accepts either text or embedding as input, but not both." super().__init__(message, name, status_code) diff --git a/cognee/infrastructure/llm/exceptions.py b/cognee/infrastructure/llm/exceptions.py index c8f5726fb..1d390a951 100644 --- a/cognee/infrastructure/llm/exceptions.py +++ b/cognee/infrastructure/llm/exceptions.py @@ -9,6 +9,7 @@ class LLMAPIKeyNotSetError(CogneeValidationError): """ Raised when the LLM API key is not set in the configuration. """ + def __init__(self, message: str = "LLM API key is not set."): super().__init__(message=message, name="LLMAPIKeyNotSetError") @@ -17,10 +18,12 @@ class UnsupportedLLMProviderError(CogneeValidationError): """ Raised when an unsupported LLM provider is specified in the configuration. """ + def __init__(self, provider: str): message = f"Unsupported LLM provider: {provider}" super().__init__(message=message, name="UnsupportedLLMProviderError") + class MissingSystemPromptPathError(CogneeValidationError): def __init__( self, diff --git a/cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/openai/adapter.py b/cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/openai/adapter.py index 4126b3e13..c3c215896 100644 --- a/cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/openai/adapter.py +++ b/cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/openai/adapter.py @@ -11,7 +11,10 @@ from cognee.infrastructure.llm.LLMGateway import LLMGateway from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.llm.llm_interface import ( LLMInterface, ) -from cognee.infrastructure.llm.exceptions import ContentPolicyFilterError, MissingSystemPromptPathError +from cognee.infrastructure.llm.exceptions import ( + ContentPolicyFilterError, + MissingSystemPromptPathError, +) from cognee.infrastructure.files.utils.open_data_file import open_data_file from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.llm.rate_limiter import ( rate_limit_async, diff --git a/cognee/modules/graph/cognee_graph/CogneeGraph.py b/cognee/modules/graph/cognee_graph/CogneeGraph.py index bdafaf238..ed867ae24 100644 --- a/cognee/modules/graph/cognee_graph/CogneeGraph.py +++ b/cognee/modules/graph/cognee_graph/CogneeGraph.py @@ -2,7 +2,11 @@ import time from cognee.shared.logging_utils import get_logger from typing import List, Dict, Union, Optional, Type -from cognee.modules.graph.exceptions import EntityNotFoundError, EntityAlreadyExistsError, InvalidDimensionsError +from cognee.modules.graph.exceptions import ( + EntityNotFoundError, + EntityAlreadyExistsError, + InvalidDimensionsError, +) from cognee.infrastructure.databases.graph.graph_db_interface import GraphDBInterface from cognee.modules.graph.cognee_graph.CogneeGraphElements import Node, Edge from cognee.modules.graph.cognee_graph.CogneeAbstractGraph import CogneeAbstractGraph diff --git a/cognee/modules/graph/cognee_graph/CogneeGraphElements.py b/cognee/modules/graph/cognee_graph/CogneeGraphElements.py index 2d8917d4a..0ca9c4fb9 100644 --- a/cognee/modules/graph/cognee_graph/CogneeGraphElements.py +++ b/cognee/modules/graph/cognee_graph/CogneeGraphElements.py @@ -2,6 +2,7 @@ import numpy as np from typing import List, Dict, Optional, Any, Union from cognee.modules.graph.exceptions import InvalidDimensionsError, DimensionOutOfRangeError + class Node: """ Represents a node in a graph. diff --git a/cognee/modules/graph/exceptions/exceptions.py b/cognee/modules/graph/exceptions/exceptions.py index 6fb2d400d..67f4200ff 100644 --- a/cognee/modules/graph/exceptions/exceptions.py +++ b/cognee/modules/graph/exceptions/exceptions.py @@ -25,6 +25,7 @@ class EntityAlreadyExistsError(CogneeValidationError): ): super().__init__(message, name, status_code) + class InvalidDimensionsError(CogneeValidationError): def __init__( self, @@ -34,6 +35,7 @@ class InvalidDimensionsError(CogneeValidationError): message = "Dimensions must be positive integers." super().__init__(message, name, status_code) + class DimensionOutOfRangeError(CogneeValidationError): def __init__( self, diff --git a/cognee/modules/search/exceptions/__init__.py b/cognee/modules/search/exceptions/__init__.py index ffb30f428..a019da249 100644 --- a/cognee/modules/search/exceptions/__init__.py +++ b/cognee/modules/search/exceptions/__init__.py @@ -4,6 +4,4 @@ Custom exceptions for the Cognee API. This module defines a set of exceptions for handling various data errors """ -from .exceptions import ( - UnsupportedSearchTypeError -) +from .exceptions import UnsupportedSearchTypeError diff --git a/cognee/tests/unit/modules/graph/cognee_graph_elements_test.py b/cognee/tests/unit/modules/graph/cognee_graph_elements_test.py index a8fb17268..37ba113b5 100644 --- a/cognee/tests/unit/modules/graph/cognee_graph_elements_test.py +++ b/cognee/tests/unit/modules/graph/cognee_graph_elements_test.py @@ -4,6 +4,7 @@ import pytest from cognee.modules.graph.cognee_graph.CogneeGraphElements import Edge, Node from cognee.modules.graph.exceptions import InvalidDimensionsError, DimensionOutOfRangeError + def test_node_initialization(): """Test that a Node is initialized correctly.""" node = Node("node1", {"attr1": "value1"}, dimension=2)