refactor: Remove changes to cognify router
Remove changes to cognify router Refactor COG-650
This commit is contained in:
parent
856f228981
commit
f660127d2d
1 changed files with 4 additions and 22 deletions
|
|
@ -1,24 +1,15 @@
|
||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
from typing import List, Optional, Any
|
from typing import List, Optional
|
||||||
from pydantic import BaseModel, create_model
|
from pydantic import BaseModel
|
||||||
from cognee.modules.users.models import User
|
from cognee.modules.users.models import User
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
from cognee.modules.users.methods import get_authenticated_user
|
from cognee.modules.users.methods import get_authenticated_user
|
||||||
from fastapi import Depends
|
from fastapi import Depends
|
||||||
|
|
||||||
from cognee.shared.data_models import KnowledgeGraph
|
from cognee.shared.data_models import KnowledgeGraph
|
||||||
|
|
||||||
|
|
||||||
class CognifyPayloadDTO(BaseModel):
|
class CognifyPayloadDTO(BaseModel):
|
||||||
datasets: List[str]
|
datasets: List[str]
|
||||||
graph_model: Optional[Any] = None
|
graph_model: Optional[BaseModel] = KnowledgeGraph
|
||||||
|
|
||||||
|
|
||||||
def json_to_pydantic_model(name: str, json_schema: dict) -> BaseModel:
|
|
||||||
"""
|
|
||||||
Create a Pydantic model on the fly from JSON.
|
|
||||||
"""
|
|
||||||
return create_model(name, **{k: (type(v), ...) for k, v in json_schema.items()})
|
|
||||||
|
|
||||||
def get_cognify_router() -> APIRouter:
|
def get_cognify_router() -> APIRouter:
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
@ -28,16 +19,7 @@ def get_cognify_router() -> APIRouter:
|
||||||
""" This endpoint is responsible for the cognitive processing of the content."""
|
""" This endpoint is responsible for the cognitive processing of the content."""
|
||||||
from cognee.api.v1.cognify.cognify_v2 import cognify as cognee_cognify
|
from cognee.api.v1.cognify.cognify_v2 import cognify as cognee_cognify
|
||||||
try:
|
try:
|
||||||
# Dynamic conversion of `graph_model` to Pydantic
|
await cognee_cognify(payload.datasets, user, payload.graph_model)
|
||||||
if payload.graph_model:
|
|
||||||
graph_model_schema = payload.graph_model
|
|
||||||
GraphModelDynamic = json_to_pydantic_model("GraphModelDynamic", graph_model_schema)
|
|
||||||
graph_model_instance = GraphModelDynamic(**graph_model_schema)
|
|
||||||
print(graph_model_instance)
|
|
||||||
else:
|
|
||||||
graph_model_instance = KnowledgeGraph
|
|
||||||
|
|
||||||
await cognee_cognify(payload.datasets, user, graph_model_instance)
|
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
status_code=409,
|
status_code=409,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue