1- from fastapi import FastAPI , File , UploadFile , Form , Request
1+ from fastapi import FastAPI , File , UploadFile , Form , Request , HTTPException
22from fastapi_health import health
33from fastapi .middleware .cors import CORSMiddleware
44from src .main import *
1919from src .neighbours import get_neighbour_nodes
2020import json
2121from typing import List
22- from starlette .middleware .sessions import SessionMiddleware
2322from google .oauth2 .credentials import Credentials
2423import os
2524from src .logger import CustomLogger
3332from starlette .types import ASGIApp , Receive , Scope , Send
3433from langchain_neo4j import Neo4jGraph
3534from src .entities .source_node import sourceNode
35+ from starlette .middleware .sessions import SessionMiddleware
36+ from starlette .responses import HTMLResponse , RedirectResponse ,JSONResponse
37+ from starlette .requests import Request
38+ import secrets
3639
3740logger = CustomLogger ()
3841CHUNK_DIR = os .path .join (os .path .dirname (__file__ ), "chunks" )
@@ -77,6 +80,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send):
7780 )
7881 await gzip_middleware (scope , receive , send )
7982app = FastAPI ()
83+
8084app .add_middleware (XContentTypeOptions )
8185app .add_middleware (XFrame , Option = {'X-Frame-Options' : 'DENY' })
8286app .add_middleware (CustomGZipMiddleware , minimum_size = 1000 , compresslevel = 5 ,paths = ["/sources_list" ,"/url/scan" ,"/extract" ,"/chat_bot" ,"/chunk_entities" ,"/get_neighbours" ,"/graph_query" ,"/schema" ,"/populate_graph_schema" ,"/get_unconnected_nodes_list" ,"/get_duplicate_nodes" ,"/fetch_chunktext" ])
@@ -86,14 +90,14 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send):
8690 allow_methods = ["*" ],
8791 allow_headers = ["*" ],
8892)
93+ app .add_middleware (SessionMiddleware , secret_key = os .urandom (24 ))
8994
9095is_gemini_enabled = os .environ .get ("GEMINI_ENABLED" , "False" ).lower () in ("true" , "1" , "yes" )
9196if is_gemini_enabled :
9297 add_routes (app ,ChatVertexAI (), path = "/vertexai" )
9398
9499app .add_api_route ("/health" , health ([healthy_condition , healthy ]))
95100
96- app .add_middleware (SessionMiddleware , secret_key = os .urandom (24 ))
97101
98102
99103@app .post ("/url/scan" )
@@ -346,14 +350,15 @@ async def post_processing(uri=Form(), userName=Form(), password=Form(), database
346350 await asyncio .to_thread (create_communities , uri , userName , password , database )
347351
348352 logging .info (f'created communities' )
349- graph = create_graph_database_connection (uri , userName , password , database )
350- graphDb_data_Access = graphDBdataAccess (graph )
351- document_name = ""
352- count_response = graphDb_data_Access .update_node_relationship_count (document_name )
353- if count_response :
354- count_response = [{"filename" : filename , ** counts } for filename , counts in count_response .items ()]
355- logging .info (f'Updated source node with community related counts' )
356-
353+
354+
355+ graph = create_graph_database_connection (uri , userName , password , database )
356+ graphDb_data_Access = graphDBdataAccess (graph )
357+ document_name = ""
358+ count_response = graphDb_data_Access .update_node_relationship_count (document_name )
359+ if count_response :
360+ count_response = [{"filename" : filename , ** counts } for filename , counts in count_response .items ()]
361+ logging .info (f'Updated source node with community related counts' )
357362
358363 end = time .time ()
359364 elapsed_time = end - start
@@ -502,12 +507,14 @@ async def connect(uri=Form(), userName=Form(), password=Form(), database=Form())
502507 graph = create_graph_database_connection (uri , userName , password , database )
503508 result = await asyncio .to_thread (connection_check_and_get_vector_dimensions , graph , database )
504509 gcs_file_cache = os .environ .get ('GCS_FILE_CACHE' )
510+ chunk_to_be_created = int (os .environ .get ('CHUNKS_TO_BE_CREATED' , '50' ))
505511 end = time .time ()
506512 elapsed_time = end - start
507513 json_obj = {'api_name' :'connect' ,'db_url' :uri , 'userName' :userName , 'database' :database , 'count' :1 , 'logging_time' : formatted_time (datetime .now (timezone .utc )), 'elapsed_api_time' :f'{ elapsed_time :.2f} ' }
508514 logger .log_struct (json_obj , "INFO" )
509515 result ['elapsed_api_time' ] = f'{ elapsed_time :.2f} '
510516 result ['gcs_file_cache' ] = gcs_file_cache
517+ result ['chunk_to_be_created' ]= chunk_to_be_created
511518 return create_api_response ('Success' ,data = result )
512519 except Exception as e :
513520 job_status = "Failed"
@@ -980,8 +987,8 @@ async def backend_connection_configuration():
980987 database = os .getenv ('NEO4J_DATABASE' )
981988 password = os .getenv ('NEO4J_PASSWORD' )
982989 gcs_file_cache = os .environ .get ('GCS_FILE_CACHE' )
990+ chunk_to_be_created = int (os .environ .get ('CHUNKS_TO_BE_CREATED' , '50' ))
983991 if all ([uri , username , database , password ]):
984- print (f'uri:{ uri } , usrName:{ username } , database :{ database } , password: { password } ' )
985992 graph = Neo4jGraph ()
986993 logging .info (f'login connection status of object: { graph } ' )
987994 if graph is not None :
@@ -995,6 +1002,7 @@ async def backend_connection_configuration():
9951002 result ["database" ] = database
9961003 result ["password" ] = encoded_password
9971004 result ['gcs_file_cache' ] = gcs_file_cache
1005+ result ['chunk_to_be_created' ]= chunk_to_be_created
9981006 end = time .time ()
9991007 elapsed_time = end - start
10001008 result ['api_name' ] = 'backend_connection_configuration'
0 commit comments