@@ -105,8 +105,8 @@ async def create_source_knowledge_graph_url(
105105 return create_api_response ('Failed' ,message = 'source_type is other than accepted source' )
106106
107107 message = f"Source Node created successfully for source type: { source_type } and source: { source } "
108- josn_obj = {'api_name' :'url_scan' ,'db_url' :uri ,'url_scanned_file' :lst_file_name , 'source_url' :source_url , 'wiki_query' :wiki_query , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
109- logger .log_struct (josn_obj )
108+ json_obj = {'api_name' :'url_scan' ,'db_url' :uri ,'url_scanned_file' :lst_file_name , 'source_url' :source_url , 'wiki_query' :wiki_query , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
109+ logger .log_struct (json_obj )
110110 return create_api_response ("Success" ,message = message ,success_count = success_count ,failed_count = failed_count ,file_name = lst_file_name )
111111 except Exception as e :
112112 error_message = str (e )
@@ -208,9 +208,9 @@ async def extract_knowledge_graph_from_file(
208208 else :
209209 logging .info (f'Deleted File Path: { merged_file_path } and Deleted File Name : { file_name } ' )
210210 delete_uploaded_local_file (merged_file_path ,file_name )
211- josn_obj = {'message' :message ,'error_message' :error_message , 'file_name' : file_name ,'status' :'Failed' ,'db_url' :uri ,'failed_count' :1 , 'source_type' : source_type , 'source_url' :source_url , 'wiki_query' :wiki_query , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
212- logger .log_struct (josn_obj )
213- logging .exception (f'File Failed in extraction: { josn_obj } ' )
211+ json_obj = {'message' :message ,'error_message' :error_message , 'file_name' : file_name ,'status' :'Failed' ,'db_url' :uri ,'failed_count' :1 , 'source_type' : source_type , 'source_url' :source_url , 'wiki_query' :wiki_query , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
212+ logger .log_struct (json_obj )
213+ logging .exception (f'File Failed in extraction: { json_obj } ' )
214214 return create_api_response ('Failed' , message = message + error_message [:100 ], error = error_message , file_name = file_name )
215215 finally :
216216 gc .collect ()
@@ -225,8 +225,8 @@ async def get_source_list(uri:str, userName:str, password:str, database:str=None
225225 if " " in uri :
226226 uri = uri .replace (" " ,"+" )
227227 result = await asyncio .to_thread (get_source_list_from_graph ,uri ,userName ,decoded_password ,database )
228- josn_obj = {'api_name' :'sources_list' ,'db_url' :uri , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
229- logger .log_struct (josn_obj )
228+ json_obj = {'api_name' :'sources_list' ,'db_url' :uri , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
229+ logger .log_struct (json_obj )
230230 return create_api_response ("Success" ,data = result )
231231 except Exception as e :
232232 job_status = "Failed"
@@ -243,19 +243,18 @@ async def post_processing(uri=Form(), userName=Form(), password=Form(), database
243243
244244 if "materialize_text_chunk_similarities" in tasks :
245245 await asyncio .to_thread (update_graph , graph )
246- josn_obj = {'api_name' : 'post_processing/materialize_text_chunk_similarities ' , 'db_url' : uri , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
247- logger .log_struct (josn_obj )
246+ json_obj = {'api_name' : 'post_processing/update_similarity_graph ' , 'db_url' : uri , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
247+ logger .log_struct (json_obj )
248248 logging .info (f'Updated KNN Graph' )
249- if "enable_hybrid_search_and_fulltext_search_in_bloom" in tasks :
250- await asyncio .to_thread (create_fulltext , uri = uri , username = userName , password = password , database = database ,type = "entities" )
251- await asyncio .to_thread (create_fulltext , uri = uri , username = userName , password = password , database = database ,type = "keyword" )
252- josn_obj = {'api_name' : 'post_processing/enable_hybrid_search_and_fulltext_search_in_bloom' , 'db_url' : uri , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
253- logger .log_struct (josn_obj )
249+ if "create_fulltext_index" in tasks :
250+ await asyncio .to_thread (create_fulltext , uri = uri , username = userName , password = password , database = database )
251+ json_obj = {'api_name' : 'post_processing/create_fulltext_index' , 'db_url' : uri , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
252+ logger .log_struct (json_obj )
254253 logging .info (f'Full Text index created' )
255254 if os .environ .get ('ENTITY_EMBEDDING' ,'False' ).upper ()== "TRUE" and "materialize_entity_similarities" in tasks :
256255 await asyncio .to_thread (create_entity_embedding , graph )
257- josn_obj = {'api_name' : 'post_processing/materialize_entity_similarities ' , 'db_url' : uri , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
258- logger .log_struct (josn_obj )
256+ json_obj = {'api_name' : 'post_processing/create_entity_embedding ' , 'db_url' : uri , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
257+ logger .log_struct (json_obj )
259258 logging .info (f'Entity Embeddings created' )
260259 return create_api_response ('Success' , message = 'All tasks completed successfully' )
261260
@@ -284,8 +283,8 @@ async def chat_bot(uri=Form(),model=Form(None),userName=Form(), password=Form(),
284283 logging .info (f"Total Response time is { total_call_time :.2f} seconds" )
285284 result ["info" ]["response_time" ] = round (total_call_time , 2 )
286285
287- josn_obj = {'api_name' :'chat_bot' ,'db_url' :uri ,'session_id' :session_id , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
288- logger .log_struct (josn_obj )
286+ json_obj = {'api_name' :'chat_bot' ,'db_url' :uri ,'session_id' :session_id , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
287+ logger .log_struct (json_obj )
289288 return create_api_response ('Success' ,data = result )
290289 except Exception as e :
291290 job_status = "Failed"
@@ -301,8 +300,8 @@ async def chunk_entities(uri=Form(),userName=Form(), password=Form(), chunk_ids=
301300 try :
302301 logging .info (f"URI: { uri } , Username: { userName } , chunk_ids: { chunk_ids } " )
303302 result = await asyncio .to_thread (get_entities_from_chunkids ,uri = uri , username = userName , password = password , chunk_ids = chunk_ids )
304- josn_obj = {'api_name' :'chunk_entities' ,'db_url' :uri , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
305- logger .log_struct (josn_obj )
303+ json_obj = {'api_name' :'chunk_entities' ,'db_url' :uri , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
304+ logger .log_struct (json_obj )
306305 return create_api_response ('Success' ,data = result )
307306 except Exception as e :
308307 job_status = "Failed"
@@ -329,8 +328,8 @@ async def graph_query(
329328 password = password ,
330329 document_names = document_names
331330 )
332- josn_obj = {'api_name' :'graph_query' ,'db_url' :uri ,'document_names' :document_names , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
333- logger .log_struct (josn_obj )
331+ json_obj = {'api_name' :'graph_query' ,'db_url' :uri ,'document_names' :document_names , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
332+ logger .log_struct (json_obj )
334333 return create_api_response ('Success' , data = result )
335334 except Exception as e :
336335 job_status = "Failed"
@@ -379,8 +378,8 @@ async def upload_large_file_into_chunks(file:UploadFile = File(...), chunkNumber
379378 try :
380379 graph = create_graph_database_connection (uri , userName , password , database )
381380 result = await asyncio .to_thread (upload_file , graph , model , file , chunkNumber , totalChunks , originalname , uri , CHUNK_DIR , MERGED_DIR )
382- josn_obj = {'api_name' :'upload' ,'db_url' :uri , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
383- logger .log_struct (josn_obj )
381+ json_obj = {'api_name' :'upload' ,'db_url' :uri , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
382+ logger .log_struct (json_obj )
384383 if int (chunkNumber ) == int (totalChunks ):
385384 return create_api_response ('Success' ,data = result , message = 'Source Node Created Successfully' )
386385 else :
@@ -401,8 +400,8 @@ async def get_structured_schema(uri=Form(), userName=Form(), password=Form(), da
401400 graph = create_graph_database_connection (uri , userName , password , database )
402401 result = await asyncio .to_thread (get_labels_and_relationtypes , graph )
403402 logging .info (f'Schema result from DB: { result } ' )
404- josn_obj = {'api_name' :'schema' ,'db_url' :uri , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
405- logger .log_struct (josn_obj )
403+ json_obj = {'api_name' :'schema' ,'db_url' :uri , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
404+ logger .log_struct (json_obj )
406405 return create_api_response ('Success' , data = result )
407406 except Exception as e :
408407 message = "Unable to get the labels and relationtypes from neo4j database"
@@ -468,10 +467,10 @@ async def delete_document_and_entities(uri=Form(),
468467 graph = create_graph_database_connection (uri , userName , password , database )
469468 graphDb_data_Access = graphDBdataAccess (graph )
470469 result , files_list_size = await asyncio .to_thread (graphDb_data_Access .delete_file_from_graph , filenames , source_types , deleteEntities , MERGED_DIR , uri )
471- # entities_count = result[0]['deletedEntities'] if 'deletedEntities' in result[0] else 0
472- message = f"Deleted { files_list_size } documents with entities from database"
473- josn_obj = {'api_name' :'delete_document_and_entities' ,'db_url' :uri , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
474- logger .log_struct (josn_obj )
470+ entities_count = result [0 ]['deletedEntities' ] if 'deletedEntities' in result [0 ] else 0
471+ message = f"Deleted { files_list_size } documents with { entities_count } entities from database"
472+ json_obj = {'api_name' :'delete_document_and_entities' ,'db_url' :uri , 'logging_time' : formatted_time (datetime .now (timezone .utc ))}
473+ logger .log_struct (json_obj )
475474 return create_api_response ('Success' ,message = message )
476475 except Exception as e :
477476 job_status = "Failed"
@@ -627,4 +626,4 @@ async def merge_duplicate_nodes(uri=Form(), userName=Form(), password=Form(), da
627626 gc .collect ()
628627
629628if __name__ == "__main__" :
630- uvicorn .run (app )
629+ uvicorn .run (app )
0 commit comments