sha6th commited on
Commit
649399f
·
1 Parent(s): f6a32f7

Fix database function structure

Browse files
Files changed (1) hide show
  1. src/database.py +22 -5
src/database.py CHANGED
@@ -5,15 +5,15 @@ import os
5
 
6
  DB_PATH = "data/evaluations.db"
7
 
8
- # Ensure the data folder exists before connecting
9
  os.makedirs(os.path.dirname(DB_PATH), exist_ok=True)
10
 
11
- DB_PATH = "data/evaluations.db"
12
 
13
  def init_db():
14
  conn = sqlite3.connect(DB_PATH)
15
  cursor = conn.cursor()
16
- cursor.execute('''
 
17
  CREATE TABLE IF NOT EXISTS evaluations (
18
  id INTEGER PRIMARY KEY AUTOINCREMENT,
19
  context TEXT,
@@ -28,10 +28,12 @@ def init_db():
28
  full_result TEXT,
29
  created_at TEXT
30
  )
31
- ''')
 
32
  conn.commit()
33
  conn.close()
34
 
 
35
  def save_evaluation(context, question, llm_response, result):
36
  conn = sqlite3.connect(DB_PATH)
37
  cursor = conn.cursor()
@@ -66,4 +68,19 @@ def save_evaluation(context, question, llm_response, result):
66
  ))
67
 
68
  conn.commit()
69
- conn.close()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  DB_PATH = "data/evaluations.db"
7
 
8
+ # Ensure the data folder exists
9
  os.makedirs(os.path.dirname(DB_PATH), exist_ok=True)
10
 
 
11
 
12
  def init_db():
13
  conn = sqlite3.connect(DB_PATH)
14
  cursor = conn.cursor()
15
+
16
+ cursor.execute("""
17
  CREATE TABLE IF NOT EXISTS evaluations (
18
  id INTEGER PRIMARY KEY AUTOINCREMENT,
19
  context TEXT,
 
28
  full_result TEXT,
29
  created_at TEXT
30
  )
31
+ """)
32
+
33
  conn.commit()
34
  conn.close()
35
 
36
+
37
  def save_evaluation(context, question, llm_response, result):
38
  conn = sqlite3.connect(DB_PATH)
39
  cursor = conn.cursor()
 
68
  ))
69
 
70
  conn.commit()
71
+ conn.close()
72
+
73
+
74
+ def get_all_evaluations():
75
+ conn = sqlite3.connect(DB_PATH)
76
+ cursor = conn.cursor()
77
+
78
+ cursor.execute(
79
+ "SELECT * FROM evaluations ORDER BY created_at DESC"
80
+ )
81
+
82
+ rows = cursor.fetchall()
83
+
84
+ conn.close()
85
+
86
+ return rows