-
Notifications
You must be signed in to change notification settings - Fork 1k
Cog 334 structure routing #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f09c28a
f8f2746
4fd4651
02d6750
fc3eb9b
eca1b9f
de1ba5c
d5a220e
801efeb
7425409
bce6540
ddf4952
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .get_add_router import get_add_router |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| from fastapi import Form, UploadFile, Depends | ||
| from fastapi.responses import JSONResponse | ||
| from fastapi import APIRouter | ||
| from typing import List | ||
| import aiohttp | ||
| import subprocess | ||
| import logging | ||
| import os | ||
| from cognee.modules.users.models import User | ||
| from cognee.modules.users.methods import get_authenticated_user | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| def get_add_router() -> APIRouter: | ||
| router = APIRouter() | ||
|
|
||
| @router.post("/", response_model=None) | ||
| async def add( | ||
| data: List[UploadFile], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect Type Annotation for 'data' Parameter The parameter Update the type annotation to accept both - from typing import List
+ from typing import List, Union
...
- data: List[UploadFile],
+ data: Union[List[UploadFile], str],
|
||
| datasetId: str = Form(...), | ||
| user: User = Depends(get_authenticated_user), | ||
| ): | ||
| """ This endpoint is responsible for adding data to the graph.""" | ||
| from cognee.api.v1.add import add as cognee_add | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Import Statement Inside Function Scope Importing modules inside functions is generally discouraged unless necessary, as it can lead to repeated imports and affect performance. Move the import statement to the module level: - from cognee.api.v1.add import add as cognee_add
+ from cognee.api.v1.add import add as cognee_add
...
def get_add_router():
|
||
| try: | ||
| if isinstance(data, str) and data.startswith("http"): | ||
| if "github" in data: | ||
|
Comment on lines
+26
to
+27
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type Checking Error: Inconsistent Handling of 'data' The condition Ensure that |
||
| # Perform git clone if the URL is from GitHub | ||
| repo_name = data.split("/")[-1].replace(".git", "") | ||
| subprocess.run(["git", "clone", data, f".data/{repo_name}"], check=True) | ||
| await cognee_add( | ||
| "data://.data/", | ||
| f"{repo_name}", | ||
| ) | ||
| else: | ||
| # Fetch and store the data from other types of URL using curl | ||
| async with aiohttp.ClientSession() as session: | ||
| async with session.get(data) as resp: | ||
| if resp.status == 200: | ||
| file_data = await resp.read() | ||
| filename = os.path.basename(data) | ||
| with open(f".data/{filename}", "wb") as f: | ||
| f.write(file_data) | ||
| await cognee_add( | ||
| "data://.data/", | ||
| f"{data.split('/')[-1]}", | ||
| ) | ||
| else: | ||
| await cognee_add( | ||
| data, | ||
| datasetId, | ||
| user=user, | ||
| ) | ||
| except Exception as error: | ||
| return JSONResponse( | ||
| status_code=409, | ||
| content={"error": str(error)} | ||
| ) | ||
|
|
||
| return router | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .get_cognify_router import get_cognify_router |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move module-level imports to the top of the file
According to PEP 8 guidelines, all module-level imports should be placed at the top of the file, after any module comments and docstrings, and before module-level variables and constants. This enhances code readability and maintainability.
Apply this diff to fix the issue:
🧰 Tools
🪛 Ruff