Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'upstream/main'
  • Loading branch information
almondbuttertoast committed Apr 22, 2025
commit 085b2010e7c2487fa840d24d619357d26ec7698e
20 changes: 16 additions & 4 deletions cognee/api/v1/add/routers/get_add_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def get_add_router() -> APIRouter:
async def add(
file: UploadFile = UploadFile(None),
url: str = Form(None),
datasetId: str = Form(...),
datasetId: Optional[UUID] = Form(default=None),
datasetName: Optional[str] = Form(default=None),
user: User = Depends(get_authenticated_user),
):
"""
Expand All @@ -31,6 +32,17 @@ async def add(
- url: a URL to fetch data from (supports GitHub clone or direct file download)
"""
from cognee.api.v1.add import add as cognee_add

if not datasetId and not datasetName:
raise ValueError("Either datasetId or datasetName must be provided.")

if datasetId and not datasetName:
dataset = await get_dataset(user_id=user.id, dataset_id=datasetId)
try:
datasetName = dataset.name
except IndexError:
raise ValueError("No dataset found with the provided datasetName.")

try:
logger.info(f"Received data for datasetId={datasetId}")
if file and file.filename:
Expand All @@ -40,15 +52,15 @@ async def add(
logger.info(f"Passing uploaded file as text to cognee_add")
return await cognee_add(
text,
datasetId,
datasetName,
user=user
)
except Exception as e:
logger.info(f"Could not decode file as text, falling back to binary. Error: {e}")
file.file.seek(0)
return await cognee_add(
file.file,
datasetId,
datasetName,
user=user
)
elif url:
Expand All @@ -72,7 +84,7 @@ async def add(
logger.info(f"Fetched content from URL: {response.text}")
return await cognee_add(
response.text,
datasetId,
datasetName,
user=user
)
else:
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.