AbdulMoid commited on
Commit
604bbfe
·
verified ·
1 Parent(s): 613fc49

Update graph_rag.py

Browse files
Files changed (1) hide show
  1. graph_rag.py +17 -12
graph_rag.py CHANGED
@@ -65,22 +65,25 @@ def clean_response(response):
65
  search_str = "SUCCESS: Global Search Response:"
66
  start_index = response.find(search_str)
67
 
68
- # If the search string is found, process the response from that point onward
69
  if start_index != -1:
70
- # Extract the relevant part of the response
71
- cleaned_response = response[start_index + len(search_str):].strip()
72
-
73
- # Remove "[Data: Reports (XXX)]" references
74
- pattern = r'\[Data: Reports \(\d+\)\]'
75
- cleaned_response = re.sub(pattern, '', cleaned_response)
76
-
77
- # Remove extra spaces that might result from the substitution
78
- cleaned_response = re.sub(r'\s+', ' ', cleaned_response).strip()
79
-
80
- return cleaned_response
81
  else:
82
  # If the search string is not found, return the original response
83
  return response
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
  def qa_tool_graph_rag(user_question):
86
  original_dir = os.getcwd() # Store the original directory
@@ -100,6 +103,8 @@ def qa_tool_graph_rag(user_question):
100
 
101
  # Clean the response to remove everything before "SUCCESS: Global Search Response:"
102
  answer = clean_response(raw_answer)
 
 
103
 
104
  logger.info(f"GraphRAG answer generated: {answer}")
105
 
 
65
  search_str = "SUCCESS: Global Search Response:"
66
  start_index = response.find(search_str)
67
 
68
+ # If the search string is found, return the substring starting from after this string
69
  if start_index != -1:
70
+ # Add the length of search_str to start_index to begin after the search string
71
+ return response[start_index + len(search_str):].strip()
 
 
 
 
 
 
 
 
 
72
  else:
73
  # If the search string is not found, return the original response
74
  return response
75
+
76
+ def remove_data_reports(response):
77
+ # Regular expression pattern to find "[Data: Reports (XXX)]" and similar patterns
78
+ pattern = r'\[Data: Reports \(\d+\)\]'
79
+
80
+ # Substitute the pattern with an empty string
81
+ cleaned_response = re.sub(pattern, '', response)
82
+
83
+ # Remove extra spaces that might result from the substitution
84
+ cleaned_response = re.sub(r'\s+', ' ', cleaned_response).strip()
85
+
86
+ return cleaned_response
87
 
88
  def qa_tool_graph_rag(user_question):
89
  original_dir = os.getcwd() # Store the original directory
 
103
 
104
  # Clean the response to remove everything before "SUCCESS: Global Search Response:"
105
  answer = clean_response(raw_answer)
106
+
107
+ answer = remove_data_reports(answer)
108
 
109
  logger.info(f"GraphRAG answer generated: {answer}")
110