oceansweep commited on
Commit
830d6c0
·
verified ·
1 Parent(s): 119c6b7

Update App_Function_Libraries/DB/RAG_QA_Chat_DB.py

Browse files
App_Function_Libraries/DB/RAG_QA_Chat_DB.py CHANGED
@@ -23,41 +23,56 @@ from App_Function_Libraries.Utils.Utils import get_project_relative_path, get_pr
23
  ########################################################################################################################
24
  #
25
  # Functions:
 
26
  def get_rag_qa_db_path():
27
- # Get and verify project root
28
- project_root = get_project_root()
29
- print(f"Project root path: {project_root}")
30
-
31
- # Construct and verify config path
32
- config_path = os.path.join(project_root, 'Config_Files', 'config.txt')
33
- print(f"Looking for config at: {config_path}")
34
- print(f"Config file exists: {os.path.exists(config_path)}")
35
-
36
- # If config exists, check its contents
37
- if os.path.exists(config_path):
38
- with open(config_path, 'r') as f:
39
- print("Raw config contents:")
40
- print(f.read())
41
-
42
- config = configparser.ConfigParser()
43
- files_read = config.read(config_path)
44
- print(f"Files successfully read: {files_read}")
45
- print(f"Available sections: {config.sections()}")
46
-
47
- if config.has_section('Database'):
48
- print(f"Database section options: {config.options('Database')}")
49
- if config.has_option('Database', 'rag_qa_db_path'):
50
- rag_qa_db_path = config.get('Database', 'rag_qa_db_path')
51
- print(f"Found rag_qa_db_path: {rag_qa_db_path}")
52
- if not os.path.isabs(rag_qa_db_path):
53
- rag_qa_db_path = get_project_relative_path(rag_qa_db_path)
54
- return rag_qa_db_path
 
 
 
 
 
 
 
 
55
  else:
56
- print("rag_qa_db_path option not found in Database section")
57
- else:
58
- print("Database section not found")
59
-
60
- raise ValueError("Database path not found in config file")
 
 
 
 
 
 
61
 
62
  def check_config_file():
63
  current_dir = os.getcwd()
 
23
  ########################################################################################################################
24
  #
25
  # Functions:
26
+
27
  def get_rag_qa_db_path():
28
+ try:
29
+ config_path = os.path.join(get_project_root(), 'Config_Files', 'config.txt')
30
+ print(f"Attempting to read config from: {config_path}")
31
+
32
+ if not os.path.exists(config_path):
33
+ print(f"Config file does not exist at: {config_path}")
34
+ raise FileNotFoundError(f"Config file not found at: {config_path}")
35
+
36
+ config = configparser.ConfigParser()
37
+ files_read = config.read(config_path)
38
+ print(f"Config files read: {files_read}")
39
+ print(f"Sections in config: {config.sections()}")
40
+
41
+ if 'Database' in config.sections():
42
+ print("Found Database section")
43
+ print(f"Options in Database section: {config.options('Database')}")
44
+
45
+ if 'rag_qa_db_path' in config.options('Database'):
46
+ rag_qa_db_path = config.get('Database', 'rag_qa_db_path')
47
+ print(f"Found rag_qa_db_path: {rag_qa_db_path}")
48
+
49
+ if not os.path.isabs(rag_qa_db_path):
50
+ project_root = get_project_root()
51
+ rag_qa_db_path = os.path.join(project_root, rag_qa_db_path)
52
+ print(f"Converted to absolute path: {rag_qa_db_path}")
53
+
54
+ # Ensure the directory exists
55
+ db_dir = os.path.dirname(rag_qa_db_path)
56
+ if not os.path.exists(db_dir):
57
+ print(f"Creating directory: {db_dir}")
58
+ os.makedirs(db_dir, exist_ok=True)
59
+
60
+ return rag_qa_db_path
61
+ else:
62
+ print("rag_qa_db_path not found in Database section")
63
+ print(f"Available options: {config.options('Database')}")
64
  else:
65
+ print("Database section not found in config")
66
+ print(f"Available sections: {config.sections()}")
67
+
68
+ raise ValueError("Database path not found in config file")
69
+
70
+ except Exception as e:
71
+ print(f"Error in get_rag_qa_db_path: {str(e)}")
72
+ print(f"Error type: {type(e)}")
73
+ import traceback
74
+ print(f"Traceback: {traceback.format_exc()}")
75
+ raise
76
 
77
  def check_config_file():
78
  current_dir = os.getcwd()