File tree Expand file tree Collapse file tree 3 files changed +31
-6
lines changed Expand file tree Collapse file tree 3 files changed +31
-6
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,8 @@ def setup_logger(name: str) -> logging.Logger:
3636
3737URL = Annotated [AnyUrl , AfterValidator (str )]
3838
39+ UPLOAD_DIR = "/app/uploads"
40+
3941# Custom StrEnum is more handy than using integers that represent logging levels
4042class LoggingLevels (StrEnum ):
4143 DEBUG = "DEBUG"
@@ -44,8 +46,6 @@ class LoggingLevels(StrEnum):
4446 ERROR = "ERROR"
4547 CRITICAL = "CRITICAL"
4648
47-
48-
4949class Settings (BaseSettings ):
5050 model_config = SettingsConfigDict (
5151 env_file = (".env" ), env_nested_delimiter = "__" , extra = "ignore"
Original file line number Diff line number Diff line change 1+ import os
12from typing import List , Dict , Any
2- from pydantic import BaseModel
3+ from pydantic import BaseModel , field_validator
4+ from src .entity_graph_api .config import UPLOAD_DIR
35
46class LoadTableRequest (BaseModel ):
57 config : Dict [str , Any ] | str
68 filename : str
79 table_name : str
810 instance_type : str
911
12+ @field_validator ('config' )
13+ @classmethod
14+ def config_must_have_filename (cls , v ):
15+ if isinstance (v , dict ):
16+ filename = v .get ("filename" )
17+ if not filename :
18+ raise ValueError ('config dictionary must contain a "filename" field' )
19+ full_path = os .path .join (UPLOAD_DIR , filename )
20+ if not os .path .exists (full_path ):
21+ raise ValueError (f'File not found: { full_path } ' )
22+ v ["filename" ] = full_path
23+ return v
24+ if isinstance (v , str ):
25+ full_path = os .path .join (UPLOAD_DIR , v )
26+ if not os .path .exists (full_path ):
27+ raise ValueError (f'File not found: { full_path } ' )
28+ return full_path
29+ return v
30+
31+ class LoadTableRequestWithString (BaseModel ):
32+ config : str
33+ filename : str
34+ table_name : str
35+ instance_type : str
36+
1037class ExtractEntitiesRequest (BaseModel ):
1138 steps : Dict [str , List [Any ]]
Original file line number Diff line number Diff line change 11import os
2+ from src .entity_graph_api .config import UPLOAD_DIR
23from fastapi import APIRouter , UploadFile , File , HTTPException
34from src .entity_graph_api .models .entity_graph import LoadTableRequest , ExtractEntitiesRequest
45from entity_graph .graph_extractor .entities_graph_extractor import EntitiesGraphExtractor
56
67extractor = EntitiesGraphExtractor ()
78entities = extractor .entities_graph_manager .entities
89
9- UPLOAD_DIR = "/app/uploads"
10-
1110os .makedirs (UPLOAD_DIR , exist_ok = True )
1211
1312router = APIRouter (
@@ -47,7 +46,6 @@ async def load_table(request: LoadTableRequest):
4746 except Exception as e :
4847 raise HTTPException (status_code = 500 , detail = f"Failed to load table: { e } " )
4948
50-
5149@router .post ("/extract-entities" )
5250async def extract_entities (request : ExtractEntitiesRequest ):
5351 """Extract entities and build the graph based on the provided steps."""
You can’t perform that action at this time.
0 commit comments