Spaces:
Runtime error
Runtime error
dauksza123
commited on
Update StarReliabilityApp_Refined.py
Browse files
StarReliabilityApp_Refined.py
CHANGED
@@ -33,15 +33,17 @@ class StarMaintAI:
|
|
33 |
|
34 |
self.load_long_term_memory()
|
35 |
|
36 |
-
|
37 |
"""
|
38 |
Ensure the database file exists and create required tables if not.
|
39 |
"""
|
40 |
if not os.path.exists(self.db_path):
|
41 |
print(f"Database not found at {self.db_path}. Initializing new database.")
|
42 |
-
|
43 |
-
|
|
|
44 |
|
|
|
45 |
# Create necessary tables
|
46 |
cursor.execute("""
|
47 |
CREATE TABLE IF NOT EXISTS long_term_memory (
|
@@ -63,8 +65,42 @@ class StarMaintAI:
|
|
63 |
""")
|
64 |
|
65 |
connection.commit()
|
|
|
|
|
|
|
66 |
connection.close()
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
def load_long_term_memory(self):
|
69 |
"""
|
70 |
Load persistent memory from the 'long_term_memory' table.
|
|
|
33 |
|
34 |
self.load_long_term_memory()
|
35 |
|
36 |
+
def ensure_database_exists(self):
|
37 |
"""
|
38 |
Ensure the database file exists and create required tables if not.
|
39 |
"""
|
40 |
if not os.path.exists(self.db_path):
|
41 |
print(f"Database not found at {self.db_path}. Initializing new database.")
|
42 |
+
|
43 |
+
connection = sqlite3.connect(self.db_path)
|
44 |
+
cursor = connection.cursor()
|
45 |
|
46 |
+
try:
|
47 |
# Create necessary tables
|
48 |
cursor.execute("""
|
49 |
CREATE TABLE IF NOT EXISTS long_term_memory (
|
|
|
65 |
""")
|
66 |
|
67 |
connection.commit()
|
68 |
+
except sqlite3.Error as e:
|
69 |
+
print(f"Error during database initialization: {e}")
|
70 |
+
finally:
|
71 |
connection.close()
|
72 |
|
73 |
+
# Refresh connection to ensure database is ready
|
74 |
+
self.connection = sqlite3.connect(self.db_path)
|
75 |
+
|
76 |
+
def load_long_term_memory(self):
|
77 |
+
"""
|
78 |
+
Load persistent memory from the 'long_term_memory' table.
|
79 |
+
"""
|
80 |
+
try:
|
81 |
+
cursor = self.connection.cursor()
|
82 |
+
cursor.execute("SELECT key, value FROM long_term_memory")
|
83 |
+
self.long_term_memory = {row[0]: row[1] for row in cursor.fetchall()}
|
84 |
+
except sqlite3.OperationalError as e:
|
85 |
+
print(f"Error loading long-term memory: {e}. Reinitializing database.")
|
86 |
+
self.ensure_database_exists()
|
87 |
+
self.long_term_memory = {}
|
88 |
+
|
89 |
+
|
90 |
+
def load_long_term_memory(self):
|
91 |
+
"""
|
92 |
+
Load persistent memory from the 'long_term_memory' table.
|
93 |
+
"""
|
94 |
+
try:
|
95 |
+
cursor = self.connection.cursor()
|
96 |
+
cursor.execute("SELECT key, value FROM long_term_memory")
|
97 |
+
self.long_term_memory = {row[0]: row[1] for row in cursor.fetchall()}
|
98 |
+
except sqlite3.OperationalError as e:
|
99 |
+
print(f"Error loading long-term memory: {e}. Reinitializing database.")
|
100 |
+
self.ensure_database_exists()
|
101 |
+
self.long_term_memory = {}
|
102 |
+
|
103 |
+
|
104 |
def load_long_term_memory(self):
|
105 |
"""
|
106 |
Load persistent memory from the 'long_term_memory' table.
|