ruff formatting

This commit is contained in:
hajdul88 2025-08-13 15:15:39 +02:00
parent 68327d3ab9
commit da40365932
13 changed files with 30 additions and 18 deletions

View file

@ -9,5 +9,5 @@ from .exceptions import (
DocumentNotFoundError, DocumentNotFoundError,
DatasetNotFoundError, DatasetNotFoundError,
DataNotFoundError, DataNotFoundError,
DocumentSubgraphNotFoundError DocumentSubgraphNotFoundError,
) )

View file

@ -1,7 +1,4 @@
from cognee.exceptions import ( from cognee.exceptions import CogneeConfigurationError, CogneeValidationError
CogneeConfigurationError,
CogneeValidationError
)
from fastapi import status from fastapi import status
@ -15,6 +12,7 @@ class InvalidConfigAttributeError(CogneeConfigurationError):
message = f"'{attribute}' is not a valid attribute of the configuration." message = f"'{attribute}' is not a valid attribute of the configuration."
super().__init__(message, name, status_code) super().__init__(message, name, status_code)
class DocumentNotFoundError(CogneeValidationError): class DocumentNotFoundError(CogneeValidationError):
def __init__( def __init__(
self, self,
@ -24,6 +22,7 @@ class DocumentNotFoundError(CogneeValidationError):
): ):
super().__init__(message, name, status_code) super().__init__(message, name, status_code)
class DatasetNotFoundError(CogneeValidationError): class DatasetNotFoundError(CogneeValidationError):
def __init__( def __init__(
self, self,
@ -33,6 +32,7 @@ class DatasetNotFoundError(CogneeValidationError):
): ):
super().__init__(message, name, status_code) super().__init__(message, name, status_code)
class DataNotFoundError(CogneeValidationError): class DataNotFoundError(CogneeValidationError):
def __init__( def __init__(
self, self,
@ -42,6 +42,7 @@ class DataNotFoundError(CogneeValidationError):
): ):
super().__init__(message, name, status_code) super().__init__(message, name, status_code)
class DocumentSubgraphNotFoundError(CogneeValidationError): class DocumentSubgraphNotFoundError(CogneeValidationError):
def __init__( def __init__(
self, self,

View file

@ -89,4 +89,3 @@ class CogneeTransientError(CogneeApiError):
log_level="ERROR", log_level="ERROR",
): ):
super().__init__(message, name, status_code, log, log_level) super().__init__(message, name, status_code, log, log_level)

View file

@ -4,6 +4,4 @@ Custom exceptions for the Cognee API.
This module defines a set of exceptions for handling various data errors This module defines a set of exceptions for handling various data errors
""" """
from .exceptions import ( from .exceptions import KeywordExtractionError
KeywordExtractionError
)

View file

@ -10,5 +10,5 @@ from .exceptions import (
DatabaseNotCreatedError, DatabaseNotCreatedError,
EmbeddingException, EmbeddingException,
MissingQueryParameterError, MissingQueryParameterError,
MutuallyExclusiveQueryParametersError MutuallyExclusiveQueryParametersError,
) )

View file

@ -103,11 +103,13 @@ class EmbeddingException(CogneeConfigurationError):
): ):
super().__init__(message, name, status_code) super().__init__(message, name, status_code)
class MissingQueryParameterError(CogneeValidationError): class MissingQueryParameterError(CogneeValidationError):
""" """
Raised when neither 'query_text' nor 'query_vector' is provided, Raised when neither 'query_text' nor 'query_vector' is provided,
and at least one is required to perform the operation. and at least one is required to perform the operation.
""" """
def __init__( def __init__(
self, self,
name: str = "MissingQueryParameterError", name: str = "MissingQueryParameterError",
@ -116,17 +118,17 @@ class MissingQueryParameterError(CogneeValidationError):
message = "One of query_text or query_vector must be provided!" message = "One of query_text or query_vector must be provided!"
super().__init__(message, name, status_code) super().__init__(message, name, status_code)
class MutuallyExclusiveQueryParametersError(CogneeValidationError): class MutuallyExclusiveQueryParametersError(CogneeValidationError):
""" """
Raised when both 'text' and 'embedding' are provided to the search function, Raised when both 'text' and 'embedding' are provided to the search function,
but only one type of input is allowed at a time. but only one type of input is allowed at a time.
""" """
def __init__( def __init__(
self, self,
name: str = "MutuallyExclusiveQueryParametersError", name: str = "MutuallyExclusiveQueryParametersError",
status_code: int = status.HTTP_400_BAD_REQUEST, status_code: int = status.HTTP_400_BAD_REQUEST,
): ):
message = ( message = "The search function accepts either text or embedding as input, but not both."
"The search function accepts either text or embedding as input, but not both."
)
super().__init__(message, name, status_code) super().__init__(message, name, status_code)

View file

@ -9,6 +9,7 @@ class LLMAPIKeyNotSetError(CogneeValidationError):
""" """
Raised when the LLM API key is not set in the configuration. Raised when the LLM API key is not set in the configuration.
""" """
def __init__(self, message: str = "LLM API key is not set."): def __init__(self, message: str = "LLM API key is not set."):
super().__init__(message=message, name="LLMAPIKeyNotSetError") super().__init__(message=message, name="LLMAPIKeyNotSetError")
@ -17,10 +18,12 @@ class UnsupportedLLMProviderError(CogneeValidationError):
""" """
Raised when an unsupported LLM provider is specified in the configuration. Raised when an unsupported LLM provider is specified in the configuration.
""" """
def __init__(self, provider: str): def __init__(self, provider: str):
message = f"Unsupported LLM provider: {provider}" message = f"Unsupported LLM provider: {provider}"
super().__init__(message=message, name="UnsupportedLLMProviderError") super().__init__(message=message, name="UnsupportedLLMProviderError")
class MissingSystemPromptPathError(CogneeValidationError): class MissingSystemPromptPathError(CogneeValidationError):
def __init__( def __init__(
self, self,

View file

@ -11,7 +11,10 @@ from cognee.infrastructure.llm.LLMGateway import LLMGateway
from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.llm.llm_interface import ( from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.llm.llm_interface import (
LLMInterface, 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.files.utils.open_data_file import open_data_file
from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.llm.rate_limiter import ( from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.llm.rate_limiter import (
rate_limit_async, rate_limit_async,

View file

@ -2,7 +2,11 @@ import time
from cognee.shared.logging_utils import get_logger from cognee.shared.logging_utils import get_logger
from typing import List, Dict, Union, Optional, Type 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.infrastructure.databases.graph.graph_db_interface import GraphDBInterface
from cognee.modules.graph.cognee_graph.CogneeGraphElements import Node, Edge from cognee.modules.graph.cognee_graph.CogneeGraphElements import Node, Edge
from cognee.modules.graph.cognee_graph.CogneeAbstractGraph import CogneeAbstractGraph from cognee.modules.graph.cognee_graph.CogneeAbstractGraph import CogneeAbstractGraph

View file

@ -2,6 +2,7 @@ import numpy as np
from typing import List, Dict, Optional, Any, Union from typing import List, Dict, Optional, Any, Union
from cognee.modules.graph.exceptions import InvalidDimensionsError, DimensionOutOfRangeError from cognee.modules.graph.exceptions import InvalidDimensionsError, DimensionOutOfRangeError
class Node: class Node:
""" """
Represents a node in a graph. Represents a node in a graph.

View file

@ -25,6 +25,7 @@ class EntityAlreadyExistsError(CogneeValidationError):
): ):
super().__init__(message, name, status_code) super().__init__(message, name, status_code)
class InvalidDimensionsError(CogneeValidationError): class InvalidDimensionsError(CogneeValidationError):
def __init__( def __init__(
self, self,
@ -34,6 +35,7 @@ class InvalidDimensionsError(CogneeValidationError):
message = "Dimensions must be positive integers." message = "Dimensions must be positive integers."
super().__init__(message, name, status_code) super().__init__(message, name, status_code)
class DimensionOutOfRangeError(CogneeValidationError): class DimensionOutOfRangeError(CogneeValidationError):
def __init__( def __init__(
self, self,

View file

@ -4,6 +4,4 @@ Custom exceptions for the Cognee API.
This module defines a set of exceptions for handling various data errors This module defines a set of exceptions for handling various data errors
""" """
from .exceptions import ( from .exceptions import UnsupportedSearchTypeError
UnsupportedSearchTypeError
)

View file

@ -4,6 +4,7 @@ import pytest
from cognee.modules.graph.cognee_graph.CogneeGraphElements import Edge, Node from cognee.modules.graph.cognee_graph.CogneeGraphElements import Edge, Node
from cognee.modules.graph.exceptions import InvalidDimensionsError, DimensionOutOfRangeError from cognee.modules.graph.exceptions import InvalidDimensionsError, DimensionOutOfRangeError
def test_node_initialization(): def test_node_initialization():
"""Test that a Node is initialized correctly.""" """Test that a Node is initialized correctly."""
node = Node("node1", {"attr1": "value1"}, dimension=2) node = Node("node1", {"attr1": "value1"}, dimension=2)