5
5
import pandas as pd
6
6
from datetime import datetime as dt
7
7
from dotenv import load_dotenv
8
-
9
8
from score import *
10
9
from src .main import *
11
10
from src .QA_integration_new import QA_RAG
26
25
graph = create_graph_database_connection (URI , USERNAME , PASSWORD , DATABASE )
27
26
28
27
def create_source_node_local (graph , model , file_name ):
29
- """Creates a source node for a local file."""
30
- source_node = sourceNode ()
31
- source_node .file_name = file_name
32
- source_node .file_type = 'pdf'
33
- source_node .file_size = '1087'
34
- source_node .file_source = 'local file'
35
- source_node .model = model
36
- source_node .created_at = dt .now ()
37
- graphDB_data_Access = graphDBdataAccess (graph )
38
- graphDB_data_Access .create_source_node (source_node )
39
- return source_node
28
+ """Creates a source node for a local file."""
29
+ source_node = sourceNode ()
30
+ source_node .file_name = file_name
31
+ source_node .file_type = 'pdf'
32
+ source_node .file_size = '1087'
33
+ source_node .file_source = 'local file'
34
+ source_node .model = model
35
+ source_node .created_at = dt .now ()
36
+ graphDB_data_Access = graphDBdataAccess (graph )
37
+ graphDB_data_Access .create_source_node (source_node )
38
+ return source_node
40
39
41
40
def test_graph_from_file_local (model_name ):
42
- """Test graph creation from a local file."""
43
- file_name = 'About Amazon.pdf'
44
- shutil .copyfile ('/workspaces/llm-graph-builder/backend/files/About Amazon.pdf' ,
45
- os .path .join (MERGED_DIR , file_name ))
46
-
47
- create_source_node_local (graph , model_name , file_name )
48
- merged_file_path = os .path .join (MERGED_DIR , file_name )
49
-
50
- local_file_result = extract_graph_from_file_local_file (
51
- URI , USERNAME , PASSWORD , DATABASE , model_name , merged_file_path , file_name , '' , ''
52
- )
53
- logging .info ("Local file processing complete" )
54
- print (local_file_result )
55
-
56
- try :
57
- assert local_file_result ['status' ] == 'Completed'
58
- assert local_file_result ['nodeCount' ] > 0
59
- assert local_file_result ['relationshipCount' ] > 0
60
- print ("Success" )
61
- except AssertionError as e :
62
- print ("Fail: " , e )
63
-
64
- return local_file_result
41
+ """Test graph creation from a local file."""
42
+ file_name = 'About Amazon.pdf'
43
+ shutil .copyfile ('/workspaces/llm-graph-builder/backend/files/About Amazon.pdf' ,
44
+ os .path .join (MERGED_DIR , file_name ))
45
+
46
+ create_source_node_local (graph , model_name , file_name )
47
+ merged_file_path = os .path .join (MERGED_DIR , file_name )
48
+
49
+ local_file_result = extract_graph_from_file_local_file (
50
+ URI , USERNAME , PASSWORD , DATABASE , model_name , merged_file_path , file_name , '' , '' , None
51
+ )
52
+ logging .info ("Local file processing complete" )
53
+ print (local_file_result )
54
+
55
+ try :
56
+ assert local_file_result ['status' ] == 'Completed'
57
+ assert local_file_result ['nodeCount' ] > 0
58
+ assert local_file_result ['relationshipCount' ] > 0
59
+ print ("Success" )
60
+ except AssertionError as e :
61
+ print ("Fail: " , e )
62
+
63
+ return local_file_result
65
64
66
65
def test_graph_from_wikipedia (model_name ):
67
- """Test graph creation from a Wikipedia page."""
68
- wiki_query = 'https://en.wikipedia.org/wiki/Google_DeepMind'
69
- source_type = 'Wikipedia'
70
- file_name = "Google_DeepMind"
71
- create_source_node_graph_url_wikipedia (graph , model_name , wiki_query , source_type )
72
-
73
- wiki_result = extract_graph_from_file_Wikipedia (URI , USERNAME , PASSWORD , DATABASE , model_name , file_name , 1 , 'en' , '' , '' )
74
- logging .info ("Wikipedia test done" )
75
- print (wiki_result )
76
-
77
- try :
78
- assert wiki_result ['status' ] == 'Completed'
79
- assert wiki_result ['nodeCount' ] > 0
80
- assert wiki_result ['relationshipCount' ] > 0
81
- print ("Success" )
82
- except AssertionError as e :
83
- print ("Fail: " , e )
84
-
85
- return wiki_result
66
+ # try:
67
+ """Test graph creation from a Wikipedia page."""
68
+ wiki_query = 'https://en.wikipedia.org/wiki/Ram_Mandir'
69
+ source_type = 'Wikipedia'
70
+ file_name = "Ram_Mandir"
71
+ create_source_node_graph_url_wikipedia (graph , model_name , wiki_query , source_type )
72
+
73
+ wiki_result = extract_graph_from_file_Wikipedia (URI , USERNAME , PASSWORD , DATABASE , model_name , file_name , 'en' ,file_name , '' , '' ,None )
74
+ logging .info ("Wikipedia test done" )
75
+ print (wiki_result )
76
+ try :
77
+ assert wiki_result ['status' ] == 'Completed'
78
+ assert wiki_result ['nodeCount' ] > 0
79
+ assert wiki_result ['relationshipCount' ] > 0
80
+ print ("Success" )
81
+ except AssertionError as e :
82
+ print ("Fail: " , e )
83
+
84
+ return wiki_result
85
+ # except Exception as ex:
86
+ # print(ex)
86
87
87
88
def test_graph_website (model_name ):
88
- """Test graph creation from a Website page."""
89
- #graph, model, source_url, source_type
90
- source_url = 'https://www.amazon.com/'
91
- source_type = 'web-url'
92
- create_source_node_graph_web_url ( graph , model_name , source_url , source_type )
93
-
94
- weburl_result = extract_graph_from_web_page ( URI , USERNAME , PASSWORD , DATABASE , model_name , source_url , '' , '' )
95
- logging . info ( "WebUrl test done" )
96
- print ( weburl_result )
97
-
98
- try :
99
- assert weburl_result [ 'status' ] == 'Completed'
100
- assert weburl_result ['nodeCount ' ] > 0
101
- assert weburl_result ['relationshipCount ' ] > 0
102
- print ( "Success" )
103
- except AssertionError as e :
104
- print ( "Fail: " , e )
105
- return weburl_result
106
-
89
+ """Test graph creation from a Website page."""
90
+ #graph, model, source_url, source_type
91
+ source_url = 'https://www.amazon.com/'
92
+ source_type = 'web-url'
93
+ file_name = []
94
+ create_source_node_graph_web_url ( graph , model_name , source_url , source_type )
95
+
96
+ weburl_result = extract_graph_from_web_page ( URI , USERNAME , PASSWORD , DATABASE , model_name , source_url , file_name , '' , '' , None )
97
+ logging . info ( "WebUrl test done" )
98
+ print ( weburl_result )
99
+
100
+ try :
101
+ assert weburl_result ['status ' ] == 'Completed'
102
+ assert weburl_result ['nodeCount ' ] > 0
103
+ assert weburl_result [ 'relationshipCount' ] > 0
104
+ print ( "Success" )
105
+ except AssertionError as e :
106
+ print ( "Fail: " , e )
107
+ return weburl_result
107
108
108
109
def test_graph_from_youtube_video (model_name ):
109
- """Test graph creation from a YouTube video."""
110
- source_url = 'https://www.youtube.com/watch?v=T-qy-zPWgqA'
111
- source_type = 'youtube'
112
-
113
- create_source_node_graph_url_youtube (graph , model_name , source_url , source_type )
114
- youtube_result = extract_graph_from_file_youtube (
115
- URI , USERNAME , PASSWORD , DATABASE , model_name , source_url , '' , ''
116
- )
117
- logging .info ("YouTube Video test done" )
118
- print (youtube_result )
119
-
120
- try :
121
- assert youtube_result ['status' ] == 'Completed'
122
- assert youtube_result ['nodeCount' ] > 1
123
- assert youtube_result ['relationshipCount' ] > 1
124
- print ("Success" )
125
- except AssertionError as e :
126
- print ("Failed: " , e )
127
-
128
- return youtube_result
110
+ """Test graph creation from a YouTube video."""
111
+ source_url = 'https://www.youtube.com/watch?v=T-qy-zPWgqA'
112
+ source_type = 'youtube'
113
+ create_source_node_graph_url_youtube (graph , model_name , source_url , source_type )
114
+ youtube_result = extract_graph_from_file_youtube (
115
+ URI , USERNAME , PASSWORD , DATABASE , model_name , source_url , '' , ''
116
+ )
117
+ logging .info ("YouTube Video test done" )
118
+ print (youtube_result )
119
+
120
+ try :
121
+ assert youtube_result ['status' ] == 'Completed'
122
+ assert youtube_result ['nodeCount' ] > 1
123
+ assert youtube_result ['relationshipCount' ] > 1
124
+ print ("Success" )
125
+ except AssertionError as e :
126
+ print ("Failed: " , e )
127
+
128
+ return youtube_result
129
129
130
130
def test_chatbot_qna (model_name , mode = 'vector' ):
131
- """Test chatbot QnA functionality for different modes."""
132
- QA_n_RAG = QA_RAG (graph , model_name , 'Tell me about amazon' , '[]' , 1 , mode )
133
- print (QA_n_RAG )
134
- print (len (QA_n_RAG ['message' ]))
135
-
136
- try :
137
- assert len (QA_n_RAG ['message' ]) > 20
138
- return QA_n_RAG
139
- print ("Success" )
140
- except AssertionError as e :
141
- print ("Failed " , e )
142
- return QA_n_RAG
143
-
131
+ """Test chatbot QnA functionality for different modes."""
132
+ QA_n_RAG = QA_RAG (graph , model_name , 'Tell me about amazon' , '[]' , 1 , mode )
133
+ print (QA_n_RAG )
134
+ print (len (QA_n_RAG ['message' ]))
135
+
136
+
137
+ try :
138
+ assert len (QA_n_RAG ['message' ]) > 20
139
+ return QA_n_RAG
140
+ print ("Success" )
141
+ except AssertionError as e :
142
+ print ("Failed " , e )
143
+ return QA_n_RAG
144
+
144
145
#Get Test disconnected_nodes list
145
146
def disconected_nodes ():
146
- #graph = create_graph_database_connection(uri, userName, password, database)
147
- graphDb_data_Access = graphDBdataAccess (graph )
148
- nodes_list , total_nodes = graphDb_data_Access .list_unconnected_nodes ()
149
- print (nodes_list [0 ]["e" ]["elementId" ])
150
- status = "False"
151
-
152
- if total_nodes ['total' ]> 0 :
153
- status = "True"
154
- else :
155
- status = "False"
156
-
157
- return nodes_list [0 ]["e" ]["elementId" ], status
158
-
147
+ #graph = create_graph_database_connection(uri, userName, password, database)
148
+ graphDb_data_Access = graphDBdataAccess (graph )
149
+ nodes_list , total_nodes = graphDb_data_Access .list_unconnected_nodes ()
150
+ print (nodes_list [0 ]["e" ]["elementId" ])
151
+ status = "False"
152
+ if total_nodes ['total' ]> 0 :
153
+ status = "True"
154
+ else :
155
+ status = "False"
156
+ return nodes_list [0 ]["e" ]["elementId" ], status
157
+
159
158
#Test Delete delete_disconnected_nodes list
160
159
def delete_disconected_nodes (lst_element_id ):
161
- print (f'disconnect elementid list { lst_element_id } ' )
162
- #graph = create_graph_database_connection(uri, userName, password, database)
163
- graphDb_data_Access = graphDBdataAccess (graph )
164
- result = graphDb_data_Access .delete_unconnected_nodes (json .dumps (lst_element_id ))
165
- print (f'delete disconnect api result { result } ' )
166
- if not result :
167
- return "True"
168
- else :
169
- return "False"
160
+ print (f'disconnect elementid list { lst_element_id } ' )
161
+ #graph = create_graph_database_connection(uri, userName, password, database)
162
+ graphDb_data_Access = graphDBdataAccess (graph )
163
+ result = graphDb_data_Access .delete_unconnected_nodes (json .dumps (lst_element_id ))
164
+ print (f'delete disconnect api result { result } ' )
165
+ if not result :
166
+ return "True"
167
+ else :
168
+ return "False"
170
169
171
170
#Test Get Duplicate_nodes
172
171
def get_duplicate_nodes ():
173
- #graph = create_graph_database_connection(uri, userName, password, database)
174
- graphDb_data_Access = graphDBdataAccess (graph )
175
- nodes_list , total_nodes = graphDb_data_Access .get_duplicate_nodes_list ()
176
- if total_nodes ['total' ]> 0 :
177
- return "True"
178
- else :
179
- return "False"
180
-
172
+ #graph = create_graph_database_connection(uri, userName, password, database)
173
+ graphDb_data_Access = graphDBdataAccess (graph )
174
+ nodes_list , total_nodes = graphDb_data_Access .get_duplicate_nodes_list ()
175
+ if total_nodes ['total' ]> 0 :
176
+ return "True"
177
+ else :
178
+ return "False"
179
+
181
180
#Test populate_graph_schema
182
181
def test_populate_graph_schema_from_text (model ):
183
- result_schema = populate_graph_schema_from_text ('When Amazon was founded in 1993 by creator Jeff Benzos, it was mostly an online bookstore. Initially Amazon’s growth was very slow, not turning a profit until over 7 years after its founding. This was thanks to the great momentum provided by the dot-com bubble.' , model , True )
184
- print (result_schema )
185
- return result_schema
182
+ result_schema = populate_graph_schema_from_text ('When Amazon was founded in 1993 by creator Jeff Benzos, it was mostly an online bookstore. Initially Amazon’s growth was very slow, not turning a profit until over 7 years after its founding. This was thanks to the great momentum provided by the dot-com bubble.' , model , True )
183
+ print (result_schema )
184
+ return result_schema
186
185
187
186
# def compare_graph_results(results):
188
187
# """
@@ -200,44 +199,45 @@ def test_populate_graph_schema_from_text(model):
200
199
# print(f"Result {i} differs from result {i+1}")
201
200
202
201
def run_tests ():
203
- final_list = []
204
- error_list = []
205
- models = ['openai-gpt-4o' ,'gemini-1.5-pro' ]
206
-
207
- for model_name in models :
208
- try :
209
- final_list .append (test_graph_from_file_local (model_name ))
210
- final_list .append (test_graph_from_wikipedia (model_name ))
211
- final_list .append (test_populate_graph_schema_from_text (model_name ))
212
- final_list .append (test_graph_website (model_name ))
213
- # final_list.append(test_graph_from_youtube_video(model_name))
214
- # final_list.append(test_chatbot_qna(model_name))
215
- # final_list.append(test_chatbot_qna(model_name, mode='vector'))
216
- # final_list.append(test_chatbot_qna(model_name, mode='graph+vector+fulltext'))
217
- except Exception as e :
218
- error_list .append ((model_name , str (e )))
219
- # #Compare and log diffrences in graph results
220
- # # compare_graph_results(final_list) # Pass the final_list to comapre_graph_results
221
- # test_populate_graph_schema_from_text('openai-gpt-4o')
222
- dis_elementid , dis_status = disconected_nodes ()
223
- lst_element_id = [dis_elementid ]
224
- delt = delete_disconected_nodes (lst_element_id )
225
- dup = get_duplicate_nodes ()
226
- # schma = test_populate_graph_schema_from_text(model)
227
- # Save final results to CSV
228
- df = pd .DataFrame (final_list )
229
- print (df )
230
- df ['execution_date' ] = dt .today ().strftime ('%Y-%m-%d' )
231
- df ['disconnected_nodes' ]= dis_status
232
- df ['get_duplicate_nodes' ]= dup
233
- df ['delete_disconected_nodes' ]= delt
234
- # df['test_populate_graph_schema_from_text'] = schma
235
- df .to_csv (f"Integration_TestResult_{ dt .now ().strftime ('%Y%m%d_%H%M%S' )} .csv" , index = False )
236
-
237
- # Save error details to CSV
238
- df_errors = pd .DataFrame (error_list , columns = ['Model' , 'Error' ])
239
- df_errors ['execution_date' ] = dt .today ().strftime ('%Y-%m-%d' )
240
- df_errors .to_csv (f"Error_details_{ dt .now ().strftime ('%Y%m%d_%H%M%S' )} .csv" , index = False )
202
+ final_list = []
203
+ error_list = []
204
+ models = ['openai-gpt-3.5' ,'openai-gpt-4o' ,'openai-gpt-4o-mini' ,'gemini-1.0-pro' ,'gemini-1.5-pro' ,'azure_ai_gpt_35' ,'azure_ai_gpt_4o' ,'ollama_llama3' ,'groq_llama3_70b' ,'anthropic_claude_3_5_sonnet' ,'fireworks_v3p1_405b' ,'bedrock_claude_3_5_sonnet' ]
205
+
206
+ for model_name in models :
207
+ try :
208
+ final_list .append (test_graph_from_file_local (model_name ))
209
+ final_list .append (test_graph_from_wikipedia (model_name ))
210
+ final_list .append (test_populate_graph_schema_from_text (model_name ))
211
+ final_list .append (test_graph_website (model_name ))
212
+ final_list .append (test_graph_from_youtube_video (model_name ))
213
+ final_list .append (test_chatbot_qna (model_name ))
214
+ final_list .append (test_chatbot_qna (model_name , mode = 'vector' ))
215
+ final_list .append (test_chatbot_qna (model_name , mode = 'graph+vector+fulltext' ))
216
+ except Exception as e :
217
+ error_list .append ((model_name , str (e )))
218
+ # #Compare and log diffrences in graph results
219
+ # # compare_graph_results(final_list) # Pass the final_list to comapre_graph_results
220
+ # test_populate_graph_schema_from_text('openai-gpt-4o')
221
+ dis_elementid , dis_status = disconected_nodes ()
222
+ lst_element_id = [dis_elementid ]
223
+ delt = delete_disconected_nodes (lst_element_id )
224
+ dup = get_duplicate_nodes ()
225
+ print (final_list )
226
+ # schma = test_populate_graph_schema_from_text(model)
227
+ # Save final results to CSV
228
+ df = pd .DataFrame (final_list )
229
+ print (df )
230
+ df ['execution_date' ] = dt .today ().strftime ('%Y-%m-%d' )
231
+ df ['disconnected_nodes' ]= dis_status
232
+ df ['get_duplicate_nodes' ]= dup
233
+ df ['delete_disconected_nodes' ]= delt
234
+ # df['test_populate_graph_schema_from_text'] = schma
235
+ df .to_csv (f"Integration_TestResult_{ dt .now ().strftime ('%Y%m%d_%H%M%S' )} .csv" , index = False )
236
+
237
+ # Save error details to CSV
238
+ df_errors = pd .DataFrame (error_list , columns = ['Model' , 'Error' ])
239
+ df_errors ['execution_date' ] = dt .today ().strftime ('%Y-%m-%d' )
240
+ df_errors .to_csv (f"Error_details_{ dt .now ().strftime ('%Y%m%d_%H%M%S' )} .csv" , index = False )
241
241
242
242
if __name__ == "__main__" :
243
- run_tests ()
243
+ run_tests ()
0 commit comments