AbdulMoid commited on
Commit
0f81c79
·
verified ·
1 Parent(s): 2423011

Update graph_rag.py

Browse files
Files changed (1) hide show
  1. graph_rag.py +17 -1
graph_rag.py CHANGED
@@ -59,6 +59,19 @@ def run_graphrag_query(query, ragtest_dir):
59
  logger.error(f"GraphRAG query failed with error: {result.stderr}")
60
  return result.stderr
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  def qa_tool_graph_rag(user_question):
63
  original_dir = os.getcwd() # Store the original directory
64
  try:
@@ -73,7 +86,10 @@ def qa_tool_graph_rag(user_question):
73
  combined_input = f"{patient_info}\n\n{user_question}"
74
 
75
  # Run the GraphRAG query with the combined input
76
- answer = run_graphrag_query(combined_input, output_dir)
 
 
 
77
 
78
  logger.info(f"GraphRAG answer generated: {answer}")
79
 
 
59
  logger.error(f"GraphRAG query failed with error: {result.stderr}")
60
  return result.stderr
61
 
62
+ def clean_response(response):
63
+ # Find the position of "SUCCESS: Global Search Response:"
64
+ search_str = "SUCCESS: Global Search Response:"
65
+ start_index = response.find(search_str)
66
+
67
+ # If the search string is found, return the substring starting from after this string
68
+ if start_index != -1:
69
+ # Add the length of search_str to start_index to begin after the search string
70
+ return response[start_index + len(search_str):].strip()
71
+ else:
72
+ # If the search string is not found, return the original response
73
+ return response
74
+
75
  def qa_tool_graph_rag(user_question):
76
  original_dir = os.getcwd() # Store the original directory
77
  try:
 
86
  combined_input = f"{patient_info}\n\n{user_question}"
87
 
88
  # Run the GraphRAG query with the combined input
89
+ raw_answer = run_graphrag_query(combined_input, output_dir)
90
+
91
+ # Clean the response to remove everything before "SUCCESS: Global Search Response:"
92
+ answer = clean_response(raw_answer)
93
 
94
  logger.info(f"GraphRAG answer generated: {answer}")
95