feat: adds input checks for add datapoints and summarization tasks
This commit is contained in:
parent
9f965c44b4
commit
63d071f0d8
6 changed files with 62 additions and 1 deletions
|
|
@ -5,9 +5,18 @@ from cognee.infrastructure.databases.graph import get_graph_engine
|
|||
from cognee.modules.graph.utils import deduplicate_nodes_and_edges, get_graph_from_model
|
||||
from .index_data_points import index_data_points
|
||||
from .index_graph_edges import index_graph_edges
|
||||
from cognee.tasks.storage.exceptions import (
|
||||
InvalidDataPointsInAddDataPointsError,
|
||||
)
|
||||
|
||||
|
||||
async def add_data_points(data_points: List[DataPoint]) -> List[DataPoint]:
|
||||
|
||||
if not isinstance(data_points, list):
|
||||
raise InvalidDataPointsInAddDataPointsError("data_points must be a list.")
|
||||
if not all(isinstance(dp, DataPoint) for dp in data_points):
|
||||
raise InvalidDataPointsInAddDataPointsError("data_points: each item must be a DataPoint.")
|
||||
|
||||
nodes = []
|
||||
edges = []
|
||||
|
||||
|
|
|
|||
9
cognee/tasks/storage/exceptions/__init__.py
Normal file
9
cognee/tasks/storage/exceptions/__init__.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
"""
|
||||
Custom exceptions for the Cognee API.
|
||||
|
||||
This module defines a set of exceptions for handling various data errors
|
||||
"""
|
||||
|
||||
from .exceptions import (
|
||||
InvalidDataPointsInAddDataPointsError,
|
||||
)
|
||||
13
cognee/tasks/storage/exceptions/exceptions.py
Normal file
13
cognee/tasks/storage/exceptions/exceptions.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
from cognee.exceptions import (
|
||||
CogneeValidationError,
|
||||
)
|
||||
from fastapi import status
|
||||
|
||||
|
||||
class InvalidDataPointsInAddDataPointsError(CogneeValidationError):
|
||||
def __init__(self, detail: str):
|
||||
super().__init__(
|
||||
message=f"Invalid data_points: {detail}",
|
||||
name="InvalidDataPointsInAddDataPointsError",
|
||||
status_code=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
9
cognee/tasks/summarization/exceptions/__init__.py
Normal file
9
cognee/tasks/summarization/exceptions/__init__.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
"""
|
||||
Custom exceptions for the Cognee API.
|
||||
|
||||
This module defines a set of exceptions for handling various data errors
|
||||
"""
|
||||
|
||||
from .exceptions import (
|
||||
InvalidSummaryInputsError,
|
||||
)
|
||||
13
cognee/tasks/summarization/exceptions/exceptions.py
Normal file
13
cognee/tasks/summarization/exceptions/exceptions.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
from cognee.exceptions import (
|
||||
CogneeValidationError,
|
||||
CogneeConfigurationError,
|
||||
)
|
||||
from fastapi import status
|
||||
|
||||
|
||||
class InvalidSummaryInputsError(CogneeValidationError):
|
||||
def __init__(self, detail: str):
|
||||
super().__init__(
|
||||
message=f"Invalid summarize_text inputs: {detail}",
|
||||
name="InvalidSummaryInputsError",
|
||||
status_code=status.HTTP_400_BAD_REQUEST)
|
||||
|
|
@ -3,10 +3,11 @@ from typing import Type
|
|||
from uuid import uuid5
|
||||
from pydantic import BaseModel
|
||||
|
||||
from cognee.tasks.summarization.exceptions import InvalidSummaryInputsError
|
||||
from cognee.modules.chunking.models.DocumentChunk import DocumentChunk
|
||||
from cognee.infrastructure.llm.LLMGateway import LLMGateway
|
||||
from cognee.modules.cognify.config import get_cognify_config
|
||||
from .models import TextSummary
|
||||
from cognee.tasks.summarization.models import TextSummary
|
||||
|
||||
|
||||
async def summarize_text(
|
||||
|
|
@ -35,6 +36,13 @@ async def summarize_text(
|
|||
A list of TextSummary objects, each containing the summary of a corresponding
|
||||
DocumentChunk.
|
||||
"""
|
||||
|
||||
if not isinstance(data_chunks, list):
|
||||
raise InvalidSummaryInputsError("data_chunks must be a list.")
|
||||
if not all(hasattr(c, "text") for c in data_chunks):
|
||||
raise InvalidSummaryInputsError("each DocumentChunk must have a 'text' attribute.")
|
||||
|
||||
|
||||
if len(data_chunks) == 0:
|
||||
return data_chunks
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue