cognee/cognee/modules/ingestion/classify.py
James edea54c5c3
fix: convert file path to str (#693)
## Description

fix int unable find method .split, not sure why its a int

## DCO Affirmation

I affirm that all code in every commit of this pull request conforms to
the terms of the Topoteretes Developer Certificate of Origin.
2025-04-02 12:35:19 +02:00

18 lines
653 B
Python

from io import BufferedReader
from typing import Union, BinaryIO
from .data_types import TextData, BinaryData
from tempfile import SpooledTemporaryFile
from cognee.modules.ingestion.exceptions import IngestionError
def classify(data: Union[str, BinaryIO], filename: str = None):
if isinstance(data, str):
return TextData(data)
if isinstance(data, BufferedReader) or isinstance(data, SpooledTemporaryFile):
return BinaryData(data, str(data.name).split("/")[-1] if data.name else filename)
raise IngestionError(
message=f"Type of data sent to classify(data: Union[str, BinaryIO) not supported: {type(data)}"
)