@@ -49,17 +49,10 @@ async def create_source_knowledge_graph(
4949 Returns:
5050 'Source' Node creation in Neo4j database
5151 """
52- try :
53- result = await asyncio .to_thread (
54- create_source_node_graph_local_file , uri , userName , password , file , model
55- )
56- return result
57- except Exception as e :
58- job_status = "Failure"
59- error_message = str (e )
60- logging .exception (f"Exception Stack trace:{ e } " )
61- return create_api_response (job_status , error = error_message )
62-
52+ result = await asyncio .to_thread (
53+ create_source_node_graph_local_file , uri , userName , password , file , model
54+ )
55+ return result
6356
6457@app .post ("/url/scan" )
6558async def create_source_knowledge_graph_url (
@@ -105,68 +98,53 @@ async def extract_knowledge_graph_from_file(
10598 Returns:
10699 Nodes and Relations created in Neo4j databse for the pdf file
107100 """
108- try :
109- if file :
110- return await asyncio .to_thread (
111- extract_graph_from_file ,
112- uri ,
113- userName ,
114- password ,
115- model ,
116- file = file ,
117- source_url = None ,
118- wiki_query = wiki_query ,
119- max_sources = max_sources ,
120- )
121- elif source_url :
122- return await asyncio .to_thread (
123- extract_graph_from_file ,
124- uri ,
125- userName ,
126- password ,
127- model ,
128- source_url = source_url ,
129- aws_access_key_id = aws_access_key_id ,
130- aws_secret_access_key = aws_secret_access_key ,
131- wiki_query = wiki_query ,
132- max_sources = max_sources ,
133- )
134- else :
135- return {"job_status" : "Failure" , "error" : "No file found" }
136- except Exception as e :
137- job_status = "Failure"
138- error_message = str (e )
139- logging .exception (f"Exception Stack trace:{ e } " )
140- return create_api_response (job_status , error = error_message )
141-
101+
102+ if file :
103+ return await asyncio .to_thread (
104+ extract_graph_from_file ,
105+ uri ,
106+ userName ,
107+ password ,
108+ model ,
109+ file = file ,
110+ source_url = None ,
111+ wiki_query = wiki_query ,
112+ max_sources = max_sources ,
113+ )
114+ elif source_url :
115+ return await asyncio .to_thread (
116+ extract_graph_from_file ,
117+ uri ,
118+ userName ,
119+ password ,
120+ model ,
121+ source_url = source_url ,
122+ aws_access_key_id = aws_access_key_id ,
123+ aws_secret_access_key = aws_secret_access_key ,
124+ wiki_query = wiki_query ,
125+ max_sources = max_sources ,
126+ )
127+ else :
128+ return {"job_status" : "Failure" , "error" : "No file found" }
129+
142130
143131@app .get ("/sources_list" )
144132async def get_source_list ():
145133 """
146134 Calls 'get_source_list_from_graph' which returns list of sources which alreday exist in databse
147135 """
148- try :
149- result = await asyncio .to_thread (get_source_list_from_graph )
150- return result
151- except Exception as e :
152- job_status = "Failure"
153- error_message = str (e )
154- logging .exception (f"Exception Stack trace:{ e } " )
155- return create_api_response (job_status , error = error_message )
136+ result = await asyncio .to_thread (get_source_list_from_graph )
137+ return result
156138
157139@app .post ("/update_similarity_graph" )
158140async def update_similarity_graph ():
159141 """
160142 Calls 'update_graph' which post the query to update the similiar nodes in the graph
161143 """
162- try :
163- result = await asyncio .to_thread (update_graph )
164- return result
165- except Exception as e :
166- job_status = "Failure"
167- error_message = str (e )
168- logging .exception (f"Exception Stack trace:{ e } " )
169- return create_api_response (job_status , error = error_message )
144+
145+ result = await asyncio .to_thread (update_graph )
146+ return result
147+
170148
171149
172150if __name__ == "__main__" :
0 commit comments