AbdulMoid commited on
Commit
2ac1935
·
verified ·
1 Parent(s): d0be79d

Update graph_rag.py

Browse files
Files changed (1) hide show
  1. graph_rag.py +17 -8
graph_rag.py CHANGED
@@ -17,17 +17,25 @@ def unzip_folder(zip_path, extract_path):
17
  os.makedirs(output_dir, exist_ok=True)
18
 
19
  with zipfile.ZipFile(zip_path, 'r') as zip_ref:
20
- zip_ref.extractall(output_dir)
21
 
22
- logger.info(f"Extracted contents to {output_dir}")
23
- logger.info(f"Contents of {output_dir}:")
24
- for file in os.listdir(output_dir):
25
- logger.info(os.path.join(output_dir, file))
26
 
27
- return output_dir
 
 
 
 
 
 
 
 
 
28
 
29
  def run_graphrag_query(query, ragtest_dir):
30
- # Check and log the contents of the ragtest_dir
 
31
  logger.info(f"Contents of {ragtest_dir}:")
32
  for file in os.listdir(ragtest_dir):
33
  logger.info(os.path.join(ragtest_dir, file))
@@ -47,9 +55,9 @@ def run_graphrag_query(query, ragtest_dir):
47
  if result.returncode == 0:
48
  return result.stdout
49
  else:
 
50
  return result.stderr
51
 
52
-
53
  def qa_tool_graph_rag(user_question):
54
  original_dir = os.getcwd() # Store the original directory
55
  try:
@@ -77,3 +85,4 @@ def qa_tool_graph_rag(user_question):
77
  shutil.rmtree(output_dir)
78
 
79
  os.chdir(original_dir) # Return to the original directory
 
 
17
  os.makedirs(output_dir, exist_ok=True)
18
 
19
  with zipfile.ZipFile(zip_path, 'r') as zip_ref:
20
+ zip_ref.extractall(extract_path)
21
 
22
+ # Adjust to handle the extra ragtest folder inside the zip
23
+ actual_output_dir = os.path.join(output_dir, "ragtest")
 
 
24
 
25
+ if os.path.exists(actual_output_dir):
26
+ logger.info(f"Extracted contents to {actual_output_dir}")
27
+ logger.info(f"Contents of {actual_output_dir}:")
28
+ for file in os.listdir(actual_output_dir):
29
+ logger.info(os.path.join(actual_output_dir, file))
30
+ else:
31
+ logger.error(f"Expected directory {actual_output_dir} does not exist. Check the structure of the zip file.")
32
+ actual_output_dir = output_dir # fallback in case the structure is not as expected
33
+
34
+ return actual_output_dir
35
 
36
  def run_graphrag_query(query, ragtest_dir):
37
+ # Log the directory and its contents
38
+ logger.info(f"Running GraphRAG query with root: {ragtest_dir}")
39
  logger.info(f"Contents of {ragtest_dir}:")
40
  for file in os.listdir(ragtest_dir):
41
  logger.info(os.path.join(ragtest_dir, file))
 
55
  if result.returncode == 0:
56
  return result.stdout
57
  else:
58
+ logger.error(f"GraphRAG query failed with error: {result.stderr}")
59
  return result.stderr
60
 
 
61
  def qa_tool_graph_rag(user_question):
62
  original_dir = os.getcwd() # Store the original directory
63
  try:
 
85
  shutil.rmtree(output_dir)
86
 
87
  os.chdir(original_dir) # Return to the original directory
88
+